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