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
|
||||
void testIsAssignable() {
|
||||
void shouldNotThrowExceptionWhenClassIsAssignable() {
|
||||
Validate.isAssignableFrom(CharSequence.class, String.class);
|
||||
Validate.isAssignableFrom(AbstractList.class, ArrayList.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsAssignableExceptionMessage() {
|
||||
try {
|
||||
Validate.isAssignableFrom(List.class, String.class);
|
||||
fail("Expecting IllegalArgumentException");
|
||||
} catch (final IllegalArgumentException e) {
|
||||
assertEquals("Cannot assign a java.lang.String to a java.util.List", e.getMessage());
|
||||
void shouldThrowIllegalArgumentExceptionWithDefaultMessageWhenClassIsNotAssignable() {
|
||||
final IllegalArgumentException ex = assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> Validate.isAssignableFrom(List.class, String.class));
|
||||
|
||||
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
|
||||
void testIsAssignable_withMessage() {
|
||||
Validate.isAssignableFrom(CharSequence.class, String.class, "Error");
|
||||
Validate.isAssignableFrom(AbstractList.class, ArrayList.class, "Error");
|
||||
try {
|
||||
Validate.isAssignableFrom(List.class, String.class, "Error");
|
||||
fail("Expecting IllegalArgumentException");
|
||||
} catch (final IllegalArgumentException e) {
|
||||
assertEquals("Error", e.getMessage());
|
||||
}
|
||||
}
|
||||
void shouldThrowIllegalArgumentExceptionWithGiventMessageWhenClassIsNotAssignable() {
|
||||
final IllegalArgumentException ex = assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> Validate.isAssignableFrom(List.class, String.class, "MSG"));
|
||||
|
||||
assertEquals("MSG", ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue