You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2018/09/06 20:02:32 UTC
[10/16] [lang] Convert tests for Validate.finite overloads to @Nested
test
Convert tests for Validate.finite overloads to @Nested test
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/6e9f406a
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/6e9f406a
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/6e9f406a
Branch: refs/heads/master
Commit: 6e9f406aacc8444d22c35d50ab2e90afab5cddd6
Parents: 4077b57
Author: Benedikt Ritter <br...@apache.org>
Authored: Thu Sep 6 19:38:45 2018 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Thu Sep 6 19:38:45 2018 +0200
----------------------------------------------------------------------
.../org/apache/commons/lang3/ValidateTest.java | 112 ++++++++++++-------
1 file changed, 69 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/6e9f406a/src/test/java/org/apache/commons/lang3/ValidateTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/ValidateTest.java b/src/test/java/org/apache/commons/lang3/ValidateTest.java
index 6ebcefd..0af343e 100644
--- a/src/test/java/org/apache/commons/lang3/ValidateTest.java
+++ b/src/test/java/org/apache/commons/lang3/ValidateTest.java
@@ -1167,53 +1167,79 @@ class ValidateTest {
}
}
+ @Nested
+ class Finite {
- //-----------------------------------------------------------------------
- //-----------------------------------------------------------------------
+ @Nested
+ class WithoutMessage {
- @Test
- void testFinite1() {
- 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
+ void shouldNotThrowExceptionForFiniteValue() {
+ Validate.finite(0.0);
+ }
- @Test
- void testFinite2() {
- Validate.finite(0.0, "MSG");
- try {
- Validate.finite(Double.POSITIVE_INFINITY, "MSG");
- fail("Expecting IllegalArgumentException");
- } catch (final IllegalArgumentException ex) {
- assertEquals("MSG", ex.getMessage());
- }
- try {
- Validate.finite(Double.NEGATIVE_INFINITY, "MSG");
- fail("Expecting IllegalArgumentException");
- } catch (final IllegalArgumentException ex) {
- assertEquals("MSG", ex.getMessage());
+ @Test
+ void shouldThrowIllegalArgumentExceptionWithDefaultMessageForPositiveInfinity() {
+ final IllegalArgumentException ex = assertThrows(
+ IllegalArgumentException.class,
+ () -> Validate.finite(Double.POSITIVE_INFINITY));
+
+ assertEquals("The value is invalid: Infinity", 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.NaN, "MSG");
- fail("Expecting IllegalArgumentException");
- } catch (final IllegalArgumentException ex) {
- assertEquals("MSG", ex.getMessage());
+
+ @Nested
+ class WithMessage {
+
+ @Test
+ void shouldNotThrowExceptionForFiniteValue() {
+ Validate.finite(0.0, "MSG");
+ }
+
+ @Test
+ 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());
+ }
}
}