@Test public void testIsFailedAfterNoResultAndNullException() { GenericRequest request = harness.getRequest(); request.onException(null); assertTrue(request.isFailed()); }
@Test public void testIsFailedAfterException() { GenericRequest request = harness.getRequest(); request.onException(new Exception("test")); assertTrue(request.isFailed()); }
@Test public void testIsNotRunningAfterFailing() { GenericRequest request = harness.getRequest(); request.begin(); request.onException(new RuntimeException("Test")); assertFalse(request.isRunning()); }
@Test public void testDoesNotSetErrorDrawableIfRequestCoordinatorDoesntAllowIt() { harness.errorDrawable = new ColorDrawable(Color.RED); GenericRequest request = harness.getRequest(); when(harness.requestCoordinator.canNotifyStatusChanged(any(Request.class))).thenReturn(false); request.onException(new IOException("Test")); verify(harness.target, never()).onLoadFailed(any(Exception.class), any(Drawable.class)); }
@Test public void testCallsTargetOnExceptionIfNoRequestListener() { harness.requestListener = null; GenericRequest request = harness.getRequest(); Exception exception = new IOException("test"); request.onException(exception); verify(harness.target).onLoadFailed(eq(exception), eq(harness.errorDrawable)); }
@Test public void testDoesNotCallTargetOnExceptionIfRequestListenerReturnsTrue() { GenericRequest request = harness.getRequest(); when(harness.requestListener.onException( any(Exception.class), any(Number.class), eq(harness.target), anyBoolean())) .thenReturn(true); request.onException(new IllegalArgumentException("test")); verify(harness.target, never()).onLoadFailed(any(Exception.class), any(Drawable.class)); }
@Test public void testCallsTargetOnExceptionIfRequestListenerReturnsFalse() { GenericRequest request = harness.getRequest(); when(harness.requestListener.onException( any(Exception.class), any(Number.class), eq(harness.target), anyBoolean())) .thenReturn(false); Exception exception = new IOException("Test"); request.onException(exception); verify(harness.target).onLoadFailed(eq(exception), eq(harness.errorDrawable)); }
@Test public void testErrorDrawableIsSetOnLoadFailed() { Drawable expected = new ColorDrawable(Color.RED); MockTarget target = new MockTarget(); harness.errorDrawable = expected; harness.target = target; GenericRequest request = harness.getRequest(); request.onException(null); assertEquals(expected, target.currentPlaceholder); }
@Test public void testErrorResourceIsSetOnLoadFailed() { final int expectedId = 12345; Drawable expected = new ColorDrawable(Color.RED); Context context = mockContextToReturn(expectedId, expected); MockTarget target = new MockTarget(); harness.context = context; harness.errorResourceId = expectedId; harness.target = target; GenericRequest request = harness.getRequest(); request.onException(null); assertEquals(expected, target.currentPlaceholder); }