@Test public void quickMemoryCheckReturnsNullIfNotInCache() { Bitmap cached = picasso.quickMemoryCacheCheck(URI_KEY_1); assertThat(cached).isNull(); verify(stats).dispatchCacheMiss(); }
@Test public void intoImageViewWithNullUriAndResourceIdSkipsAndCancels() { ImageView target = mockImageViewTarget(); new RequestCreator(picasso, null, 0).into(target); verify(picasso).cancelRequest(target); verify(picasso, never()).quickMemoryCacheCheck(anyString()); verify(picasso, never()).enqueueAndSubmit(any(Action.class)); }
@Test public void fetchWithCache() { when(picasso.quickMemoryCacheCheck(URI_KEY_1)).thenReturn(bitmap); new RequestCreator(picasso, URI_1, 0).memoryPolicy(MemoryPolicy.NO_CACHE).fetch(); verify(picasso, never()).enqueueAndSubmit(any(Action.class)); }
private void performRemoteViewInto(Request request, RemoteViewsAction action) { if (shouldReadFromMemoryCache(request.memoryPolicy)) { Bitmap bitmap = picasso.quickMemoryCacheCheck(action.request.key); if (bitmap != null) { action.complete(new RequestHandler.Result(bitmap, MEMORY)); return; } } if (placeholderResId != 0) { action.setImageResource(placeholderResId); } picasso.enqueueAndSubmit(action); } }
@Test public void fetchWithMemoryPolicyNoCache() { new RequestCreator(picasso, URI_1, 0).memoryPolicy(MemoryPolicy.NO_CACHE).fetch(); verify(picasso, never()).quickMemoryCacheCheck(URI_KEY_1); verify(picasso).submit(actionCaptor.capture()); }
@Test public void intoTargetWithQuickMemoryCacheCheckDoesNotSubmit() { when(picasso.quickMemoryCacheCheck(URI_KEY_1)).thenReturn(bitmap); BitmapTarget target = mockTarget(); new RequestCreator(picasso, URI_1, 0).into(target); verify(target).onBitmapLoaded(bitmap, MEMORY); verify(picasso).cancelRequest(target); verify(picasso, never()).enqueueAndSubmit(any(Action.class)); }
@Test public void quickMemoryCheckReturnsBitmapIfInCache() { cache.set(URI_KEY_1, bitmap); Bitmap cached = picasso.quickMemoryCacheCheck(URI_KEY_1); assertThat(cached).isEqualTo(bitmap); verify(stats).dispatchCacheHit(); }
@Test public void intoImageViewWithQuickMemoryCacheCheckDoesNotSubmit() { PlatformLruCache cache = new PlatformLruCache(0); Picasso picasso = spy(new Picasso(RuntimeEnvironment.application, mock(Dispatcher.class), UNUSED_CALL_FACTORY, null, cache, null, NO_TRANSFORMERS, NO_HANDLERS, mock(Stats.class), ARGB_8888, false, false)); doReturn(bitmap).when(picasso).quickMemoryCacheCheck(URI_KEY_1); ImageView target = mockImageViewTarget(); Callback callback = mockCallback(); new RequestCreator(picasso, URI_1, 0).into(target, callback); verify(target).setImageDrawable(any(PicassoDrawable.class)); verify(callback).onSuccess(); verify(picasso).cancelRequest(target); verify(picasso, never()).enqueueAndSubmit(any(Action.class)); }
@Test public void intoImageViewWithSkipMemoryCachePolicy() { ImageView target = mockImageViewTarget(); new RequestCreator(picasso, URI_1, 0).memoryPolicy(MemoryPolicy.NO_CACHE).into(target); verify(picasso, never()).quickMemoryCacheCheck(URI_KEY_1); }
@Test public void intoTargetWithSkipMemoryPolicy() { BitmapTarget target = mockTarget(); new RequestCreator(picasso, URI_1, 0).memoryPolicy(MemoryPolicy.NO_CACHE).into(target); verify(picasso, never()).quickMemoryCacheCheck(URI_KEY_1); }
Bitmap bitmap = picasso.quickMemoryCacheCheck(request.key); if (bitmap != null) { if (picasso.loggingEnabled) {
Bitmap bitmap = picasso.quickMemoryCacheCheck(request.key); if (bitmap != null) { picasso.cancelRequest(target);
void resumeAction(Action action) { Bitmap bitmap = null; if (shouldReadFromMemoryCache(action.request.memoryPolicy)) { bitmap = quickMemoryCacheCheck(action.request.key); } if (bitmap != null) { // Resumed action is cached, complete immediately. deliverAction(new RequestHandler.Result(bitmap, MEMORY), action, null); if (loggingEnabled) { log(OWNER_MAIN, VERB_COMPLETED, action.request.logId(), "from " + MEMORY); } } else { // Re-submit the action to the executor. enqueueAndSubmit(action); if (loggingEnabled) { log(OWNER_MAIN, VERB_RESUMED, action.request.logId()); } } }
Bitmap bitmap = picasso.quickMemoryCacheCheck(request.key); if (bitmap != null) { picasso.cancelRequest(target);