From f2b7f988407a55de784f4cb259dc066d3538c5a0 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 9 May 2019 14:34:53 -0400 Subject: [PATCH] Sort methods. --- .../lang3/tuple/ImmutablePairTest.java | 56 +++++------ .../lang3/tuple/ImmutableTripleTest.java | 66 ++++++------- .../commons/lang3/tuple/MutablePairTest.java | 48 ++++----- .../lang3/tuple/MutableTripleTest.java | 62 ++++++------ .../apache/commons/lang3/tuple/PairTest.java | 98 +++++++++---------- .../commons/lang3/tuple/TripleTest.java | 68 ++++++------- 6 files changed, 199 insertions(+), 199 deletions(-) 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 d9635a262..2aca73c23 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/ImmutablePairTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/ImmutablePairTest.java @@ -53,20 +53,6 @@ public class ImmutablePairTest { assertEquals("bar", pair2.getRight()); } - @Test - public void testPairOf() { - final ImmutablePair pair = ImmutablePair.of(0, "foo"); - assertEquals(0, pair.left.intValue()); - assertEquals(0, pair.getLeft().intValue()); - assertEquals("foo", pair.right); - assertEquals("foo", pair.getRight()); - final ImmutablePair pair2 = ImmutablePair.of(null, "bar"); - assertNull(pair2.left); - assertNull(pair2.getLeft()); - assertEquals("bar", pair2.right); - assertEquals("bar", pair2.getRight()); - } - @Test public void testEquals() { assertEquals(ImmutablePair.of(null, "foo"), ImmutablePair.of(null, "foo")); @@ -89,8 +75,8 @@ public class ImmutablePairTest { } @Test - public void testNullPairSame() { - assertSame(ImmutablePair.nullPair(), ImmutablePair.nullPair()); + public void testNullPairKey() { + assertNull(ImmutablePair.nullPair().getKey()); } @Test @@ -98,19 +84,14 @@ public class ImmutablePairTest { assertNull(ImmutablePair.nullPair().getLeft()); } - @Test - public void testNullPairKey() { - assertNull(ImmutablePair.nullPair().getKey()); - } - @Test public void testNullPairRight() { assertNull(ImmutablePair.nullPair().getRight()); } @Test - public void testNullPairValue() { - assertNull(ImmutablePair.nullPair().getValue()); + public void testNullPairSame() { + assertSame(ImmutablePair.nullPair(), ImmutablePair.nullPair()); } @Test @@ -122,11 +103,22 @@ public class ImmutablePairTest { } @Test - public void testToString() { - assertEquals("(null,null)", ImmutablePair.of(null, null).toString()); - assertEquals("(null,two)", ImmutablePair.of(null, "two").toString()); - assertEquals("(one,null)", ImmutablePair.of("one", null).toString()); - assertEquals("(one,two)", ImmutablePair.of("one", "two").toString()); + public void testNullPairValue() { + assertNull(ImmutablePair.nullPair().getValue()); + } + + @Test + public void testPairOf() { + final ImmutablePair pair = ImmutablePair.of(0, "foo"); + assertEquals(0, pair.left.intValue()); + assertEquals(0, pair.getLeft().intValue()); + assertEquals("foo", pair.right); + assertEquals("foo", pair.getRight()); + final ImmutablePair pair2 = ImmutablePair.of(null, "bar"); + assertNull(pair2.left); + assertNull(pair2.getLeft()); + assertEquals("bar", pair2.right); + assertEquals("bar", pair2.getRight()); } @Test @@ -142,6 +134,14 @@ public class ImmutablePairTest { assertEquals(origPair.hashCode(), deserializedPair.hashCode()); } + @Test + public void testToString() { + assertEquals("(null,null)", ImmutablePair.of(null, null).toString()); + assertEquals("(null,two)", ImmutablePair.of(null, "two").toString()); + assertEquals("(one,null)", ImmutablePair.of("one", null).toString()); + assertEquals("(one,two)", ImmutablePair.of("one", "two").toString()); + } + @Test public void testUseAsKeyOfHashMap() { HashMap, String> 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 f5205d254..fc27ac85c 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java @@ -57,24 +57,6 @@ public class ImmutableTripleTest { assertEquals(new Integer(42), triple2.getRight()); } - @Test - public void testTripleOf() { - final ImmutableTriple triple = ImmutableTriple.of(0, "foo", Boolean.FALSE); - assertEquals(0, triple.left.intValue()); - assertEquals(0, triple.getLeft().intValue()); - assertEquals("foo", triple.middle); - assertEquals("foo", triple.getMiddle()); - assertEquals(Boolean.FALSE, triple.right); - assertEquals(Boolean.FALSE, triple.getRight()); - final ImmutableTriple triple2 = ImmutableTriple.of(null, "bar", Boolean.TRUE); - assertNull(triple2.left); - assertNull(triple2.getLeft()); - assertEquals("bar", triple2.middle); - assertEquals("bar", triple2.getMiddle()); - assertEquals(Boolean.TRUE, triple2.right); - assertEquals(Boolean.TRUE, triple2.getRight()); - } - @Test public void testEquals() { assertEquals(ImmutableTriple.of(null, "foo", 42), ImmutableTriple.of(null, "foo", 42)); @@ -96,11 +78,6 @@ public class ImmutableTripleTest { assertEquals(ImmutableTriple.nullTriple(), ImmutableTriple.nullTriple()); } - @Test - public void testNullTripleSame() { - assertSame(ImmutableTriple.nullTriple(), ImmutableTriple.nullTriple()); - } - @Test public void testNullTripleLeft() { assertNull(ImmutableTriple.nullTriple().getLeft()); @@ -116,6 +93,11 @@ public class ImmutableTripleTest { assertNull(ImmutableTriple.nullTriple().getRight()); } + @Test + public void testNullTripleSame() { + assertSame(ImmutableTriple.nullTriple(), ImmutableTriple.nullTriple()); + } + @Test public void testNullTripleTyped() { // No compiler warnings @@ -124,6 +106,19 @@ public class ImmutableTripleTest { assertNotNull(triple); } + @Test + @SuppressWarnings("unchecked") + public void testSerialization() throws Exception { + final ImmutableTriple origTriple = ImmutableTriple.of(0, "foo", Boolean.TRUE); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final ObjectOutputStream out = new ObjectOutputStream(baos); + out.writeObject(origTriple); + final ImmutableTriple deserializedTriple = (ImmutableTriple) new ObjectInputStream( + new ByteArrayInputStream(baos.toByteArray())).readObject(); + assertEquals(origTriple, deserializedTriple); + assertEquals(origTriple.hashCode(), deserializedTriple.hashCode()); + } + @Test public void testToString() { assertEquals("(null,null,null)", ImmutableTriple.of(null, null, null).toString()); @@ -136,16 +131,21 @@ public class ImmutableTripleTest { } @Test - @SuppressWarnings("unchecked") - public void testSerialization() throws Exception { - final ImmutableTriple origTriple = ImmutableTriple.of(0, "foo", Boolean.TRUE); - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(origTriple); - final ImmutableTriple deserializedTriple = (ImmutableTriple) new ObjectInputStream( - new ByteArrayInputStream(baos.toByteArray())).readObject(); - assertEquals(origTriple, deserializedTriple); - assertEquals(origTriple.hashCode(), deserializedTriple.hashCode()); + public void testTripleOf() { + final ImmutableTriple triple = ImmutableTriple.of(0, "foo", Boolean.FALSE); + assertEquals(0, triple.left.intValue()); + assertEquals(0, triple.getLeft().intValue()); + assertEquals("foo", triple.middle); + assertEquals("foo", triple.getMiddle()); + assertEquals(Boolean.FALSE, triple.right); + assertEquals(Boolean.FALSE, triple.getRight()); + final ImmutableTriple triple2 = ImmutableTriple.of(null, "bar", Boolean.TRUE); + assertNull(triple2.left); + assertNull(triple2.getLeft()); + assertEquals("bar", triple2.middle); + assertEquals("bar", triple2.getMiddle()); + assertEquals(Boolean.TRUE, triple2.right); + assertEquals(Boolean.TRUE, triple2.getRight()); } @Test 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 9d456219d..2e2da2388 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/MutablePairTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/MutablePairTest.java @@ -49,6 +49,22 @@ public class MutablePairTest { assertNull(pair.getRight()); } + @Test + public void testEquals() { + assertEquals(MutablePair.of(null, "foo"), MutablePair.of(null, "foo")); + assertNotEquals(MutablePair.of("foo", 0), MutablePair.of("foo", null)); + assertNotEquals(MutablePair.of("foo", "bar"), MutablePair.of("xyz", "bar")); + + final MutablePair p = MutablePair.of("foo", "bar"); + assertEquals(p, p); + assertNotEquals(p, new Object()); + } + + @Test + public void testHashCode() { + assertEquals(MutablePair.of(null, "foo").hashCode(), MutablePair.of(null, "foo").hashCode()); + } + @Test public void testMutate() { final MutablePair pair = new MutablePair<>(0, "foo"); @@ -68,30 +84,6 @@ public class MutablePairTest { assertEquals("bar", pair2.getRight()); } - @Test - public void testEquals() { - assertEquals(MutablePair.of(null, "foo"), MutablePair.of(null, "foo")); - assertNotEquals(MutablePair.of("foo", 0), MutablePair.of("foo", null)); - assertNotEquals(MutablePair.of("foo", "bar"), MutablePair.of("xyz", "bar")); - - final MutablePair p = MutablePair.of("foo", "bar"); - assertEquals(p, p); - assertNotEquals(p, new Object()); - } - - @Test - public void testHashCode() { - assertEquals(MutablePair.of(null, "foo").hashCode(), MutablePair.of(null, "foo").hashCode()); - } - - @Test - public void testToString() { - assertEquals("(null,null)", MutablePair.of(null, null).toString()); - assertEquals("(null,two)", MutablePair.of(null, "two").toString()); - assertEquals("(one,null)", MutablePair.of("one", null).toString()); - assertEquals("(one,two)", MutablePair.of("one", "two").toString()); - } - @Test @SuppressWarnings("unchecked") public void testSerialization() throws Exception { @@ -104,4 +96,12 @@ public class MutablePairTest { assertEquals(origPair, deserializedPair); assertEquals(origPair.hashCode(), deserializedPair.hashCode()); } + + @Test + public void testToString() { + assertEquals("(null,null)", MutablePair.of(null, null).toString()); + assertEquals("(null,two)", MutablePair.of(null, "two").toString()); + assertEquals("(one,null)", MutablePair.of("one", null).toString()); + assertEquals("(one,two)", MutablePair.of("one", "two").toString()); + } } 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 b5cca98ee..0c513c655 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/MutableTripleTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/MutableTripleTest.java @@ -52,29 +52,6 @@ public class MutableTripleTest { assertNull(triple.getRight()); } - @Test - public void testMutate() { - final MutableTriple triple = new MutableTriple<>(0, "foo", Boolean.TRUE); - triple.setLeft(42); - triple.setMiddle("bar"); - triple.setRight(Boolean.FALSE); - assertEquals(42, triple.getLeft().intValue()); - assertEquals("bar", triple.getMiddle()); - assertEquals(Boolean.FALSE, triple.getRight()); - } - - @Test - public void testTripleOf() { - final MutableTriple triple = MutableTriple.of(0, "foo", Boolean.TRUE); - assertEquals(0, triple.getLeft().intValue()); - assertEquals("foo", triple.getMiddle()); - assertEquals(Boolean.TRUE, triple.getRight()); - final MutableTriple triple2 = MutableTriple.of(null, "bar", "hello"); - assertNull(triple2.getLeft()); - assertEquals("bar", triple2.getMiddle()); - assertEquals("hello", triple2.getRight()); - } - @Test public void testEquals() { assertEquals(MutableTriple.of(null, "foo", "baz"), MutableTriple.of(null, "foo", "baz")); @@ -93,14 +70,14 @@ public class MutableTripleTest { } @Test - public void testToString() { - assertEquals("(null,null,null)", MutableTriple.of(null, null, null).toString()); - assertEquals("(null,two,null)", MutableTriple.of(null, "two", null).toString()); - assertEquals("(one,null,null)", MutableTriple.of("one", null, null).toString()); - assertEquals("(one,two,null)", MutableTriple.of("one", "two", null).toString()); - assertEquals("(null,two,three)", MutableTriple.of(null, "two", "three").toString()); - assertEquals("(one,null,three)", MutableTriple.of("one", null, "three").toString()); - assertEquals("(one,two,three)", MutableTriple.of("one", "two", "three").toString()); + public void testMutate() { + final MutableTriple triple = new MutableTriple<>(0, "foo", Boolean.TRUE); + triple.setLeft(42); + triple.setMiddle("bar"); + triple.setRight(Boolean.FALSE); + assertEquals(42, triple.getLeft().intValue()); + assertEquals("bar", triple.getMiddle()); + assertEquals(Boolean.FALSE, triple.getRight()); } @Test @@ -115,5 +92,28 @@ public class MutableTripleTest { assertEquals(origTriple, deserializedTriple); assertEquals(origTriple.hashCode(), deserializedTriple.hashCode()); } + + @Test + public void testToString() { + assertEquals("(null,null,null)", MutableTriple.of(null, null, null).toString()); + assertEquals("(null,two,null)", MutableTriple.of(null, "two", null).toString()); + assertEquals("(one,null,null)", MutableTriple.of("one", null, null).toString()); + assertEquals("(one,two,null)", MutableTriple.of("one", "two", null).toString()); + assertEquals("(null,two,three)", MutableTriple.of(null, "two", "three").toString()); + assertEquals("(one,null,three)", MutableTriple.of("one", null, "three").toString()); + assertEquals("(one,two,three)", MutableTriple.of("one", "two", "three").toString()); + } + + @Test + public void testTripleOf() { + final MutableTriple triple = MutableTriple.of(0, "foo", Boolean.TRUE); + assertEquals(0, triple.getLeft().intValue()); + assertEquals("foo", triple.getMiddle()); + assertEquals(Boolean.TRUE, triple.getRight()); + final MutableTriple triple2 = MutableTriple.of(null, "bar", "hello"); + assertNull(triple2.getLeft()); + assertEquals("bar", triple2.getMiddle()); + assertEquals("hello", triple2.getRight()); + } } 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 39c75eb74..5de6f16e6 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/PairTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/PairTest.java @@ -33,43 +33,6 @@ import org.junit.jupiter.api.Test; */ public class PairTest { - @Test - public void testPairOf() { - final Pair pair = Pair.of(0, "foo"); - assertTrue(pair instanceof ImmutablePair); - assertEquals(0, ((ImmutablePair) pair).left.intValue()); - assertEquals("foo", ((ImmutablePair) pair).right); - final Pair pair2 = Pair.of(null, "bar"); - assertTrue(pair2 instanceof ImmutablePair); - assertNull(((ImmutablePair) pair2).left); - assertEquals("bar", ((ImmutablePair) pair2).right); - } - - @Test - public void testCompatibilityBetweenPairs() { - final Pair pair = ImmutablePair.of(0, "foo"); - final Pair pair2 = MutablePair.of(0, "foo"); - assertEquals(pair, pair2); - assertEquals(pair.hashCode(), pair2.hashCode()); - final HashSet> set = new HashSet<>(); - set.add(pair); - assertTrue(set.contains(pair2)); - - pair2.setValue("bar"); - assertNotEquals(pair, pair2); - assertNotEquals(pair.hashCode(), pair2.hashCode()); - } - - @Test - public void testMapEntry() { - final Pair pair = ImmutablePair.of(0, "foo"); - final HashMap map = new HashMap<>(); - map.put(0, "foo"); - final Entry entry = map.entrySet().iterator().next(); - assertEquals(pair, entry); - assertEquals(pair.hashCode(), entry.hashCode()); - } - @Test public void testComparable1() { final Pair pair1 = Pair.of("A", "D"); @@ -90,6 +53,55 @@ public class PairTest { assertTrue(pair2.compareTo(pair1) > 0); } + @Test + public void testCompatibilityBetweenPairs() { + final Pair pair = ImmutablePair.of(0, "foo"); + final Pair pair2 = MutablePair.of(0, "foo"); + assertEquals(pair, pair2); + assertEquals(pair.hashCode(), pair2.hashCode()); + final HashSet> set = new HashSet<>(); + set.add(pair); + assertTrue(set.contains(pair2)); + + pair2.setValue("bar"); + assertNotEquals(pair, pair2); + assertNotEquals(pair.hashCode(), pair2.hashCode()); + } + + @Test + public void testFormattable_padded() { + final Pair pair = Pair.of("Key", "Value"); + assertEquals(" (Key,Value)", String.format("%1$20s", pair)); + } + + @Test + public void testFormattable_simple() { + final Pair pair = Pair.of("Key", "Value"); + assertEquals("(Key,Value)", String.format("%1$s", pair)); + } + + @Test + public void testMapEntry() { + final Pair pair = ImmutablePair.of(0, "foo"); + final HashMap map = new HashMap<>(); + map.put(0, "foo"); + final Entry entry = map.entrySet().iterator().next(); + assertEquals(pair, entry); + assertEquals(pair.hashCode(), entry.hashCode()); + } + + @Test + public void testPairOf() { + final Pair pair = Pair.of(0, "foo"); + assertTrue(pair instanceof ImmutablePair); + assertEquals(0, ((ImmutablePair) pair).left.intValue()); + assertEquals("foo", ((ImmutablePair) pair).right); + final Pair pair2 = Pair.of(null, "bar"); + assertTrue(pair2 instanceof ImmutablePair); + assertNull(((ImmutablePair) pair2).left); + assertEquals("bar", ((ImmutablePair) pair2).right); + } + @Test public void testToString() { final Pair pair = Pair.of("Key", "Value"); @@ -104,16 +116,4 @@ public class PairTest { assertEquals("Test created on " + "04-25-2011", pair.toString("Test created on %2$tm-%2$td-%2$tY")); } - @Test - public void testFormattable_simple() { - final Pair pair = Pair.of("Key", "Value"); - assertEquals("(Key,Value)", String.format("%1$s", pair)); - } - - @Test - public void testFormattable_padded() { - final Pair pair = Pair.of("Key", "Value"); - assertEquals(" (Key,Value)", String.format("%1$20s", pair)); - } - } 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 48ba48f9e..aad03731a 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/TripleTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/TripleTest.java @@ -30,31 +30,6 @@ import org.junit.jupiter.api.Test; */ public class TripleTest { - @Test - public void testTripleOf() { - final Triple triple = Triple.of(0, "foo", Boolean.TRUE); - assertTrue(triple instanceof ImmutableTriple); - assertEquals(0, ((ImmutableTriple) triple).left.intValue()); - assertEquals("foo", ((ImmutableTriple) triple).middle); - assertEquals(Boolean.TRUE, ((ImmutableTriple) triple).right); - final Triple triple2 = Triple.of(null, "bar", Long.valueOf(200L)); - assertTrue(triple2 instanceof ImmutableTriple); - assertNull(((ImmutableTriple) triple2).left); - assertEquals("bar", ((ImmutableTriple) triple2).middle); - assertEquals(new Long(200L), ((ImmutableTriple) triple2).right); - } - - @Test - public void testCompatibilityBetweenTriples() { - final Triple triple = ImmutableTriple.of(0, "foo", Boolean.TRUE); - final Triple triple2 = MutableTriple.of(0, "foo", Boolean.TRUE); - assertEquals(triple, triple2); - assertEquals(triple.hashCode(), triple2.hashCode()); - final HashSet> set = new HashSet<>(); - set.add(triple); - assertTrue(set.contains(triple2)); - } - @Test public void testComparable1() { final Triple triple1 = Triple.of("A", "D", "A"); @@ -95,6 +70,29 @@ public class TripleTest { assertTrue(triple2.compareTo(triple1) > 0); } + @Test + public void testCompatibilityBetweenTriples() { + final Triple triple = ImmutableTriple.of(0, "foo", Boolean.TRUE); + final Triple triple2 = MutableTriple.of(0, "foo", Boolean.TRUE); + assertEquals(triple, triple2); + assertEquals(triple.hashCode(), triple2.hashCode()); + final HashSet> set = new HashSet<>(); + set.add(triple); + assertTrue(set.contains(triple2)); + } + + @Test + public void testFormattable_padded() { + final Triple triple = Triple.of("Key", "Something", "Value"); + assertEquals(" (Key,Something,Value)", String.format("%1$30s", triple)); + } + + @Test + public void testFormattable_simple() { + final Triple triple = Triple.of("Key", "Something", "Value"); + assertEquals("(Key,Something,Value)", String.format("%1$s", triple)); + } + @Test public void testToString() { final Triple triple = Triple.of("Key", "Something", "Value"); @@ -110,15 +108,17 @@ public class TripleTest { } @Test - public void testFormattable_simple() { - final Triple triple = Triple.of("Key", "Something", "Value"); - assertEquals("(Key,Something,Value)", String.format("%1$s", triple)); - } - - @Test - public void testFormattable_padded() { - final Triple triple = Triple.of("Key", "Something", "Value"); - assertEquals(" (Key,Something,Value)", String.format("%1$30s", triple)); + public void testTripleOf() { + final Triple triple = Triple.of(0, "foo", Boolean.TRUE); + assertTrue(triple instanceof ImmutableTriple); + assertEquals(0, ((ImmutableTriple) triple).left.intValue()); + assertEquals("foo", ((ImmutableTriple) triple).middle); + assertEquals(Boolean.TRUE, ((ImmutableTriple) triple).right); + final Triple triple2 = Triple.of(null, "bar", Long.valueOf(200L)); + assertTrue(triple2 instanceof ImmutableTriple); + assertNull(((ImmutableTriple) triple2).left); + assertEquals("bar", ((ImmutableTriple) triple2).middle); + assertEquals(new Long(200L), ((ImmutableTriple) triple2).right); } }