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

    assertNotNull(loadStatus);
  }
Esempio n. 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));
  }
Esempio n. 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));
  }
Esempio n. 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));
  }
Esempio n. 5
0
  @Test
  public void testNewRunnerIsNotCreatedAndPostedWithExistingLoad() {
    harness.doLoad();
    harness.doLoad();

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

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

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

    Engine.LoadStatus loadStatus = harness.doLoad();
    assertNull(loadStatus);
  }
Esempio n. 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));
  }
Esempio n. 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));
  }
Esempio n. 11
0
  @Test
  public void testKeyIsRemovedFromActiveResourcesIfRefIsCleared() {
    harness.activeResources.put(harness.cacheKey, new WeakReference<EngineResource<?>>(null));

    harness.doLoad();

    assertThat(harness.activeResources).doesNotContainKey(harness.cacheKey);
  }
Esempio n. 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));
  }
Esempio n. 13
0
  @Test
  public void testResourceIsAcquiredIfReturnedFromCache() {
    when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(harness.resource);

    harness.doLoad();

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

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

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

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

    assertThat(harness.jobs).doesNotContainKey(harness.cacheKey);
  }
Esempio n. 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));
  }
Esempio n. 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));
  }
Esempio n. 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());
  }
Esempio n. 19
0
  @Test
  public void testJobIsNotRemovedFromJobsIfOldJobIsCancelled() {
    harness.doLoad();

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

    assertEquals(harness.job, harness.jobs.get(harness.cacheKey));
  }
Esempio n. 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));
  }
Esempio n. 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));
  }
Esempio n. 22
0
  @Test
  public void testResourceIsAcquiredIfReturnedFromActiveResources() {
    harness.activeResources.put(
        harness.cacheKey, new WeakReference<EngineResource<?>>(harness.resource));

    harness.doLoad();

    verify(harness.resource).acquire();
  }
Esempio n. 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));
  }
Esempio n. 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));
  }
Esempio n. 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));
  }
Esempio n. 26
0
  @Test
  public void testNewRunnerIsAddedToRunnersMap() {
    harness.doLoad();

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

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

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

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