WordCap implements Comparable<WordCap>, Serializable { @Override public int hashCode() { int result = word.hashCode(); result = 31 * result + (isCapitalized ? 1 : 0); return result; } WordCap(String word, boolean isCapitalized); String getWord(); boolean isCapitalized(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override int compareTo(WordCap o); @Override String toString();  }
@Test public void testHashCode() { WordCap first = new WordCap("aWord", true); WordCap second = new WordCap("aWord", true); assertTrue(first.hashCode() == second.hashCode()); }
@Test public void testHashCodeNonEqual() { WordCap first = new WordCap("aWord", true); WordCap second = new WordCap("aWord", false); assertFalse(first.hashCode() == second.hashCode()); }