@Test public void performCompleteCleansUpAndDoesNotPostToMainIfCancelled() { Request data = new Request.Builder(URI_1).build(); Action action = noopAction(data); BitmapHunter hunter = new BitmapHunter(mockPicasso(), dispatcher, cache, stats, action, EMPTY_REQUEST_HANDLER); hunter.result = new RequestHandler.Result(bitmap1, MEMORY); hunter.future = new FutureTask<>(mock(Runnable.class), null); hunter.future.cancel(false); dispatcher.performComplete(hunter); assertThat(dispatcher.hunterMap).isEmpty(); // TODO verify no main thread interactions. }
@Test public void performCompleteCleansUpAndPostsToMain() { Request data = new Request.Builder(URI_1).build(); Action action = noopAction(data); BitmapHunter hunter = new BitmapHunter(mockPicasso(), dispatcher, cache, stats, action, EMPTY_REQUEST_HANDLER); hunter.result = new RequestHandler.Result(bitmap1, MEMORY); dispatcher.performComplete(hunter); assertThat(dispatcher.hunterMap).isEmpty(); // TODO verify post to main thread. }
@Test public void performCompleteWithNoStoreMemoryPolicy() { Request data = new Request.Builder(URI_1).memoryPolicy(MemoryPolicy.NO_STORE).build(); Action action = noopAction(data); BitmapHunter hunter = new BitmapHunter(mockPicasso(), dispatcher, cache, stats, action, EMPTY_REQUEST_HANDLER); hunter.result = new RequestHandler.Result(bitmap1, MEMORY); dispatcher.performComplete(hunter); assertThat(dispatcher.hunterMap).isEmpty(); assertThat(cache.size()).isEqualTo(0); }
@Test public void performCompleteSetsResultInCache() { Request data = new Request.Builder(URI_1).build(); Action action = noopAction(data); BitmapHunter hunter = new BitmapHunter(mockPicasso(), dispatcher, cache, stats, action, EMPTY_REQUEST_HANDLER); hunter.result = new RequestHandler.Result(bitmap1, MEMORY); dispatcher.performComplete(hunter); assertThat(cache.get(hunter.getKey())).isSameAs(hunter.result.getBitmap()); }