AppDownloadManager implements AppDownloader { @Override public Completable removeAppDownload() { return Observable.from(app.getDownloadFiles()) .flatMap(downloadAppFile -> getFileDownloader(downloadAppFile.getMainDownloadPath())) .flatMapCompletable(fileDownloader -> fileDownloader.removeDownloadFile() .onErrorComplete()) .toCompletable(); } AppDownloadManager(RetryFileDownloaderProvider fileDownloaderProvider, DownloadApp app,
      HashMap<String, RetryFileDownloader> fileDownloaderPersistence,
      DownloadAnalytics downloadAnalytics); @Override void startAppDownload(); @Override Completable pauseAppDownload(); @Override Completable removeAppDownload(); @Override Observable<AppDownloadStatus> observeDownloadProgress(); void stop(); @VisibleForTesting Observable<RetryFileDownloader> getFileDownloader(String mainDownloadPath);  }
@Test public void removeDownloadWithNoFiles() throws Exception { when(fileDownloaderApk.removeDownloadFile()).thenReturn(Completable.complete()); appDownloadManagerWithNoFiles.removeAppDownload() .subscribe(testSubscriber); testSubscriber.assertCompleted(); testSubscriber.assertNoErrors(); verifyZeroInteractions(fileDownloaderApk); }
@Test public void removeDownloadWithOneFile() throws Exception { when(fileDownloaderApk.removeDownloadFile()).thenReturn(Completable.complete()); appDownloadManager.removeAppDownload() .subscribe(testSubscriber); testSubscriber.assertCompleted(); testSubscriber.assertNoErrors(); verify(fileDownloaderApk).removeDownloadFile(); }
@Test public void removeDownloadWithMultipleFiles() throws Exception { when(fileDownloaderApk.removeDownloadFile()).thenReturn(Completable.complete()); when(fileDownloaderMainObb.removeDownloadFile()).thenReturn(Completable.complete()); when(fileDownloaderPatchObb.removeDownloadFile()).thenReturn(Completable.complete()); appDownloadManagerWithObbs.removeAppDownload() .subscribe(testSubscriber); verify(fileDownloaderApk).removeDownloadFile(); verify(fileDownloaderMainObb).removeDownloadFile(); verify(fileDownloaderPatchObb).removeDownloadFile(); testSubscriber.assertCompleted(); testSubscriber.assertNoErrors(); }