AnnouncementPresenter extends RxPresenter<AnnouncementView, ArrayList<Announcement>> implements Comparator<Announcement> { @Override public int compare(Announcement lhs, Announcement rhs) { if (!rhs.getPinned() && !lhs.getPinned()) return DateTimeComparator.getInstance().compare(rhs.getCreatedAt(), lhs.getCreatedAt()); else if (rhs.getPinned() && lhs.getPinned()) return DateTimeComparator.getInstance().compare(rhs.getCreatedAt(), lhs.getCreatedAt()); else if (rhs.getPinned()) return RIGHT_FIRST; return LEFT_FIRST; }  void updateAnnouncements(); @Override int compare(Announcement lhs, Announcement rhs);  }
@Test public void testCompare() throws Exception { Announcement rhsPin = new Announcement(); rhsPin.setPinned(1); Announcement lhsPin = new Announcement(); lhsPin.setPinned(1); Announcement rhsNoPin = new Announcement(); rhsNoPin.setPinned(0); Announcement lhsNoPin = new Announcement(); lhsNoPin.setPinned(0); assertEquals(1, presenter.compare(lhsNoPin, rhsPin)); assertEquals(-1, presenter.compare(lhsPin, rhsNoPin)); lhsNoPin.setCreatedAt("2016-02-28T22:15:00"); rhsNoPin.setCreatedAt("2016-02-28T22:15:00"); assertEquals(0, presenter.compare(lhsNoPin, rhsNoPin)); lhsNoPin.setCreatedAt("2016-02-28T21:15:00"); assertEquals(-1, presenter.compare(rhsNoPin, lhsNoPin)); rhsNoPin.setCreatedAt("2016-02-28T20:15:00"); assertEquals(1, presenter.compare(rhsNoPin, lhsNoPin)); }