### Question:
HttpDownloadWorker implements Callable { @Override public Void call() throws InterruptedException, CancelledExecutionException { Page page = queue.poll(); int updateInterval = queue.getTotalPages() / 100; if (updateInterval < 1) updateInterval = 1; while (page != null && !Thread.currentThread().isInterrupted()) { appContext.getTap().await(); if (page.canDownload(appContext.getMaxRetryCount())) { boolean status = downloader.download(rootUrl, page.getAndIncrement(), outputDir, appContext, false, simpleLogger, 1 << 22, true); if (!status) { queue.offer(page); } downloads.incrementAndGet(); appContext.incrementPages(); } else { failedDownloads.add(page); } if (queue.getCounter() % updateInterval == 0) { updateProgress(); } page = queue.poll(); } updateProgress(); return null; } HttpDownloadWorker(PageSpread queue, String serverHost, String rootUrl, String outputDir, Downloader downloader, List<Page> failedDownloads, DownloadObserver observer, DLIDownloader dliDownloader, AppContext appContext, LogWindow simpleLogger); @Override Void call(); void updateProgress(); int getTotalDownloads(); String getRootUrl(); @Override String toString();  }### Answer:
@Test public void testFor25Pages() throws Exception { when(pageSpread.getTotalPages()).thenReturn(25); HttpDownloadWorker test = new HttpDownloadWorker(pageSpread, "", "some directory", "test", downloader, new ArrayList<PageSpread.Page>(), downloadObserver, dliDownloader, appContext, logWindow); test.call(); verify(downloadObserver).update(dliDownloader); }
@Test public void testFor500Pages() throws InterruptedException, CancelledExecutionException { when(pageSpread.getTotalPages()).thenReturn(500); HttpDownloadWorker test = new HttpDownloadWorker(pageSpread, "", "some directory", "test", downloader, new ArrayList<PageSpread.Page>(), downloadObserver, dliDownloader, appContext, logWindow); test.call(); verify(downloadObserver).update(dliDownloader); }
@Test public void testComplete() throws InterruptedException, CancelledExecutionException { pageSpread = new PageSpread(1,25); HttpDownloadWorker test = new HttpDownloadWorker(pageSpread, "", "some directory", "test", downloader, new ArrayList<PageSpread.Page>(), downloadObserver, dliDownloader, appContext, logWindow); test.call(); verify(downloadObserver, times(26)).update(dliDownloader); }