Exemple #1
0
  @Test
  public void testLoadStatusIsReturnedForExistingJob() {
    harness.doLoad();
    Engine.LoadStatus loadStatus = harness.doLoad();

    assertNotNull(loadStatus);
  }
Exemple #2
0
  @Test
  public void testCacheIsNotCheckedIfNotMemoryCacheable() {
    when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(harness.resource);

    harness.isMemoryCacheable = false;
    harness.doLoad();

    verify(harness.job).start(any(EngineRunnable.class));
  }
Exemple #3
0
  @Test
  public void testActiveResourcesIsNotCheckedIfNotMemoryCacheable() {
    harness.activeResources.put(
        harness.cacheKey, new WeakReference<EngineResource<?>>(harness.resource));

    harness.isMemoryCacheable = false;
    harness.doLoad();

    verify(harness.resource, never()).acquire();
    verify(harness.job).start(any(EngineRunnable.class));
  }
Exemple #4
0
  @Test
  @SuppressWarnings("unchecked")
  public void testCallbackIsAddedToExistingRunnerWithExistingLoad() {
    harness.doLoad();

    ResourceCallback newCallback = mock(ResourceCallback.class);
    harness.cb = newCallback;
    harness.doLoad();

    verify(harness.job).addCallback(eq(newCallback));
  }
Exemple #5
0
  @Test
  public void testNewRunnerIsNotCreatedAndPostedWithExistingLoad() {
    harness.doLoad();
    harness.doLoad();

    verify(harness.job, times(1)).start(any(EngineRunnable.class));
  }
Exemple #6
0
  @Test
  public void testEngineJobReceivesRemoveCallbackFromLoadStatus() {
    Engine.LoadStatus loadStatus = harness.doLoad();
    loadStatus.cancel();

    verify(harness.job).removeCallback(eq(harness.cb));
  }
Exemple #7
0
  @Test
  public void testNullLoadStatusIsReturnedIfResourceIsActive() {
    harness.activeResources.put(
        harness.cacheKey, new WeakReference<EngineResource<?>>(harness.resource));

    assertNull(harness.doLoad());
  }
Exemple #8
0
  @Test
  public void testNullLoadStatusIsReturnedForCachedResource() {
    when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(mock(EngineResource.class));

    Engine.LoadStatus loadStatus = harness.doLoad();
    assertNull(loadStatus);
  }
Exemple #9
0
  @Test
  public void testResourceIsNotReturnedFromActiveResourcesIfRefIsCleared() {
    harness.activeResources.put(harness.cacheKey, new WeakReference<EngineResource<?>>(null));

    harness.doLoad();

    verify(harness.cb, never()).onResourceReady(isNull(Resource.class));
  }
Exemple #10
0
  @Test
  public void testCacheIsCheckedIfMemoryCacheable() {
    when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(harness.resource);

    harness.doLoad();

    verify(harness.cb).onResourceReady(eq(harness.resource));
  }
Exemple #11
0
  @Test
  public void testKeyIsRemovedFromActiveResourcesIfRefIsCleared() {
    harness.activeResources.put(harness.cacheKey, new WeakReference<EngineResource<?>>(null));

    harness.doLoad();

    assertThat(harness.activeResources).doesNotContainKey(harness.cacheKey);
  }
Exemple #12
0
  @Test
  public void testResourceIsReturnedFromCacheIfPresent() {
    when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(harness.resource);

    harness.doLoad();

    verify(harness.cb).onResourceReady(eq(harness.resource));
  }
Exemple #13
0
  @Test
  public void testResourceIsAcquiredIfReturnedFromCache() {
    when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(harness.resource);

    harness.doLoad();

    verify(harness.resource).acquire();
  }
Exemple #14
0
  @Test
  public void testRunnerIsRemovedFromRunnersOnEngineNotifiedJobCancel() {
    harness.doLoad();

    harness.engine.onEngineJobCancelled(harness.job, harness.cacheKey);

    assertThat(harness.jobs).doesNotContainKey(harness.cacheKey);
  }
Exemple #15
0
  @Test
  public void testRunnerIsRemovedFromRunnersOnEngineNotifiedJobComplete() {
    harness.doLoad();

    harness.engine.onEngineJobComplete(harness.cacheKey, harness.resource);

    assertThat(harness.jobs).doesNotContainKey(harness.cacheKey);
  }
Exemple #16
0
  @Test
  public void testEngineIsSetAsResourceListenerOnJobComplete() {
    harness.doLoad();

    harness.engine.onEngineJobComplete(harness.cacheKey, harness.resource);

    verify(harness.resource).setResourceListener(eq(harness.cacheKey), eq(harness.engine));
  }
