ImageDiskTaskManager extends TaskManager<Bitmap> { @Override void execute() { if (mUrls.isEmpty()) { mImageTaskManagerListener.onSuccess(mResults); } ImageDiskTaskListener imageDiskTaskListener = new ImageDiskTaskListener(mMaxImageWidth); for (final String url : mUrls) { CacheService.getFromDiskCacheAsync(url, imageDiskTaskListener); } } ImageDiskTaskManager(@NonNull final List<String> urls,
            @NonNull final TaskManagerListener<Bitmap> imageTaskManagerListener,
            final int maxImageWidth);   }
@Test public void execute_withEmptyDiskCache_shouldReturnNullsInMap() throws Exception { new ImageDiskTaskManager(list, imageTaskManagerListener, TEST_WIDTH).execute(); semaphore.acquire(); assertThat(bitmaps.size()).isEqualTo(2); assertThat(bitmaps.containsKey(url1)).isTrue(); assertThat(bitmaps.containsKey(url2)).isTrue(); assertThat(bitmaps.get(url1)).isNull(); assertThat(bitmaps.get(url2)).isNull(); }
@Test public void execute_withPopulatedDiskCache_shouldReturnImagesInMap() throws Exception { CacheService.initialize(context); CacheServiceTest.assertCachesAreEmpty(); CacheService.putToDiskCache(url1, imageData1.getBytes()); CacheService.putToDiskCache(url2, imageData2.getBytes()); new ImageDiskTaskManager(list, imageTaskManagerListener, TEST_WIDTH).execute(); semaphore.acquire(); assertThat(bitmaps.size()).isEqualTo(2); assertThat(bitmaps.get(url1)).isNotNull(); assertThat(bitmaps.get(url2)).isNotNull(); }
@Test public void execute_withPartiallyPopulatedDiskCache_shouldReturnSomeImagesInMap() throws Exception { CacheService.initialize(context); CacheServiceTest.assertCachesAreEmpty(); CacheService.putToDiskCache(url1, imageData1.getBytes()); new ImageDiskTaskManager(list, imageTaskManagerListener, TEST_WIDTH).execute(); semaphore.acquire(); assertThat(bitmaps.size()).isEqualTo(2); assertThat(bitmaps.get(url1)).isNotNull(); assertThat(bitmaps.containsKey(url2)).isTrue(); assertThat(bitmaps.get(url2)).isNull(); }