ofNonNull(final L left, final M middle, final R right) {
+ return ImmutableTriple.ofNonNull(left, middle, right);
+ }
+
/**
* Compares the triple based on the left element, followed by the middle element,
* finally the right element.
diff --git a/src/test/java/org/apache/commons/lang3/tuple/ImmutablePairTest.java b/src/test/java/org/apache/commons/lang3/tuple/ImmutablePairTest.java
index c1b9f357c..2bfa17e91 100644
--- a/src/test/java/org/apache/commons/lang3/tuple/ImmutablePairTest.java
+++ b/src/test/java/org/apache/commons/lang3/tuple/ImmutablePairTest.java
@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ArrayList;
import java.util.HashMap;
@@ -154,6 +155,16 @@ public class ImmutablePairTest {
assertNull(ImmutablePair.nullPair().getValue());
}
+ @Test
+ public void testOfNonNull() {
+ assertThrows(NullPointerException.class, () -> ImmutablePair.ofNonNull(null, null));
+ assertThrows(NullPointerException.class, () -> ImmutablePair.ofNonNull(null, "x"));
+ assertThrows(NullPointerException.class, () -> ImmutablePair.ofNonNull("x", null));
+ final ImmutablePair pair = ImmutablePair.ofNonNull("x", "y");
+ assertEquals("x", pair.left);
+ assertEquals("y", pair.right);
+ }
+
@Test
public void testPairOfMapEntry() {
final HashMap map = new HashMap<>();
diff --git a/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java b/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java
index dc01ac5b3..ddaea459d 100644
--- a/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java
+++ b/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java
@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ArrayList;
import java.util.HashMap;
@@ -116,6 +117,19 @@ public class ImmutableTripleTest {
assertNotNull(triple);
}
+ @Test
+ public void testOfNonNull() {
+ assertThrows(NullPointerException.class, () -> ImmutableTriple.ofNonNull(null, null, null));
+ assertThrows(NullPointerException.class, () -> ImmutableTriple.ofNonNull(null, null, "z"));
+ assertThrows(NullPointerException.class, () -> ImmutableTriple.ofNonNull(null, "y", "z"));
+ assertThrows(NullPointerException.class, () -> ImmutableTriple.ofNonNull("x", null, null));
+ assertThrows(NullPointerException.class, () -> ImmutableTriple.ofNonNull("x", "y", null));
+ final ImmutableTriple pair = ImmutableTriple.ofNonNull("x", "y", "z");
+ assertEquals("x", pair.left);
+ assertEquals("y", pair.middle);
+ assertEquals("z", pair.right);
+ }
+
@Test
@SuppressWarnings("unchecked")
public void testSerialization() throws Exception {
diff --git a/src/test/java/org/apache/commons/lang3/tuple/MutablePairTest.java b/src/test/java/org/apache/commons/lang3/tuple/MutablePairTest.java
index 045b02c30..1497a3614 100644
--- a/src/test/java/org/apache/commons/lang3/tuple/MutablePairTest.java
+++ b/src/test/java/org/apache/commons/lang3/tuple/MutablePairTest.java
@@ -19,6 +19,7 @@ package org.apache.commons.lang3.tuple;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.HashMap;
import java.util.Map.Entry;
@@ -102,6 +103,16 @@ public class MutablePairTest {
assertEquals("bar", pair.getRight());
}
+ @Test
+ public void testOfNonNull() {
+ assertThrows(NullPointerException.class, () -> MutablePair.ofNonNull(null, null));
+ assertThrows(NullPointerException.class, () -> MutablePair.ofNonNull(null, "x"));
+ assertThrows(NullPointerException.class, () -> MutablePair.ofNonNull("x", null));
+ final MutablePair pair = MutablePair.ofNonNull("x", "y");
+ assertEquals("x", pair.left);
+ assertEquals("y", pair.right);
+ }
+
@Test
public void testPairOfMapEntry() {
final HashMap map = new HashMap<>();
diff --git a/src/test/java/org/apache/commons/lang3/tuple/MutableTripleTest.java b/src/test/java/org/apache/commons/lang3/tuple/MutableTripleTest.java
index d4de141a3..059ee8baf 100644
--- a/src/test/java/org/apache/commons/lang3/tuple/MutableTripleTest.java
+++ b/src/test/java/org/apache/commons/lang3/tuple/MutableTripleTest.java
@@ -19,6 +19,7 @@ package org.apache.commons.lang3.tuple;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.commons.lang3.SerializationUtils;
import org.junit.jupiter.api.Test;
@@ -28,6 +29,20 @@ import org.junit.jupiter.api.Test;
*/
public class MutableTripleTest {
+ @Test
+ public void testOfNonNull() {
+ assertThrows(NullPointerException.class, () -> MutableTriple.ofNonNull(null, null, null));
+ assertThrows(NullPointerException.class, () -> MutableTriple.ofNonNull(null, null, "z"));
+ assertThrows(NullPointerException.class, () -> MutableTriple.ofNonNull(null, "y", "z"));
+ assertThrows(NullPointerException.class, () -> MutableTriple.ofNonNull("x", null, null));
+ assertThrows(NullPointerException.class, () -> MutableTriple.ofNonNull("x", "y", null));
+ final MutableTriple pair = MutableTriple.ofNonNull("x", "y", "z");
+ assertEquals("x", pair.left);
+ assertEquals("y", pair.middle);
+ assertEquals("z", pair.right);
+ }
+
+
@Test
public void testBasic() {
final MutableTriple triple = new MutableTriple<>(0, "foo", Boolean.FALSE);
diff --git a/src/test/java/org/apache/commons/lang3/tuple/PairTest.java b/src/test/java/org/apache/commons/lang3/tuple/PairTest.java
index 80bae1210..4640a9c07 100644
--- a/src/test/java/org/apache/commons/lang3/tuple/PairTest.java
+++ b/src/test/java/org/apache/commons/lang3/tuple/PairTest.java
@@ -19,6 +19,7 @@ package org.apache.commons.lang3.tuple;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Calendar;
@@ -103,6 +104,16 @@ public class PairTest {
assertEquals(pair.hashCode(), entry.hashCode());
}
+ @Test
+ public void testOfNonNull() {
+ assertThrows(NullPointerException.class, () -> Pair.ofNonNull(null, null));
+ assertThrows(NullPointerException.class, () -> Pair.ofNonNull(null, "x"));
+ assertThrows(NullPointerException.class, () -> Pair.ofNonNull("x", null));
+ final Pair pair = Pair.ofNonNull("x", "y");
+ assertEquals("x", pair.getLeft());
+ assertEquals("y", pair.getRight());
+ }
+
@Test
public void testPairOfMapEntry() {
final HashMap map = new HashMap<>();
diff --git a/src/test/java/org/apache/commons/lang3/tuple/TripleTest.java b/src/test/java/org/apache/commons/lang3/tuple/TripleTest.java
index b9ae9de68..496785873 100644
--- a/src/test/java/org/apache/commons/lang3/tuple/TripleTest.java
+++ b/src/test/java/org/apache/commons/lang3/tuple/TripleTest.java
@@ -18,6 +18,7 @@ package org.apache.commons.lang3.tuple;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Calendar;
@@ -30,6 +31,19 @@ import org.junit.jupiter.api.Test;
*/
public class TripleTest {
+ @Test
+ public void testOfNonNull() {
+ assertThrows(NullPointerException.class, () -> Triple.ofNonNull(null, null, null));
+ assertThrows(NullPointerException.class, () -> Triple.ofNonNull(null, null, "z"));
+ assertThrows(NullPointerException.class, () -> Triple.ofNonNull(null, "y", "z"));
+ assertThrows(NullPointerException.class, () -> Triple.ofNonNull("x", null, null));
+ assertThrows(NullPointerException.class, () -> Triple.ofNonNull("x", "y", null));
+ final Triple pair = Triple.ofNonNull("x", "y", "z");
+ assertEquals("x", pair.getLeft());
+ assertEquals("y", pair.getMiddle());
+ assertEquals("z", pair.getRight());
+ }
+
@Test
public void testComparable1() {
final Triple triple1 = Triple.of("A", "D", "A");