Convert tests for Validate.notNull overloads to @Nested test

This commit is contained in:
Benedikt Ritter 2018-09-06 10:16:26 +02:00
parent aad2db8b12
commit d3f2a89ba2
No known key found for this signature in database
GPG Key ID: 9DAADC1C9FCC82D0

View File

@ -139,39 +139,60 @@ void shouldThrowExceptionWithDoubleInsertedIntoTemplateMessageForFalseExpression
} }
} }
//----------------------------------------------------------------------- @Nested
//----------------------------------------------------------------------- class NotNull {
@SuppressWarnings("unused")
@Test @Nested
void testNotNull1() { class WithoutMessage {
Validate.notNull(new Object());
try { @Test
Validate.notNull(null); void shouldNotThrowForNonNullReference() {
fail("Expecting NullPointerException"); Validate.notNull(new Object());
} catch (final NullPointerException ex) { }
assertEquals("The validated object is null", ex.getMessage());
@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"; @Nested
final String testStr = Validate.notNull(str); class WithMessage {
assertSame(str, testStr);
}
//----------------------------------------------------------------------- @Test
@SuppressWarnings("unused") void shouldNotThrowForNonNullReference() {
@Test Validate.notNull(new Object(), "MSG");
void testNotNull2() { }
Validate.notNull(new Object(), "MSG");
try { @Test
Validate.notNull(null, "MSG"); void shouldReturnTheSameInstance() {
fail("Expecting NullPointerException"); final String str = "Hi";
} catch (final NullPointerException ex) { final String result = Validate.notNull(str, "MSG");
assertEquals("MSG", ex.getMessage());
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);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------