@Override public void onLoadFailed(Exception e, Drawable errorDrawable) { if (target != null) target.onLoadFailed(e, errorDrawable); }
@Override public void onLoadFailed(Exception e, Drawable errorDrawable) { target.onLoadFailed(e, errorDrawable); }
@Test public void testNullModelResolvesToUsePlaceholder() { Drawable placeholder = new ColorDrawable(Color.GREEN); requestManager .load(NULL) .apply(placeholderOf(placeholder)) .into(target); verify(target).onLoadFailed(eq(placeholder)); }
@Test public void testNullModelDoesNotThrow() { Drawable drawable = new ColorDrawable(Color.RED); requestManager .load(NULL) .apply(errorOf(drawable)) .into(target); verify(target).onLoadFailed(eq(drawable)); }
@Test public void testNullModelPrefersErrorDrawable() { Drawable placeholder = new ColorDrawable(Color.GREEN); Drawable error = new ColorDrawable(Color.RED); requestManager .load(NULL) .apply(placeholderOf(placeholder) .error(error)) .into(target); verify(target).onLoadFailed(eq(error)); }
@Test public void testNullModelPrefersFallbackDrawable() { Drawable placeholder = new ColorDrawable(Color.GREEN); Drawable error = new ColorDrawable(Color.RED); Drawable fallback = new ColorDrawable(Color.BLUE); requestManager .load(NULL) .apply(placeholderOf(placeholder) .error(error) .fallback(fallback)) .into(target); verify(target).onLoadFailed(eq(fallback)); }
private synchronized void setErrorPlaceholder() { if (!canNotifyStatusChanged()) { return; } Drawable error = null; if (model == null) { error = getFallbackDrawable(); } // Either the model isn't null, or there was no fallback drawable set. if (error == null) { error = getErrorDrawable(); } // The model isn't null, no fallback drawable was set or no error drawable was set. if (error == null) { error = getPlaceholderDrawable(); } target.onLoadFailed(error); }
@Test public void testDoesNotSetErrorDrawableIfRequestCoordinatorDoesntAllowIt() { SingleRequest<List> request = builder .setErrorDrawable(new ColorDrawable(Color.RED)) .build(); when(builder.requestCoordinator.canNotifyStatusChanged(any(Request.class))).thenReturn(false); request.onLoadFailed(new GlideException("test")); verify(builder.target, never()).onLoadFailed(any(Drawable.class)); }
@Test public void testCallsTargetOnExceptionIfNoRequestListener() { SingleRequest<List> request = builder.build(); request.onLoadFailed(new GlideException("test")); verify(builder.target).onLoadFailed(eq(builder.errorDrawable)); }
@Test public void testDoesNotCallTargetOnExceptionIfAnyRequestListenerReturnsTrue() { SingleRequest<List> request = builder.addRequestListener(listener1).addRequestListener(listener2).build(); when(listener1.onLoadFailed(isAGlideException(), any(Number.class), eq(builder.target), anyBoolean())) .thenReturn(false); when(listener2.onLoadFailed(isAGlideException(), any(Number.class), eq(builder.target), anyBoolean())) .thenReturn(true); request.onLoadFailed(new GlideException("test")); verify(builder.target, never()).onLoadFailed(any(Drawable.class)); }
@Test public void testCallsTargetOnExceptionIfAllRequestListenersReturnFalse() { SingleRequest<List> request = builder.addRequestListener(listener1).addRequestListener(listener2).build(); when(listener1.onLoadFailed(isAGlideException(), any(Number.class), eq(builder.target), anyBoolean())) .thenReturn(false); when(listener2.onLoadFailed(isAGlideException(), any(Number.class), eq(builder.target), anyBoolean())) .thenReturn(false); request.onLoadFailed(new GlideException("test")); verify(builder.target).onLoadFailed(eq(builder.errorDrawable)); }
@Override public void onLoadFailed(Exception e, Drawable errorDrawable) { target.onLoadFailed(e, errorDrawable); }
private void setErrorPlaceholder(Exception e) { if (!canNotifyStatusChanged()) { return; } Drawable error = model == null ? getFallbackDrawable() : null; if (error == null) { error = getErrorDrawable(); } if (error == null) { error = getPlaceholderDrawable(); } target.onLoadFailed(e, error); }
@Override public void onLoadFailed(@Nullable Drawable errorDrawable) { target.onLoadFailed(errorDrawable); }
private void setErrorPlaceholder() { if (!canNotifyStatusChanged()) { return; } Drawable error = null; if (model == null) { error = getFallbackDrawable(); } // Either the model isn't null, or there was no fallback drawable set. if (error == null) { error = getErrorDrawable(); } // The model isn't null, no fallback drawable was set or no error drawable was set. if (error == null) { error = getPlaceholderDrawable(); } target.onLoadFailed(error); }