CategorySummaryAmountDescendingComparator implements Comparator<CategorySummary> { @Override public int compare(CategorySummary o1, CategorySummary o2) { int i = Long.valueOf(o1.getAmount()).compareTo(o2.getAmount()); if (i == 0) { i = o1.getName().compareToIgnoreCase(o2.getName()); } return i; }  @Override int compare(CategorySummary o1, CategorySummary o2);  }
@Test public void compareTo() { CategorySummary summary1 = new CategorySummary("one", -1); CategorySummary summary2 = new CategorySummary("two", -2); assertEquals(0, comparator.compare(summary1, summary1)); assertEquals(0, comparator.compare(summary2, summary2)); assertEquals(1, comparator.compare(summary1, summary2)); assertEquals(-1, comparator.compare(summary2, summary1)); }