Esempio n. 1
0
  @Test
  public void testCanReRunCancelledRequests() {
    doAnswer(new CallSizeReady(100, 100))
        .when(harness.target)
        .getSize(any(SizeReadyCallback.class));
    when(harness.engine.load(
            anyInt(),
            anyInt(),
            any(ResourceDecoder.class),
            any(DataFetcher.class),
            any(Encoder.class),
            any(ResourceDecoder.class),
            any(Transformation.class),
            any(ResourceEncoder.class),
            any(ResourceTranscoder.class),
            any(Priority.class),
            anyBoolean(),
            any(DiskCacheStrategy.class),
            any(ResourceCallback.class)))
        .thenAnswer(new CallResourceCallback(harness.resource));
    GenericRequest request = harness.getRequest();

    request.begin();
    request.cancel();
    request.begin();

    verify(harness.target, times(2)).onResourceReady(eq(harness.result), any(GlideAnimation.class));
  }
Esempio n. 2
0
  @Test
  public void testRequestListenerIsCalledWithLoadedFromMemoryIfLoadCompletesSynchronously() {
    final GenericRequest request = harness.getRequest();
    when(harness.engine.load(
            anyInt(),
            anyInt(),
            any(ResourceDecoder.class),
            any(DataFetcher.class),
            any(Encoder.class),
            any(ResourceDecoder.class),
            any(Transformation.class),
            any(ResourceEncoder.class),
            any(ResourceTranscoder.class),
            any(Priority.class),
            anyBoolean(),
            any(DiskCacheStrategy.class),
            any(ResourceCallback.class)))
        .thenAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                request.onResourceReady(harness.resource);
                return null;
              }
            });

    request.begin();
    request.onSizeReady(100, 100);
    verify(harness.requestListener)
        .onResourceReady(
            eq(harness.result), any(Number.class), any(Target.class), eq(true), anyBoolean());
  }
Esempio n. 3
0
  @Test
  public void testEngineLoadCancelledOnCancel() {
    Engine.LoadStatus loadStatus = mock(Engine.LoadStatus.class);
    when(harness.engine.load(
            anyInt(),
            anyInt(),
            any(ResourceDecoder.class),
            any(DataFetcher.class),
            any(Encoder.class),
            any(ResourceDecoder.class),
            any(Transformation.class),
            any(ResourceEncoder.class),
            any(ResourceTranscoder.class),
            any(Priority.class),
            anyBoolean(),
            any(DiskCacheStrategy.class),
            any(ResourceCallback.class)))
        .thenReturn(loadStatus);

    GenericRequest request = harness.getRequest();
    request.begin();

    request.onSizeReady(100, 100);
    request.cancel();

    verify(loadStatus).cancel();
  }
Esempio n. 4
0
  @Test
  public void testEngineLoadPassedCorrectPriority() {
    Priority expected = Priority.HIGH;
    harness.priority = expected;
    GenericRequest request = harness.getRequest();
    request.begin();

    request.onSizeReady(100, 100);

    verify(harness.engine)
        .load(
            anyInt(),
            anyInt(),
            any(ResourceDecoder.class),
            any(DataFetcher.class),
            any(Encoder.class),
            any(ResourceDecoder.class),
            any(Transformation.class),
            any(ResourceEncoder.class),
            any(ResourceTranscoder.class),
            eq(expected),
            anyBoolean(),
            any(DiskCacheStrategy.class),
            any(ResourceCallback.class));
  }
Esempio n. 5
0
  @Test
  public void testIsNotRunningAfterFailing() {
    GenericRequest request = harness.getRequest();
    request.begin();
    request.onException(new RuntimeException("Test"));

    assertFalse(request.isRunning());
  }
Esempio n. 6
0
  @Test
  public void testIsNotRunningAfterClear() {
    GenericRequest request = harness.getRequest();
    request.begin();
    request.clear();

    assertFalse(request.isRunning());
  }
Esempio n. 7
0
  @Test
  public void testIsNotRunningAfterComplete() {
    GenericRequest request = harness.getRequest();
    request.begin();
    request.onResourceReady(harness.resource);

    assertFalse(request.isRunning());
  }
Esempio n. 8
0
  @Test
  public void testIsNotFailedAfterBegin() {
    GenericRequest request = harness.getRequest();

    request.onResourceReady(null);
    request.begin();

    assertFalse(request.isFailed());
  }
