Convert tests for Validate.finite overloads to @Nested test
This commit is contained in:
parent
4077b57f6d
commit
6e9f406aac
|
@ -1167,55 +1167,81 @@ 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");
|
@Test
|
||||||
} catch (final IllegalArgumentException ex) {
|
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForPositiveInfinity() {
|
||||||
|
final IllegalArgumentException ex = assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> Validate.finite(Double.POSITIVE_INFINITY));
|
||||||
|
|
||||||
assertEquals("The value is invalid: Infinity", ex.getMessage());
|
assertEquals("The value is invalid: Infinity", ex.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
Validate.finite(Double.NEGATIVE_INFINITY);
|
@Test
|
||||||
fail("Expecting IllegalArgumentException");
|
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForNegativeInfinity() {
|
||||||
} catch (final IllegalArgumentException ex) {
|
final IllegalArgumentException ex = assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> Validate.finite(Double.NEGATIVE_INFINITY));
|
||||||
|
|
||||||
assertEquals("The value is invalid: -Infinity", ex.getMessage());
|
assertEquals("The value is invalid: -Infinity", ex.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
Validate.finite(Double.NaN);
|
@Test
|
||||||
fail("Expecting IllegalArgumentException");
|
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForNaN() {
|
||||||
} catch (final IllegalArgumentException ex) {
|
final IllegalArgumentException ex = assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> Validate.finite(Double.NaN));
|
||||||
|
|
||||||
assertEquals("The value is invalid: NaN", ex.getMessage());
|
assertEquals("The value is invalid: NaN", ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class WithMessage {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFinite2() {
|
void shouldNotThrowExceptionForFiniteValue() {
|
||||||
Validate.finite(0.0, "MSG");
|
Validate.finite(0.0, "MSG");
|
||||||
try {
|
}
|
||||||
Validate.finite(Double.POSITIVE_INFINITY, "MSG");
|
|
||||||
fail("Expecting IllegalArgumentException");
|
@Test
|
||||||
} catch (final IllegalArgumentException ex) {
|
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForPositiveInfinity() {
|
||||||
|
final IllegalArgumentException ex = assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> Validate.finite(Double.POSITIVE_INFINITY, "MSG"));
|
||||||
|
|
||||||
assertEquals("MSG", ex.getMessage());
|
assertEquals("MSG", ex.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
Validate.finite(Double.NEGATIVE_INFINITY, "MSG");
|
@Test
|
||||||
fail("Expecting IllegalArgumentException");
|
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForNegativeInfinity() {
|
||||||
} catch (final IllegalArgumentException ex) {
|
final IllegalArgumentException ex = assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> Validate.finite(Double.NEGATIVE_INFINITY, "MSG"));
|
||||||
|
|
||||||
assertEquals("MSG", ex.getMessage());
|
assertEquals("MSG", ex.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
Validate.finite(Double.NaN, "MSG");
|
@Test
|
||||||
fail("Expecting IllegalArgumentException");
|
void shouldThrowIllegalArgumentExceptionWithDefaultMessageForNaN() {
|
||||||
} catch (final IllegalArgumentException ex) {
|
final IllegalArgumentException ex = assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> Validate.finite(Double.NaN, "MSG"));
|
||||||
|
|
||||||
assertEquals("MSG", ex.getMessage());
|
assertEquals("MSG", ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue