FinishedTorrentsDetector { public long findLastFinishedDate(Collection<Torrent> torrents) { if (torrents.isEmpty()) return -1; List<Torrent> sortedTorrents = sortByDoneDate(torrents); return sortedTorrents.get(0).getDoneDate(); }  Collection<Torrent> filterFinishedTorrentsToNotify(Collection<Torrent> torrents, Server server); long findLastFinishedDate(Collection<Torrent> torrents);  }
@Test public void testFindLastFinishedDate() { Collection<Torrent> torrents = ImmutableSet.of( new Torrent.Builder().doneDate(-1L).build(), new Torrent.Builder().doneDate(100L).build(), new Torrent.Builder().doneDate(555L).build(), new Torrent.Builder().doneDate(873L).build(), new Torrent.Builder().doneDate(0L).build() ); assertThat(detector.findLastFinishedDate(torrents), equalTo(873L)); }
@Test public void testFindLastFinishedDateWithEmptyList() { assertThat(detector.findLastFinishedDate(Collections.<Torrent>emptyList()), equalTo(-1L)); }