FileManager { public Observable<Long> deleteCache() { return fileUtils.deleteFolder(cacheFolders) .flatMap(deletedSize -> { if (deletedSize > 0) { return downloadManager.invalidateDatabase() .andThen(Observable.just(deletedSize)); } else { return Observable.just(deletedSize); } }) .doOnNext(aVoid -> { httpClientCache.clean(); }); } FileManager(CacheHelper cacheHelper, FileUtils fileUtils, String[] cacheFolders,
      AptoideDownloadManager downloadManager, L2Cache httpClientCache); Single<Long> purgeCache(); Observable<Long> deleteCache();  }
@Test public void deleteCacheSizeGreaterZero() throws IOException { FileUtils fileUtils = mock(FileUtils.class); when(fileUtils.deleteFolder(folders[0])).thenReturn(Observable.just(10L)); FileManager fileManager = new FileManager(cacheHelper, fileUtils, folders, downloadManager, mock(L2Cache.class)); TestSubscriber<Long> subscriber = TestSubscriber.create(); fileManager.deleteCache() .subscribe(subscriber); assertSubscriber(subscriber, 10L); verify(downloadManager, times(1)).invalidateDatabase(); }
@Test public void deleteCacheSizeEqualsZero() throws IOException { FileUtils fileUtils = mock(FileUtils.class); when(fileUtils.deleteFolder(folders[0])).thenReturn(Observable.just(0L)); FileManager fileManager = new FileManager(cacheHelper, fileUtils, folders, downloadManager, mock(L2Cache.class)); TestSubscriber<Long> subscriber = TestSubscriber.create(); fileManager.deleteCache() .subscribe(subscriber); assertSubscriber(subscriber, 0L); verify(downloadManager, times(0)).invalidateDatabase(); }