Esempio n. 9
0
  @Test
  public void testIsNotPausedAfterBeginningWhilePaused() {
    GenericRequest request = harness.getRequest();
    request.pause();
    request.begin();

    assertFalse(request.isPaused());
    assertTrue(request.isRunning());
  }
Esempio n. 10
0
  @Test
  public void testDoesNotCallGetSizeIfOverrideWidthAndHeightAreSet() {
    harness.overrideWidth = 100;
    harness.overrideHeight = 100;
    GenericRequest request = harness.getRequest();
    request.begin();

    verify(harness.target, never()).getSize(any(SizeReadyCallback.class));
  }
Esempio n. 11
0
  @Test
  public void testCallsGetSizeIfOverrideHeightIsLessThanZero() {
    harness.overrideHeight = -1;
    harness.overrideWidth = 100;
    GenericRequest request = harness.getRequest();
    request.begin();

    verify(harness.target).getSize(any(SizeReadyCallback.class));
  }
Esempio n. 12
0
  @Test
  public void testOnSizeReadyWithNullDataFetcherCallsOnException() {
    GenericRequest request = harness.getRequest();
    when(harness.modelLoader.getResourceFetcher(any(Number.class), anyInt(), anyInt()))
        .thenReturn(null);
    request.begin();
    request.onSizeReady(100, 100);

    verify(harness.requestListener)
        .onException(any(Exception.class), any(Number.class), any(Target.class), anyBoolean());
  }
Esempio n. 13
0
  @Test
  public void testPlaceholderDrawableIsSet() {
    Drawable expected = new ColorDrawable(Color.RED);

    MockTarget target = new MockTarget();

    harness.placeholderDrawable = expected;
    harness.target = target;
    GenericRequest request = harness.getRequest();
    request.begin();

    assertEquals(expected, target.currentPlaceholder);
  }
Esempio n. 14
0
  @Test
  public void setTestPlaceholderDrawableSetOnNullModel() {
    Drawable placeholder = new ColorDrawable(Color.RED);

    MockTarget target = new MockTarget();

    harness.placeholderDrawable = placeholder;
    harness.target = target;
    harness.model = null;
    GenericRequest request = harness.getRequest();

    request.begin();

    assertEquals(placeholder, target.currentPlaceholder);
  }
Esempio n. 15
0
  @Test
  public void testPlaceholderResourceIsSet() {
    final int expectedId = 12345;
    Drawable expected = new ColorDrawable(Color.RED);

    Context context = mockContextToReturn(expectedId, expected);
    MockTarget target = new MockTarget();

    harness.context = context;
    harness.placeholderResourceId = expectedId;
    harness.target = target;
    GenericRequest request = harness.getRequest();
    request.begin();

    assertEquals(expected, target.currentPlaceholder);
  }
Esempio n. 16
0
  @Test
  public void testIgnoresOnSizeReadyIfNotWaitingForSize() {
    GenericRequest request = harness.getRequest();
    request.begin();
    request.onSizeReady(100, 100);
    request.onSizeReady(100, 100);

    verify(harness.engine, times(1))
        .load(
            eq(100),
            eq(100),
            any(ResourceDecoder.class),
            any(DataFetcher.class),
            any(Encoder.class),
            any(ResourceDecoder.class),
            any(Transformation.class),
            any(ResourceEncoder.class),
            any(ResourceTranscoder.class),
            any(Priority.class),
            anyBoolean(),
            any(DiskCacheStrategy.class),
            any(ResourceCallback.class));
  }
Esempio n. 17
0
  @Test
  public void testCallsEngineWithOverrideWidthAndHeightIfSet() {
    harness.overrideWidth = 1;
    harness.overrideHeight = 2;

    GenericRequest request = harness.getRequest();
    request.begin();

    verify(harness.engine)
        .load(
            eq(harness.overrideWidth),
            eq(harness.overrideHeight),
            any(ResourceDecoder.class),
            any(DataFetcher.class),
            any(Encoder.class),
            any(ResourceDecoder.class),
            any(Transformation.class),
            any(ResourceEncoder.class),
            any(ResourceTranscoder.class),
            any(Priority.class),
            anyBoolean(),
            any(DiskCacheStrategy.class),
            any(ResourceCallback.class));
  }