@Test public void intoImageViewWithFitAndNoDimensionsQueuesDeferredImageViewRequest() { ImageView target = mockFitImageViewTarget(true); when(target.getWidth()).thenReturn(0); when(target.getHeight()).thenReturn(0); new RequestCreator(picasso, URI_1, 0).fit().into(target); verify(picasso, never()).enqueueAndSubmit(any(Action.class)); verify(picasso).defer(eq(target), any(DeferredRequestCreator.class)); }
@Test public void intoImageViewWithFitAndDimensionsQueuesImageViewRequest() { ImageView target = mockFitImageViewTarget(true); when(target.getWidth()).thenReturn(100); when(target.getHeight()).thenReturn(100); new RequestCreator(picasso, URI_1, 0).fit().into(target); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue()).isInstanceOf(ImageViewAction.class); }
@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)); }
@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 targetActionWithDefaultPriority() { new RequestCreator(picasso, URI_1, 0).into(mockTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().request.priority).isEqualTo(NORMAL); }
@Test public void intoRemoteViewsWidgetQueuesAppWidgetAction() { new RequestCreator(picasso, URI_1, 0).into(mockRemoteViews(), 0, new int[] { 1, 2, 3 }); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue()).isInstanceOf(AppWidgetAction.class); }
@Test public void targetActionWithDefaultTag() { new RequestCreator(picasso, URI_1, 0).into(mockTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().getTag()).isEqualTo(actionCaptor.getValue()); }
@Test public void imageViewActionWithDefaultTag() { new RequestCreator(picasso, URI_1, 0).into(mockImageViewTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().getTag()).isEqualTo(actionCaptor.getValue()); }
@Test public void intoRemoteViewsNotificationQueuesNotificationAction() { new RequestCreator(picasso, URI_1, 0).into(mockRemoteViews(), 0, 0, mockNotification()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue()).isInstanceOf(NotificationAction.class); }
@Test public void notificationActionWithDefaultPriority() { new RequestCreator(picasso, URI_1, 0).into(mockRemoteViews(), 0, 0, mockNotification()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().request.priority).isEqualTo(NORMAL); }
@Test public void imageViewActionWithStableKey() { new RequestCreator(picasso, URI_1, 0).stableKey(STABLE_1).into(mockImageViewTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().request.key).isEqualTo(STABLE_URI_KEY_1); }
@Test public void imageViewActionWithCustomPriority() { new RequestCreator(picasso, URI_1, 0).priority(HIGH).into(mockImageViewTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().request.priority).isEqualTo(HIGH); }
@Test public void purgeable() { new RequestCreator(picasso, URI_1, 0).purgeable().into(mockImageViewTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().request.purgeable).isTrue(); } }
@Test public void notificationActionWithDefaultTag() { new RequestCreator(picasso, URI_1, 0).into(mockRemoteViews(), 0, 0, mockNotification()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().getTag()).isEqualTo(actionCaptor.getValue()); }
@Test public void submitWithTargetInvokesDispatcher() { Action action = mockAction(URI_KEY_1, URI_1, mockImageViewTarget()); assertThat(picasso.targetToAction).isEmpty(); picasso.enqueueAndSubmit(action); assertThat(picasso.targetToAction).hasSize(1); verify(dispatcher).dispatchSubmit(action); }
@Test public void targetActionWithCustomTag() { new RequestCreator(picasso, URI_1, 0).tag("tag").into(mockTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().getTag()).isEqualTo("tag"); }
@Test public void imageViewActionWithCustomTag() { new RequestCreator(picasso, URI_1, 0).tag("tag").into(mockImageViewTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().getTag()).isEqualTo("tag"); }
@Test public void cancelTagAllActions() { ImageView target = mockImageViewTarget(); Action action = mockAction(URI_KEY_1, URI_1, target, "TAG"); picasso.enqueueAndSubmit(action); assertThat(picasso.targetToAction).hasSize(1); picasso.cancelTag("TAG"); assertThat(picasso.targetToAction).isEmpty(); verify(action).cancel(); }
@Test public void completeWithReplayDoesNotRemove() { Action action = mockAction(URI_KEY_1, URI_1, mockImageViewTarget()); action.willReplay = true; BitmapHunter hunter = mockHunter(URI_KEY_1, new RequestHandler.Result(bitmap, MEMORY)); when(hunter.getAction()).thenReturn(action); picasso.enqueueAndSubmit(action); assertThat(picasso.targetToAction).hasSize(1); picasso.complete(hunter); assertThat(picasso.targetToAction).hasSize(1); verifyActionComplete(action); }