Convert tests for Validate.notNaN 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/4077b57f Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/4077b57f Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/4077b57f Branch: refs/heads/master Commit: 4077b57f6dd784b0232db0c66999ff351176c323 Parents: 8912be8 Author: Benedikt Ritter <brit...@apache.org> Authored: Thu Sep 6 19:29:01 2018 +0200 Committer: Benedikt Ritter <brit...@apache.org> Committed: Thu Sep 6 19:29:01 2018 +0200 ---------------------------------------------------------------------- .../org/apache/commons/lang3/ValidateTest.java | 77 ++++++++++++++------ 1 file changed, 56 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/4077b57f/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 43519ea..6ebcefd 100644 --- a/src/test/java/org/apache/commons/lang3/ValidateTest.java +++ b/src/test/java/org/apache/commons/lang3/ValidateTest.java @@ -1107,32 +1107,67 @@ 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()); + } } - } - @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()); + @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()); + } } } + //----------------------------------------------------------------------- //-----------------------------------------------------------------------