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