Pair { @Override public int hashCode() { int result = 0; if (left != null) result += left.hashCode(); if (right != null) result = 31 * result + right.hashCode(); return result; } Pair(T left, U right); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); public T left; public U right; }
@Test public void pairWithLeftNullAreEqual() { Pair<Command, Command> pair1 = new Pair<Command, Command>(null, Command.HasData); Pair<Command, Command> pair2 = new Pair<Command, Command>(null, Command.HasData); assertEquals(pair1, pair2); assertEquals(pair1.hashCode(), pair2.hashCode()); }
@Test public void pairWithRightNullAreEqual() { Pair<Command, Command> pair1 = new Pair<Command, Command>(Command.HasData, null); Pair<Command, Command> pair2 = new Pair<Command, Command>(Command.HasData, null); assertEquals(pair1, pair2); assertEquals(pair1.hashCode(), pair2.hashCode()); }