FinishedTorrentsDetector { public Collection<Torrent> filterFinishedTorrentsToNotify(Collection<Torrent> torrents, Server server) { long lastUpdateDate = server.getLastUpdateDate(); if (lastUpdateDate <= 0) return Collections.emptySet(); return filterFinishedAfterDate(torrents, lastUpdateDate); }  Collection<Torrent> filterFinishedTorrentsToNotify(Collection<Torrent> torrents, Server server); long findLastFinishedDate(Collection<Torrent> torrents);  }
@Test public void testFilterFinishedTorrentsToNotifyFirstUpdate() { Server server = new Server("test", "localhost", 9091); 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() ); Collection<Torrent> filteredTorrents = detector.filterFinishedTorrentsToNotify(torrents, server); assertThat(filteredTorrents, emptyCollectionOf(Torrent.class)); }
@Test public void testFilterFinishedTorrentsToNotify() { Server server = new Server("test", "localhost", 9091); server.setLastUpdateDate(100L); 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() ); Collection<Torrent> filteredTorrents = detector.filterFinishedTorrentsToNotify(torrents, server); assertThat(filteredTorrents, hasSize(2)); assertThat(filteredTorrents, hasItem(withDoneDate(555L))); assertThat(filteredTorrents, hasItem(withDoneDate(873L))); }