WordCap implements Comparable<WordCap>, Serializable { @Override public int compareTo(WordCap o) { int result = this.word.compareTo(o.word); if (result == 0) { result = Boolean.compare(this.isCapitalized, o.isCapitalized); } 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 testCompareToWord() { WordCap first = new WordCap("first", false); WordCap second = new WordCap("second", false); assertEquals(first.compareTo(second), "first".compareTo("second")); }
@Test public void testCompareToCapitalization() { WordCap first = new WordCap("aWord", true); WordCap second = new WordCap("aWord", false); assertEquals(first.compareTo(second), Boolean.compare(true, false)); }