Convert tests for Validate.isInstanceOf overloads to @Nested test
This commit is contained in:
parent
5445f22747
commit
3e58ab33b9
|
@ -1785,55 +1785,61 @@ void shouldThrowIllegalArgumentExceptionWithGivenMessageWhenValueIsAboveUpperBou
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class IsInstanceOf {
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class WithoutMessage {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testIsInstanceOf() {
|
void shouldNotThrowExceptionWhenValueIsInstanceOfClass() {
|
||||||
Validate.isInstanceOf(String.class, "hi");
|
Validate.isInstanceOf(String.class, "hi");
|
||||||
Validate.isInstanceOf(Integer.class, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testIsInstanceOfExceptionMessage() {
|
void shouldThrowIllegalArgumentExceptionWithDefaultMessageWhenValueIsNotInstanceOfClass() {
|
||||||
try {
|
final IllegalArgumentException ex = assertThrows(
|
||||||
Validate.isInstanceOf(List.class, "hi");
|
IllegalArgumentException.class,
|
||||||
fail("Expecting IllegalArgumentException");
|
() -> Validate.isInstanceOf(List.class, "hi"));
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
assertEquals("Expected type: java.util.List, actual: java.lang.String", e.getMessage());
|
assertEquals("Expected type: java.util.List, actual: java.lang.String", ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class WithMessage {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testIsInstanceOf_withMessage() {
|
void shouldNotThrowExceptionWhenValueIsInstanceOfClass() {
|
||||||
Validate.isInstanceOf(String.class, "hi", "Error");
|
Validate.isInstanceOf(String.class, "hi", "MSG");
|
||||||
Validate.isInstanceOf(Integer.class, 1, "Error");
|
|
||||||
try {
|
|
||||||
Validate.isInstanceOf(List.class, "hi", "Error");
|
|
||||||
fail("Expecting IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
assertEquals("Error", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testIsInstanceOf_withMessageArgs() {
|
void shouldThrowIllegalArgumentExceptionWithGivenMessageWhenValueIsNotInstanceOfClass() {
|
||||||
|
final IllegalArgumentException ex = assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> Validate.isInstanceOf(List.class, "hi", "MSG"));
|
||||||
|
|
||||||
|
assertEquals("MSG", ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class WithMessageTemplate {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotThrowExceptionWhenValueIsInstanceOfClass() {
|
||||||
Validate.isInstanceOf(String.class, "hi", "Error %s=%s", "Name", "Value");
|
Validate.isInstanceOf(String.class, "hi", "Error %s=%s", "Name", "Value");
|
||||||
Validate.isInstanceOf(Integer.class, 1, "Error %s=%s", "Name", "Value");
|
|
||||||
try {
|
|
||||||
Validate.isInstanceOf(List.class, "hi", "Error %s=%s", "Name", "Value");
|
|
||||||
fail("Expecting IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
assertEquals("Error Name=Value", e.getMessage());
|
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
Validate.isInstanceOf(List.class, "hi", "Error %s=%s", List.class, "Value");
|
@Test
|
||||||
fail("Expecting IllegalArgumentException");
|
void shouldThrowIllegalArgumentExceptionWithGivenMessageWhenValueIsNotInstanceOfClass() {
|
||||||
} catch (final IllegalArgumentException e) {
|
final IllegalArgumentException ex = assertThrows(
|
||||||
assertEquals("Error interface java.util.List=Value", e.getMessage());
|
IllegalArgumentException.class,
|
||||||
|
() -> Validate.isInstanceOf(List.class, "hi", "Error %s=%s", "Name", "Value"));
|
||||||
|
|
||||||
|
assertEquals("Error Name=Value", ex.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
Validate.isInstanceOf(List.class, "hi", "Error %s=%s", List.class, null);
|
|
||||||
fail("Expecting IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
assertEquals("Error interface java.util.List=null", e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue