AppDownloadManager implements AppDownloader { @Override public Completable pauseAppDownload() { return Observable.from(app.getDownloadFiles()) .flatMap(downloadAppFile -> getFileDownloader(downloadAppFile.getMainDownloadPath())) .filter(retryFileDownloader -> retryFileDownloader != null) .flatMapCompletable(fileDownloader -> fileDownloader.pauseDownload() .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 pauseAppDownloadWithOneFile() throws Exception { PublishSubject<FileDownloadCallback> fileDownloadCallbackPublishSubjectEmpty = PublishSubject.create(); when(fileDownloaderProvider.createRetryFileDownloader(apk.getDownloadMd5(), apk.getMainDownloadPath(), apk.getFileType(), apk.getPackageName(), apk.getVersionCode(), apk.getFileName(), fileDownloadCallbackPublishSubjectEmpty, apk.getAlternativeDownloadPath(), "jonenzoemid")).thenReturn(fileDownloaderApk); when(fileDownloaderApk.pauseDownload()).thenReturn(Completable.complete()); appDownloadManager.pauseAppDownload() .subscribe(testSubscriber); testSubscriber.assertCompleted(); testSubscriber.assertNoErrors(); verify(fileDownloaderApk).pauseDownload(); }
@Test public void pauseAppDownloadWithMultipleFiles() throws Exception { when(fileDownloaderApk.pauseDownload()).thenReturn(Completable.complete()); when(fileDownloaderMainObb.pauseDownload()).thenReturn(Completable.complete()); when(fileDownloaderPatchObb.pauseDownload()).thenReturn(Completable.complete()); appDownloadManagerWithObbs.pauseAppDownload() .subscribe(testSubscriber); testSubscriber.assertCompleted(); testSubscriber.assertNoErrors(); verify(fileDownloaderApk).pauseDownload(); verify(fileDownloaderMainObb).pauseDownload(); verify(fileDownloaderPatchObb).pauseDownload(); }
@Test public void pauseAppDownloadWithNoFiles() throws Exception { appDownloadManagerWithNoFiles.pauseAppDownload() .subscribe(testSubscriber); testSubscriber.assertCompleted(); testSubscriber.assertNoErrors(); verifyZeroInteractions(fileDownloaderApk); verifyZeroInteractions(fileDownloaderMainObb); verifyZeroInteractions(fileDownloaderPatchObb); }