Sort methods.
This commit is contained in:
parent
daf3dacd2c
commit
f2b7f98840
|
@ -53,20 +53,6 @@ public class ImmutablePairTest {
|
|||
assertEquals("bar", pair2.getRight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPairOf() {
|
||||
final ImmutablePair<Integer, String> 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<Object, String> 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<Integer, String> 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<Object, String> 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<ImmutablePair<Object, Object>, String> map = new HashMap<>();
|
||||
|
|
|
@ -57,24 +57,6 @@ public class ImmutableTripleTest {
|
|||
assertEquals(new Integer(42), triple2.getRight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTripleOf() {
|
||||
final ImmutableTriple<Integer, String, Boolean> 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<Object, String, Boolean> 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<Integer, String, Boolean> origTriple = ImmutableTriple.of(0, "foo", Boolean.TRUE);
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream out = new ObjectOutputStream(baos);
|
||||
out.writeObject(origTriple);
|
||||
final ImmutableTriple<Integer, String, Boolean> deserializedTriple = (ImmutableTriple<Integer, String, Boolean>) 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<Integer, String, Boolean> origTriple = ImmutableTriple.of(0, "foo", Boolean.TRUE);
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream out = new ObjectOutputStream(baos);
|
||||
out.writeObject(origTriple);
|
||||
final ImmutableTriple<Integer, String, Boolean> deserializedTriple = (ImmutableTriple<Integer, String, Boolean>) new ObjectInputStream(
|
||||
new ByteArrayInputStream(baos.toByteArray())).readObject();
|
||||
assertEquals(origTriple, deserializedTriple);
|
||||
assertEquals(origTriple.hashCode(), deserializedTriple.hashCode());
|
||||
public void testTripleOf() {
|
||||
final ImmutableTriple<Integer, String, Boolean> 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<Object, String, Boolean> 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
|
||||
|
|
|
@ -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<String, String> 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<Integer, String> 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<String, String> 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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,29 +52,6 @@ public class MutableTripleTest {
|
|||
assertNull(triple.getRight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMutate() {
|
||||
final MutableTriple<Integer, String, Boolean> 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<Integer, String, Boolean> triple = MutableTriple.of(0, "foo", Boolean.TRUE);
|
||||
assertEquals(0, triple.getLeft().intValue());
|
||||
assertEquals("foo", triple.getMiddle());
|
||||
assertEquals(Boolean.TRUE, triple.getRight());
|
||||
final MutableTriple<Object, String, String> 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<Integer, String, Boolean> 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<Integer, String, Boolean> triple = MutableTriple.of(0, "foo", Boolean.TRUE);
|
||||
assertEquals(0, triple.getLeft().intValue());
|
||||
assertEquals("foo", triple.getMiddle());
|
||||
assertEquals(Boolean.TRUE, triple.getRight());
|
||||
final MutableTriple<Object, String, String> triple2 = MutableTriple.of(null, "bar", "hello");
|
||||
assertNull(triple2.getLeft());
|
||||
assertEquals("bar", triple2.getMiddle());
|
||||
assertEquals("hello", triple2.getRight());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,43 +33,6 @@ import org.junit.jupiter.api.Test;
|
|||
*/
|
||||
public class PairTest {
|
||||
|
||||
@Test
|
||||
public void testPairOf() {
|
||||
final Pair<Integer, String> pair = Pair.of(0, "foo");
|
||||
assertTrue(pair instanceof ImmutablePair<?, ?>);
|
||||
assertEquals(0, ((ImmutablePair<Integer, String>) pair).left.intValue());
|
||||
assertEquals("foo", ((ImmutablePair<Integer, String>) pair).right);
|
||||
final Pair<Object, String> pair2 = Pair.of(null, "bar");
|
||||
assertTrue(pair2 instanceof ImmutablePair<?, ?>);
|
||||
assertNull(((ImmutablePair<Object, String>) pair2).left);
|
||||
assertEquals("bar", ((ImmutablePair<Object, String>) pair2).right);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompatibilityBetweenPairs() {
|
||||
final Pair<Integer, String> pair = ImmutablePair.of(0, "foo");
|
||||
final Pair<Integer, String> pair2 = MutablePair.of(0, "foo");
|
||||
assertEquals(pair, pair2);
|
||||
assertEquals(pair.hashCode(), pair2.hashCode());
|
||||
final HashSet<Pair<Integer, String>> 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<Integer, String> pair = ImmutablePair.of(0, "foo");
|
||||
final HashMap<Integer, String> map = new HashMap<>();
|
||||
map.put(0, "foo");
|
||||
final Entry<Integer, String> entry = map.entrySet().iterator().next();
|
||||
assertEquals(pair, entry);
|
||||
assertEquals(pair.hashCode(), entry.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComparable1() {
|
||||
final Pair<String, String> pair1 = Pair.of("A", "D");
|
||||
|
@ -90,6 +53,55 @@ public class PairTest {
|
|||
assertTrue(pair2.compareTo(pair1) > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompatibilityBetweenPairs() {
|
||||
final Pair<Integer, String> pair = ImmutablePair.of(0, "foo");
|
||||
final Pair<Integer, String> pair2 = MutablePair.of(0, "foo");
|
||||
assertEquals(pair, pair2);
|
||||
assertEquals(pair.hashCode(), pair2.hashCode());
|
||||
final HashSet<Pair<Integer, String>> 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<String, String> pair = Pair.of("Key", "Value");
|
||||
assertEquals(" (Key,Value)", String.format("%1$20s", pair));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattable_simple() {
|
||||
final Pair<String, String> pair = Pair.of("Key", "Value");
|
||||
assertEquals("(Key,Value)", String.format("%1$s", pair));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapEntry() {
|
||||
final Pair<Integer, String> pair = ImmutablePair.of(0, "foo");
|
||||
final HashMap<Integer, String> map = new HashMap<>();
|
||||
map.put(0, "foo");
|
||||
final Entry<Integer, String> entry = map.entrySet().iterator().next();
|
||||
assertEquals(pair, entry);
|
||||
assertEquals(pair.hashCode(), entry.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPairOf() {
|
||||
final Pair<Integer, String> pair = Pair.of(0, "foo");
|
||||
assertTrue(pair instanceof ImmutablePair<?, ?>);
|
||||
assertEquals(0, ((ImmutablePair<Integer, String>) pair).left.intValue());
|
||||
assertEquals("foo", ((ImmutablePair<Integer, String>) pair).right);
|
||||
final Pair<Object, String> pair2 = Pair.of(null, "bar");
|
||||
assertTrue(pair2 instanceof ImmutablePair<?, ?>);
|
||||
assertNull(((ImmutablePair<Object, String>) pair2).left);
|
||||
assertEquals("bar", ((ImmutablePair<Object, String>) pair2).right);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
final Pair<String, String> 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<String, String> pair = Pair.of("Key", "Value");
|
||||
assertEquals("(Key,Value)", String.format("%1$s", pair));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattable_padded() {
|
||||
final Pair<String, String> pair = Pair.of("Key", "Value");
|
||||
assertEquals(" (Key,Value)", String.format("%1$20s", pair));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,31 +30,6 @@ import org.junit.jupiter.api.Test;
|
|||
*/
|
||||
public class TripleTest {
|
||||
|
||||
@Test
|
||||
public void testTripleOf() {
|
||||
final Triple<Integer, String, Boolean> triple = Triple.of(0, "foo", Boolean.TRUE);
|
||||
assertTrue(triple instanceof ImmutableTriple<?, ?, ?>);
|
||||
assertEquals(0, ((ImmutableTriple<Integer, String, Boolean>) triple).left.intValue());
|
||||
assertEquals("foo", ((ImmutableTriple<Integer, String, Boolean>) triple).middle);
|
||||
assertEquals(Boolean.TRUE, ((ImmutableTriple<Integer, String, Boolean>) triple).right);
|
||||
final Triple<Object, String, Long> triple2 = Triple.of(null, "bar", Long.valueOf(200L));
|
||||
assertTrue(triple2 instanceof ImmutableTriple<?, ?, ?>);
|
||||
assertNull(((ImmutableTriple<Object, String, Long>) triple2).left);
|
||||
assertEquals("bar", ((ImmutableTriple<Object, String, Long>) triple2).middle);
|
||||
assertEquals(new Long(200L), ((ImmutableTriple<Object, String, Long>) triple2).right);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompatibilityBetweenTriples() {
|
||||
final Triple<Integer, String, Boolean> triple = ImmutableTriple.of(0, "foo", Boolean.TRUE);
|
||||
final Triple<Integer, String, Boolean> triple2 = MutableTriple.of(0, "foo", Boolean.TRUE);
|
||||
assertEquals(triple, triple2);
|
||||
assertEquals(triple.hashCode(), triple2.hashCode());
|
||||
final HashSet<Triple<Integer, String, Boolean>> set = new HashSet<>();
|
||||
set.add(triple);
|
||||
assertTrue(set.contains(triple2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComparable1() {
|
||||
final Triple<String, String, String> triple1 = Triple.of("A", "D", "A");
|
||||
|
@ -95,6 +70,29 @@ public class TripleTest {
|
|||
assertTrue(triple2.compareTo(triple1) > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompatibilityBetweenTriples() {
|
||||
final Triple<Integer, String, Boolean> triple = ImmutableTriple.of(0, "foo", Boolean.TRUE);
|
||||
final Triple<Integer, String, Boolean> triple2 = MutableTriple.of(0, "foo", Boolean.TRUE);
|
||||
assertEquals(triple, triple2);
|
||||
assertEquals(triple.hashCode(), triple2.hashCode());
|
||||
final HashSet<Triple<Integer, String, Boolean>> set = new HashSet<>();
|
||||
set.add(triple);
|
||||
assertTrue(set.contains(triple2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattable_padded() {
|
||||
final Triple<String, String, String> triple = Triple.of("Key", "Something", "Value");
|
||||
assertEquals(" (Key,Something,Value)", String.format("%1$30s", triple));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattable_simple() {
|
||||
final Triple<String, String, String> triple = Triple.of("Key", "Something", "Value");
|
||||
assertEquals("(Key,Something,Value)", String.format("%1$s", triple));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
final Triple<String, String, String> triple = Triple.of("Key", "Something", "Value");
|
||||
|
@ -110,15 +108,17 @@ public class TripleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFormattable_simple() {
|
||||
final Triple<String, String, String> triple = Triple.of("Key", "Something", "Value");
|
||||
assertEquals("(Key,Something,Value)", String.format("%1$s", triple));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattable_padded() {
|
||||
final Triple<String, String, String> triple = Triple.of("Key", "Something", "Value");
|
||||
assertEquals(" (Key,Something,Value)", String.format("%1$30s", triple));
|
||||
public void testTripleOf() {
|
||||
final Triple<Integer, String, Boolean> triple = Triple.of(0, "foo", Boolean.TRUE);
|
||||
assertTrue(triple instanceof ImmutableTriple<?, ?, ?>);
|
||||
assertEquals(0, ((ImmutableTriple<Integer, String, Boolean>) triple).left.intValue());
|
||||
assertEquals("foo", ((ImmutableTriple<Integer, String, Boolean>) triple).middle);
|
||||
assertEquals(Boolean.TRUE, ((ImmutableTriple<Integer, String, Boolean>) triple).right);
|
||||
final Triple<Object, String, Long> triple2 = Triple.of(null, "bar", Long.valueOf(200L));
|
||||
assertTrue(triple2 instanceof ImmutableTriple<?, ?, ?>);
|
||||
assertNull(((ImmutableTriple<Object, String, Long>) triple2).left);
|
||||
assertEquals("bar", ((ImmutableTriple<Object, String, Long>) triple2).middle);
|
||||
assertEquals(new Long(200L), ((ImmutableTriple<Object, String, Long>) triple2).right);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue