Convert tests for Validate.notNaN overloads to @Nested test

This commit is contained in:
Benedikt Ritter 2018-09-06 19:29:01 +02:00
parent 8912be8a88
commit 4077b57f6d
No known key found for this signature in database
GPG Key ID: 9DAADC1C9FCC82D0
1 changed files with 57 additions and 22 deletions

View File

@ -1107,31 +1107,66 @@ class ValidateTest {
}
}
@Test
void testNotNaN1() {
Validate.notNaN(0.0);
Validate.notNaN(Double.POSITIVE_INFINITY);
Validate.notNaN(Double.NEGATIVE_INFINITY);
try {
Validate.notNaN(Double.NaN);
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("The validated value is not a number", ex.getMessage());
@Nested
class NotNaN {
@Nested
class WithoutMessage {
@Test
void shouldNotThrowExceptionForNumber() {
Validate.notNaN(0.0);
}
@Test
void shouldNotThrowExceptionForPositiveInfinity() {
Validate.notNaN(Double.POSITIVE_INFINITY);
}
@Test
void shouldNotThrowExceptionForNegativeInfinity() {
Validate.notNaN(Double.NEGATIVE_INFINITY);
}
@Test
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForNaN() {
final IllegalArgumentException ex = assertThrows(
IllegalArgumentException.class,
() -> Validate.notNaN(Double.NaN));
assertEquals("The validated value is not a number", ex.getMessage());
}
}
@Nested
class WithMessage {
@Test
void shouldNotThrowExceptionForNumber() {
Validate.notNaN(0.0, "MSG");
}
@Test
void shouldNotThrowExceptionForPositiveInfinity() {
Validate.notNaN(Double.POSITIVE_INFINITY, "MSG");
}
@Test
void shouldNotThrowExceptionForNegativeInfinity() {
Validate.notNaN(Double.NEGATIVE_INFINITY, "MSG");
}
@Test
void shouldThrowIllegalArgumentExceptionWithGivenMessageForNaN() {
final IllegalArgumentException ex = assertThrows(
IllegalArgumentException.class,
() -> Validate.notNaN(Double.NaN, "MSG"));
assertEquals("MSG", ex.getMessage());
}
}
}
@Test
void testNotNaN2() {
Validate.notNaN(0.0, "MSG");
Validate.notNaN(Double.POSITIVE_INFINITY, "MSG");
Validate.notNaN(Double.NEGATIVE_INFINITY, "MSG");
try {
Validate.notNaN(Double.NaN, "MSG");
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("MSG", ex.getMessage());
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------