void complete(BitmapHunter hunter) { Action single = hunter.getAction(); List<Action> joined = hunter.getActions(); boolean hasMultiple = joined != null && !joined.isEmpty(); boolean shouldDeliver = single != null || hasMultiple; if (!shouldDeliver) { return; } Uri uri = checkNotNull(hunter.getData().uri, "uri == null"); Exception exception = hunter.getException(); RequestHandler.Result result = hunter.getResult(); if (single != null) { deliverAction(result, single, exception); } if (joined != null) { //noinspection ForLoopReplaceableByForEach for (int i = 0, n = joined.size(); i < n; i++) { Action join = joined.get(i); deliverAction(result, join, exception); } } if (listener != null && exception != null) { listener.onImageLoadFailed(this, uri, exception); } }
@Test public void completeInvokesErrorOnAllFailedRequests() { Action action1 = mockAction(URI_KEY_1, URI_1, mockImageViewTarget()); Action action2 = mockCanceledAction(); Exception exception = mock(Exception.class); BitmapHunter hunter = mockHunter(URI_KEY_1, null); when(hunter.getException()).thenReturn(exception); when(hunter.getActions()).thenReturn(Arrays.asList(action1, action2)); picasso.complete(hunter); verify(action1).error(exception); verify(action2, never()).error(exception); verify(listener).onImageLoadFailed(picasso, URI_1, exception); }
log(OWNER_DISPATCHER, VERB_RETRYING, getLogIdsForHunter(hunter)); if (hunter.getException() instanceof NetworkRequestHandler.ContentLengthException) { hunter.data = hunter.data.newBuilder().networkPolicy(NetworkPolicy.NO_CACHE).build();
@Test public void outOfMemoryDispatchFailed() { Action action = mockAction(URI_KEY_1, URI_1); BitmapHunter hunter = new OOMBitmapHunter(picasso, dispatcher, cache, stats, action); hunter.run(); Exception exception = hunter.getException(); verify(dispatcher).dispatchFailed(hunter); assertThat(hunter.getResult()).isNull(); assertThat(exception).hasMessageThat().contains("BEGIN PICASSO STATS"); assertThat(exception.getCause()).isInstanceOf(OutOfMemoryError.class); }