@Override void error(Exception e) { if (callback != null) { callback.onError(e); } }
@Override void complete(RequestHandler.Result result) { if (callback != null) { callback.onSuccess(); } }
@Override public void error(Exception e) { if (errorResId != 0) { setImageResource(errorResId); } if (callback != null) { callback.onError(e); } }
@Override public void complete(RequestHandler.Result result) { if (result == null) { throw new AssertionError( String.format("Attempted to complete action with no result!\n%s", this)); } boolean indicatorsEnabled = picasso.indicatorsEnabled; PicassoDrawable.setResult(target, picasso.context, result, noFade, indicatorsEnabled); if (callback != null) { callback.onSuccess(); } }
@Override public void error(Exception e) { Drawable placeholder = target.getDrawable(); if (placeholder instanceof Animatable) { ((Animatable) placeholder).stop(); } if (errorResId != 0) { target.setImageResource(errorResId); } else if (errorDrawable != null) { target.setImageDrawable(errorDrawable); } if (callback != null) { callback.onError(e); } }
@Override void complete(RequestHandler.Result result) { target.remoteViews.setImageViewBitmap(target.viewId, result.getBitmap()); update(); if (callback != null) { callback.onSuccess(); } }
@Test public void invokesErrorIfTargetIsNotNullWithErrorDrawable() { Drawable errorDrawable = mock(Drawable.class); ImageView target = mockImageViewTarget(); Callback callback = mockCallback(); Picasso mock = mock(Picasso.class); ImageViewAction request = new ImageViewAction(mock, target, null, errorDrawable, 0, false, callback); Exception e = new RuntimeException(); request.error(e); verify(target).setImageDrawable(errorDrawable); verify(callback).onError(e); }
@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 invokesTargetAndCallbackErrorIfTargetIsNotNullWithErrorResourceId() { ImageView target = mockImageViewTarget(); Callback callback = mockCallback(); Picasso mock = mock(Picasso.class); ImageViewAction request = new ImageViewAction(mock, target, null, null, RESOURCE_ID_1, false, callback); Exception e = new RuntimeException(); request.error(e); verify(target).setImageResource(RESOURCE_ID_1); verify(callback).onError(e); }
callback.onSuccess();
@Test public void invokesErrorIfTargetIsNotNullWithErrorResourceId() { ImageView target = mockImageViewTarget(); Callback callback = mockCallback(); Picasso mock = mock(Picasso.class); ImageViewAction request = new ImageViewAction(mock, target, null, null, RESOURCE_ID_1, false, callback); Exception e = new RuntimeException(); request.error(e); verify(target).setImageResource(RESOURCE_ID_1); verify(callback).onError(e); }
@Test public void invokesTargetAndCallbackSuccessIfTargetIsNotNull() { Bitmap bitmap = makeBitmap(); Dispatcher dispatcher = mock(Dispatcher.class); PlatformLruCache cache = new PlatformLruCache(0); Picasso picasso = new Picasso(RuntimeEnvironment.application, dispatcher, UNUSED_CALL_FACTORY, null, cache, null, NO_TRANSFORMERS, NO_HANDLERS, mock(Stats.class), Bitmap.Config.ARGB_8888, false, false); ImageView target = mockImageViewTarget(); Callback callback = mockCallback(); ImageViewAction request = new ImageViewAction(picasso, target, null, null, 0, false, callback); request.complete(new RequestHandler.Result(bitmap, MEMORY)); verify(target).setImageDrawable(any(PicassoDrawable.class)); verify(callback).onSuccess(); }
@Test public void errorWithNoResourceIsNoop() { Callback callback = mockCallback(); RemoteViewsAction action = createAction(callback); Exception e = new RuntimeException(); action.error(e); verifyZeroInteractions(remoteViews); verify(callback).onError(e); }
@Test public void completeSetsBitmapOnRemoteViews() { Callback callback = mockCallback(); Bitmap bitmap = makeBitmap(); RemoteViewsAction action = createAction(callback); action.complete(new RequestHandler.Result(bitmap, NETWORK)); verify(remoteViews).setImageViewBitmap(1, bitmap); verify(callback).onSuccess(); }
@Test public void errorWithResourceSetsResource() { Callback callback = mockCallback(); RemoteViewsAction action = createAction(1, callback); Exception e = new RuntimeException(); action.error(e); verify(remoteViews).setImageViewResource(1, 1); verify(callback).onError(e); }
callback.onSuccess();