mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-08 11:05:09 +00:00
Convert tests for Validate.notNull overloads to @Nested test
This commit is contained in:
parent
aad2db8b12
commit
d3f2a89ba2
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user