Exemple #17
0
  @Test
  public void testNewLoadIsNotStartedIfResourceIsCached() {
    when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(mock(EngineResource.class));

    harness.doLoad();

    verify(harness.job, never()).start(any(EngineRunnable.class));
  }
Exemple #18
0
  @Test
  public void testResourceIsAddedToActiveResourceIfReturnedFromCache() {
    when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(harness.resource);

    harness.doLoad();

    assertEquals(harness.resource, harness.activeResources.get(harness.cacheKey).get());
  }
Exemple #19
0
  @Test
  public void testJobIsNotRemovedFromJobsIfOldJobIsCancelled() {
    harness.doLoad();

    harness.engine.onEngineJobCancelled(mock(EngineJob.class), harness.cacheKey);

    assertEquals(harness.job, harness.jobs.get(harness.cacheKey));
  }
Exemple #20
0
  @Test
  public void testNewLoadIsNotStartedIfResourceIsActive() {
    harness.activeResources.put(
        harness.cacheKey, new WeakReference<EngineResource<?>>(harness.resource));

    harness.doLoad();

    verify(harness.job, never()).start(any(EngineRunnable.class));
  }
Exemple #21
0
  @Test
  public void testResourceIsReturnedFromActiveResourcesIfPresent() {
    harness.activeResources.put(
        harness.cacheKey, new WeakReference<EngineResource<?>>(harness.resource));

    harness.doLoad();

    verify(harness.cb).onResourceReady(eq(harness.resource));
  }
Exemple #22
0
  @Test
  public void testResourceIsAcquiredIfReturnedFromActiveResources() {
    harness.activeResources.put(
        harness.cacheKey, new WeakReference<EngineResource<?>>(harness.resource));

    harness.doLoad();

    verify(harness.resource).acquire();
  }
Exemple #23
0
  @Test
  public void testActiveResourcesIsNotCheckedIfReturnedFromCache() {
    when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(harness.resource);
    EngineResource other = mock(EngineResource.class);
    harness.activeResources.put(harness.cacheKey, new WeakReference<EngineResource<?>>(other));

    harness.doLoad();

    verify(harness.cb).onResourceReady(eq(harness.resource));
    verify(harness.cb, never()).onResourceReady(eq(other));
  }
Exemple #24
0
  @Test
  public void testKeyFactoryIsGivenNecessaryArguments() {
    harness.doLoad();

    verify(harness.keyFactory)
        .buildKey(
            eq(ID),
            eq(harness.signature),
            eq(harness.width),
            eq(harness.height),
            eq(harness.cacheDecoder),
            eq(harness.decoder),
            eq(harness.transformation),
            eq(harness.encoder),
            eq(harness.transcoder),
            eq(harness.sourceEncoder));
  }
Exemple #25
0
  @Test
  public void testHandlesNonEngineResourcesFromCacheIfPresent() {
    final Object expected = new Object();
    Resource fromCache = mock(Resource.class);
    when(fromCache.get()).thenReturn(expected);
    when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(fromCache);

    doAnswer(
            new Answer() {
              @Override
              public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                Resource resource = (Resource) invocationOnMock.getArguments()[0];
                assertEquals(expected, resource.get());
                return null;
              }
            })
        .when(harness.cb)
        .onResourceReady(any(Resource.class));

    harness.doLoad();

    verify(harness.cb).onResourceReady(any(Resource.class));
  }
Exemple #26
0
  @Test
  public void testNewRunnerIsAddedToRunnersMap() {
    harness.doLoad();

    assertThat(harness.jobs).containsKey(harness.cacheKey);
  }
Exemple #27
0
 @Test
 public void testLoadStatusIsReturnedForNewLoad() {
   assertNotNull(harness.doLoad());
 }
Exemple #28
0
  @Test
  public void testCallbackIsAddedToNewEngineJobWithNoExistingLoad() {
    harness.doLoad();

    verify(harness.job).addCallback(eq(harness.cb));
  }
Exemple #29
0
  @Test
  public void testFactoryIsGivenNecessaryArguments() {
    harness.doLoad();

    verify(harness.engineJobFactory).build(eq(harness.cacheKey), eq(harness.isMemoryCacheable));
  }
Exemple #30
0
  @Test
  public void testJobIsPutInJobWithCacheKeyWithRelevantIds() {
    harness.doLoad();

    assertThat(harness.jobs).containsEntry(harness.cacheKey, harness.job);
  }