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:24 UTC
[02/16] [lang] Convert tests for Validate.notNull overloads to
@Nested test
Convert tests for Validate.notNull 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/d3f2a89b
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/d3f2a89b
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/d3f2a89b
Branch: refs/heads/master
Commit: d3f2a89ba229c57073e4f2a63a9a7f1053a5720d
Parents: aad2db8
Author: Benedikt Ritter <br...@apache.org>
Authored: Thu Sep 6 10:16:26 2018 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Thu Sep 6 10:16:26 2018 +0200
----------------------------------------------------------------------
.../org/apache/commons/lang3/ValidateTest.java | 79 +++++++++++++-------
1 file changed, 50 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/d3f2a89b/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 c4cbe07..2c1c6cb 100644
--- a/src/test/java/org/apache/commons/lang3/ValidateTest.java
+++ b/src/test/java/org/apache/commons/lang3/ValidateTest.java
@@ -139,39 +139,60 @@ class ValidateTest {
}
}
- //-----------------------------------------------------------------------
- //-----------------------------------------------------------------------
- @SuppressWarnings("unused")
- @Test
- void testNotNull1() {
- Validate.notNull(new Object());
- try {
- Validate.notNull(null);
- fail("Expecting NullPointerException");
- } catch (final NullPointerException ex) {
- assertEquals("The validated object is null", ex.getMessage());
- }
+ @Nested
+ class NotNull {
- final String str = "Hi";
- final String testStr = Validate.notNull(str);
- assertSame(str, testStr);
- }
+ @Nested
+ class WithoutMessage {
- //-----------------------------------------------------------------------
- @SuppressWarnings("unused")
- @Test
- void testNotNull2() {
- Validate.notNull(new Object(), "MSG");
- try {
- Validate.notNull(null, "MSG");
- fail("Expecting NullPointerException");
- } catch (final NullPointerException ex) {
- assertEquals("MSG", ex.getMessage());
+ @Test
+ void shouldNotThrowForNonNullReference() {
+ Validate.notNull(new Object());
+ }
+
+ @Test
+ void shouldReturnTheSameInstance() {
+ final String str = "Hi";
+ final String result = Validate.notNull(str);
+
+ assertSame(str, result);
+ }
+
+ @Test
+ void shouldThrowExceptionWithDefaultMessageForNullReference() {
+ final NullPointerException ex = assertThrows(
+ NullPointerException.class,
+ () -> Validate.notNull(null));
+
+ assertEquals("The validated object is null", ex.getMessage());
+ }
}
- final String str = "Hi";
- final String testStr = Validate.notNull(str, "Message");
- assertSame(str, testStr);
+ @Nested
+ class WithMessage {
+
+ @Test
+ void shouldNotThrowForNonNullReference() {
+ Validate.notNull(new Object(), "MSG");
+ }
+
+ @Test
+ void shouldReturnTheSameInstance() {
+ final String str = "Hi";
+ final String result = Validate.notNull(str, "MSG");
+
+ assertSame(str, result);
+ }
+
+ @Test
+ void shouldThrowExceptionWithGivenMessageForNullReference() {
+ final NullPointerException ex = assertThrows(
+ NullPointerException.class,
+ () -> Validate.notNull(null, "MSG"));
+
+ assertEquals("MSG", ex.getMessage());
+ }
+ }
}
//-----------------------------------------------------------------------