Convert tests for Validate.finite overloads to @Nested test

This commit is contained in:
Benedikt Ritter 2018-09-06 19:38:45 +02:00
parent 4077b57f6d
commit 6e9f406aac
No known key found for this signature in database
GPG Key ID: 9DAADC1C9FCC82D0
1 changed files with 69 additions and 43 deletions

View File

@ -1167,53 +1167,79 @@ class ValidateTest {
} }
} }
@Nested
class Finite {
//----------------------------------------------------------------------- @Nested
//----------------------------------------------------------------------- class WithoutMessage {
@Test @Test
void testFinite1() { void shouldNotThrowExceptionForFiniteValue() {
Validate.finite(0.0); Validate.finite(0.0);
try { }
Validate.finite(Double.POSITIVE_INFINITY);
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("The value is invalid: Infinity", ex.getMessage());
}
try {
Validate.finite(Double.NEGATIVE_INFINITY);
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("The value is invalid: -Infinity", ex.getMessage());
}
try {
Validate.finite(Double.NaN);
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("The value is invalid: NaN", ex.getMessage());
}
}
@Test @Test
void testFinite2() { void shouldThrowIllegalArgumentExceptionWithDefaultMessageForPositiveInfinity() {
Validate.finite(0.0, "MSG"); final IllegalArgumentException ex = assertThrows(
try { IllegalArgumentException.class,
Validate.finite(Double.POSITIVE_INFINITY, "MSG"); () -> Validate.finite(Double.POSITIVE_INFINITY));
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) { assertEquals("The value is invalid: Infinity", ex.getMessage());
assertEquals("MSG", ex.getMessage()); }
@Test
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForNegativeInfinity() {
final IllegalArgumentException ex = assertThrows(
IllegalArgumentException.class,
() -> Validate.finite(Double.NEGATIVE_INFINITY));
assertEquals("The value is invalid: -Infinity", ex.getMessage());
}
@Test
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForNaN() {
final IllegalArgumentException ex = assertThrows(
IllegalArgumentException.class,
() -> Validate.finite(Double.NaN));
assertEquals("The value is invalid: NaN", ex.getMessage());
}
} }
try {
Validate.finite(Double.NEGATIVE_INFINITY, "MSG"); @Nested
fail("Expecting IllegalArgumentException"); class WithMessage {
} catch (final IllegalArgumentException ex) {
assertEquals("MSG", ex.getMessage()); @Test
} void shouldNotThrowExceptionForFiniteValue() {
try { Validate.finite(0.0, "MSG");
Validate.finite(Double.NaN, "MSG"); }
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) { @Test
assertEquals("MSG", ex.getMessage()); void shouldThrowIllegalArgumentExceptionWithDefaultMessageForPositiveInfinity() {
final IllegalArgumentException ex = assertThrows(
IllegalArgumentException.class,
() -> Validate.finite(Double.POSITIVE_INFINITY, "MSG"));
assertEquals("MSG", ex.getMessage());
}
@Test
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForNegativeInfinity() {
final IllegalArgumentException ex = assertThrows(
IllegalArgumentException.class,
() -> Validate.finite(Double.NEGATIVE_INFINITY, "MSG"));
assertEquals("MSG", ex.getMessage());
}
@Test
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForNaN() {
final IllegalArgumentException ex = assertThrows(
IllegalArgumentException.class,
() -> Validate.finite(Double.NaN, "MSG"));
assertEquals("MSG", ex.getMessage());
}
} }
} }