Convert tests for Validate.notNull overloads to @Nested test
This commit is contained in:
parent
aad2db8b12
commit
d3f2a89ba2
|
@ -139,39 +139,60 @@ class ValidateTest {
|
|||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@SuppressWarnings("unused")
|
||||
@Nested
|
||||
class NotNull {
|
||||
|
||||
@Nested
|
||||
class WithoutMessage {
|
||||
|
||||
@Test
|
||||
void testNotNull1() {
|
||||
void shouldNotThrowForNonNullReference() {
|
||||
Validate.notNull(new Object());
|
||||
try {
|
||||
Validate.notNull(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (final NullPointerException ex) {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnTheSameInstance() {
|
||||
final String str = "Hi";
|
||||
final String result = Validate.notNull(str);
|
||||
|
||||
assertSame(str, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowExceptionWithDefaultMessageForNullReference() {
|
||||
final NullPointerException ex = assertThrows(
|
||||
NullPointerException.class,
|
||||
() -> Validate.notNull(null));
|
||||
|
||||
assertEquals("The validated object is null", ex.getMessage());
|
||||
}
|
||||
|
||||
final String str = "Hi";
|
||||
final String testStr = Validate.notNull(str);
|
||||
assertSame(str, testStr);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@SuppressWarnings("unused")
|
||||
@Nested
|
||||
class WithMessage {
|
||||
|
||||
@Test
|
||||
void testNotNull2() {
|
||||
void shouldNotThrowForNonNullReference() {
|
||||
Validate.notNull(new Object(), "MSG");
|
||||
try {
|
||||
Validate.notNull(null, "MSG");
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (final NullPointerException ex) {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnTheSameInstance() {
|
||||
final String str = "Hi";
|
||||
final String result = Validate.notNull(str, "MSG");
|
||||
|
||||
assertSame(str, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowExceptionWithGivenMessageForNullReference() {
|
||||
final NullPointerException ex = assertThrows(
|
||||
NullPointerException.class,
|
||||
() -> Validate.notNull(null, "MSG"));
|
||||
|
||||
assertEquals("MSG", ex.getMessage());
|
||||
}
|
||||
|
||||
final String str = "Hi";
|
||||
final String testStr = Validate.notNull(str, "Message");
|
||||
assertSame(str, testStr);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue