Convert tests for Validate.isAssignable overloads to @Nested test
This commit is contained in:
parent
3e58ab33b9
commit
0b14928ee4
|
@ -1843,32 +1843,43 @@ class ValidateTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class IsAssignable {
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class WithoutMessage {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testIsAssignable() {
|
void shouldNotThrowExceptionWhenClassIsAssignable() {
|
||||||
Validate.isAssignableFrom(CharSequence.class, String.class);
|
Validate.isAssignableFrom(CharSequence.class, String.class);
|
||||||
Validate.isAssignableFrom(AbstractList.class, ArrayList.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testIsAssignableExceptionMessage() {
|
void shouldThrowIllegalArgumentExceptionWithDefaultMessageWhenClassIsNotAssignable() {
|
||||||
try {
|
final IllegalArgumentException ex = assertThrows(
|
||||||
Validate.isAssignableFrom(List.class, String.class);
|
IllegalArgumentException.class,
|
||||||
fail("Expecting IllegalArgumentException");
|
() -> Validate.isAssignableFrom(List.class, String.class));
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
assertEquals("Cannot assign a java.lang.String to a java.util.List", e.getMessage());
|
assertEquals("Cannot assign a java.lang.String to a java.util.List", ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class WithMessage {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotThrowExceptionWhenClassIsAssignable() {
|
||||||
|
Validate.isAssignableFrom(CharSequence.class, String.class, "MSG");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testIsAssignable_withMessage() {
|
void shouldThrowIllegalArgumentExceptionWithGiventMessageWhenClassIsNotAssignable() {
|
||||||
Validate.isAssignableFrom(CharSequence.class, String.class, "Error");
|
final IllegalArgumentException ex = assertThrows(
|
||||||
Validate.isAssignableFrom(AbstractList.class, ArrayList.class, "Error");
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> Validate.isAssignableFrom(List.class, String.class, "MSG"));
|
||||||
Validate.isAssignableFrom(List.class, String.class, "Error");
|
|
||||||
fail("Expecting IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
assertEquals("Error", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
assertEquals("MSG", ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue