### Question:
Pair { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Pair<?, ?> other = (Pair<?, ?>) obj; if (left == null) { if (other.left != null) { return false; } } else if (!left.equals(other.left)) { return false; } if (right == null) { if (other.right != null) { return false; } } else if (!right.equals(other.right)) { return false; } return true; } Pair(L l, R r); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); public L left; public R right; }### Answer:
@Test public void testEqualsObject() { Pair<String, Integer> p1 = new Pair<String, Integer>("a", 123123); Pair<String, Integer> p2 = new Pair<String, Integer>("a", 123123); assertTrue(p1.equals(p2)); p1 = new Pair<String, Integer>("a", null); p2 = new Pair<String, Integer>("a", 123123); assertFalse(p1.equals(p2)); p1 = new Pair<String, Integer>("a", 123123); p2 = new Pair<String, Integer>("a", null); assertFalse(p1.equals(p2)); p1 = new Pair<String, Integer>(null, 123123); p2 = new Pair<String, Integer>("a", 123123); assertFalse(p1.equals(p2)); p1 = new Pair<String, Integer>("a", 123123); p2 = new Pair<String, Integer>(null, 123123); assertFalse(p1.equals(p2)); p1 = new Pair<String, Integer>(null, 123123); p2 = null; assertFalse(p1.equals(p2)); p1 = new Pair<String, Integer>(null, 123123); p2 = new Pair<String, Integer>(null, 123123); Map<Pair<String, Integer>, Integer> map = new HashMap<Pair<String, Integer>, Integer>(); map.put(p1, 1); assertTrue(map.containsKey(p2)); assertTrue(p1.equals(p2)); p1 = new Pair<String, Integer>("a", null); p2 = new Pair<String, Integer>("a", null); assertTrue(p1.equals(p2)); assertTrue(p1.equals(p1)); assertFalse(p1.equals(new Integer(1))); }