Esempio n. 1
0
  @Test
  public void testIsFailedAfterNoResultAndNullException() {
    GenericRequest request = harness.getRequest();

    request.onException(null);
    assertTrue(request.isFailed());
  }
Esempio n. 2
0
  @Test
  public void testIsFailedAfterException() {
    GenericRequest request = harness.getRequest();

    request.onException(new Exception("test"));
    assertTrue(request.isFailed());
  }
Esempio n. 3
0
  @Test
  public void testIsNotRunningAfterFailing() {
    GenericRequest request = harness.getRequest();
    request.begin();
    request.onException(new RuntimeException("Test"));

    assertFalse(request.isRunning());
  }
Esempio n. 4
0
  @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));
  }
Esempio n. 5
0
  @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));
  }
Esempio n. 6
0
  @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));
  }
Esempio n. 7
0
  @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));
  }
Esempio n. 8
0
  @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);
  }
Esempio n. 9
0
  @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);
  }