Pair { @Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final Pair<?, ?> other = (Pair<?, ?>) obj; if (first == null) { if (other.first != null) return false; } else if (!first.equals(other.first)) return false; if (second == null) { if (other.second != null) return false; } else if (!second.equals(other.second)) return false; return true; } Pair(final F first, final S second); F getFirst(); S getSecond(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString();  }
@Test public void testEquals() { assertTrue(pair1.equals(pair1)); assertTrue(pair1.equals(new Pair<>(o1, o2))); assertEquals(pair1.hashCode(), new Pair<>(o1, o2).hashCode()); assertTrue(new Pair<>(null, o2).equals(new Pair<>(null, o2))); assertEquals(new Pair<>(null, o2).hashCode(), new Pair<>(null, o2).hashCode()); assertTrue(new Pair<>(o1, null).equals(new Pair<>(o1, null))); assertEquals(new Pair<>(o1, null).hashCode(), new Pair<>(o1, null).hashCode()); }
@Test public void testNotEquals() { assertFalse(pair1.equals(null)); assertFalse(pair1.equals(new Object())); assertFalse(pair1.equals(new Pair<>(null, o2))); assertFalse(pair1.equals(new Pair<>(o1, null))); assertFalse(new Pair<>(null, o2).equals(pair1)); assertFalse(new Pair<>(o1, null).equals(pair1)); }