Convert tests for Validate.isAssignable overloads to @Nested test

This commit is contained in:
Benedikt Ritter 2018-09-06 20:19:14 +02:00
parent 3e58ab33b9
commit 0b14928ee4
No known key found for this signature in database
GPG Key ID: 9DAADC1C9FCC82D0
1 changed files with 36 additions and 25 deletions

View File

@ -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());
}
}
}
}