PrizePresenter extends RxPresenter<PrizeView, ArrayList<Prize> > implements Comparator<Prize> { @Override public int compare(Prize lhs, Prize rhs) { if (lhs.getSponsor().getLevel() - rhs.getSponsor().getLevel() != 0) return lhs.getSponsor().getLevel() - rhs.getSponsor().getLevel(); return lhs.getName().compareTo(rhs.getName()); }  void updatePrizes(); @Override int compare(Prize lhs, Prize rhs);  }
@Test public void testCompare() throws Exception { Company rhsCompany = mock(Company.class); Company lhsCompany = mock(Company.class); Prize rhsPrize = mock(Prize.class); Prize lhsPrize = mock(Prize.class); when(rhsPrize.getSponsor()).thenReturn(rhsCompany); when(lhsPrize.getSponsor()).thenReturn(lhsCompany); when(rhsCompany.getLevel()).thenReturn(2); when(rhsPrize.getName()).thenReturn("rhsPrize"); when(lhsCompany.getLevel()).thenReturn(2); when(lhsPrize.getName()).thenReturn("lhsPrize"); assertEquals(lhsPrize.getName().compareTo(rhsPrize.getName()), presenter.compare(lhsPrize, rhsPrize)); when(rhsCompany.getLevel()).thenReturn(5); when(lhsCompany.getLevel()).thenReturn(4); assertEquals(lhsPrize.getSponsor().getLevel() - rhsPrize.getSponsor().getLevel(), presenter.compare(lhsPrize, rhsPrize)); }