@Test public void signalsCompletionToPostProcessor() throws Exception { DownloadManager.CompletionInfo info = DownloadManager.CompletionInfo.success(TITLE, LOCAL_PATH); when(downloadManager.query(1)).thenReturn(info); downloader.finishDownload(1); verify(processor).downloadComplete(TITLE, LOCAL_PATH); }
@Test public void signalsErrorToPostProcessor() throws Exception { final int errorCode = 1006; DownloadManager.CompletionInfo info = DownloadManager.CompletionInfo.failure(TITLE, errorCode); when(downloadManager.query(1)).thenReturn(info); downloader.finishDownload(1); verify(processor).downloadError(TITLE, errorCode); }
@Test public void skipsCancelledTasks() throws Exception { when(downloadManager.query(1)).thenReturn(null); downloader.finishDownload(1); verifyZeroInteractions(processor); }
@Test public void ensuresDownloadFolderExists() throws Exception { downloader.startDownloading(request); verify(downloadFolder).mkdirs(); }
@Test public void constructsLocalPathForTaskFromSourceUrl() throws Exception { when(downloadFolder.makePathForUrl(SOURCE_URL)).thenReturn(LOCAL_PATH); downloader.startDownloading(request); assertEquals(request.localPath, LOCAL_PATH); }
@Test public void submitsTaskToDownloader() throws Exception { downloader.startDownloading(request); verify(downloadManager).submit(request); }