FeedDownloadTask implements Runnable { @Override public void run() { CombinedFeed fetchedCombinedFeed = datastore.get(combinedFeedID, CombinedFeed.class); if (fetchedCombinedFeed == null) { LOG.warn("There is no CombinedFeed for the ID: " + combinedFeedID); return; } List<FeedEntry> entries = fetchedCombinedFeed.getUrls().stream() .map(feedDownloader) .flatMap(Collection::stream) .map(entryMapper) .filter(Objects::nonNull) .sorted((e1, e2) -> e2.getPublishDate().compareTo(e1.getPublishDate())) .collect(Collectors.toList()); CombinedFeed combinedFeed = of(fetchedCombinedFeed).feedEntries(entries).build(); datastore.put(combinedFeedID, combinedFeed); LOG.debug("New entries for the CombinedFeed were downloaded [combined-feed={}, entries-count={}]", combinedFeed.getId(), entries.size()); } FeedDownloadTask(Function<URL, List<SyndEntry>> feedDownloader, InMemoryDataStore datastore, String feedId); @Override void run();  }
@Test public void testCombinedFeedNotFound() { expect(datastore.get(feedId, CombinedFeed.class)).andReturn(null); replayAll(); testedClass.run(); verifyAll(); }
@Test public void testSuccess() throws Exception { URL url = new URL("http: String id = "1"; CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(id, singletonList(url)) .refreshPeriod(5L).build(); expect(datastore.get(feedId, CombinedFeed.class)).andReturn(feed); expect(downloader.apply(url)).andReturn(syndEntries()); Capture<CombinedFeed> feedCapture = EasyMock.newCapture(); expect(datastore.put(eq(id), capture(feedCapture))).andReturn(null); replayAll(); testedClass.run(); verifyAll(); CombinedFeed capturedFeed = feedCapture.getValue(); assertEquals(2, capturedFeed.getFeedEntries().size()); for (FeedEntry entry : capturedFeed.getFeedEntries()) { if (TITLES[0].equals(entry.getTitle())) { assertEquals(feedEntries().get(0), entry); } else { assertEquals(feedEntries().get(1), entry); } } }