Search in sources :

Example 6 with ResourceCallback

use of com.bumptech.glide.request.ResourceCallback in project glide by bumptech.

the class EngineJobTest method testRemovingCallbackDuringOnResourceReadyPreventsCallbackFromBeingCalledIfNotYetCalled.

@Test
public void testRemovingCallbackDuringOnResourceReadyPreventsCallbackFromBeingCalledIfNotYetCalled() {
    final EngineJob<Object> job = harness.getJob();
    final ResourceCallback notYetCalled = mock(ResourceCallback.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            job.removeCallback(notYetCalled);
            return null;
        }
    }).when(harness.cb).onResourceReady(anyResource(), isADataSource());
    job.addCallback(notYetCalled);
    job.start(harness.decodeJob);
    job.onResourceReady(harness.resource, harness.dataSource);
    verify(notYetCalled, never()).onResourceReady(anyResource(), isADataSource());
}
Also used : ResourceCallback(com.bumptech.glide.request.ResourceCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 7 with ResourceCallback

use of com.bumptech.glide.request.ResourceCallback in project glide by bumptech.

the class EngineJob method handleExceptionOnMainThread.

@Synthetic
void handleExceptionOnMainThread() {
    stateVerifier.throwIfRecycled();
    if (isCancelled) {
        release(false);
        return;
    } else if (cbs.isEmpty()) {
        throw new IllegalStateException("Received an exception without any callbacks to notify");
    } else if (hasLoadFailed) {
        throw new IllegalStateException("Already failed once");
    }
    hasLoadFailed = true;
    listener.onEngineJobComplete(key, null);
    for (ResourceCallback cb : cbs) {
        if (!isInIgnoredCallbacks(cb)) {
            cb.onLoadFailed(exception);
        }
    }
    release(false);
}
Also used : ResourceCallback(com.bumptech.glide.request.ResourceCallback) Synthetic(com.bumptech.glide.util.Synthetic)

Example 8 with ResourceCallback

use of com.bumptech.glide.request.ResourceCallback in project glide by bumptech.

the class EngineJobTest method testNotifiesAllCallbacksOnException.

@Test
public void testNotifiesAllCallbacksOnException() {
    MultiCbHarness harness = new MultiCbHarness();
    harness.job.start(harness.decodeJob);
    GlideException exception = new GlideException("test");
    harness.job.onLoadFailed(exception);
    for (ResourceCallback cb : harness.cbs) {
        verify(cb).onLoadFailed(eq(exception));
    }
}
Also used : ResourceCallback(com.bumptech.glide.request.ResourceCallback) Test(org.junit.Test)

Example 9 with ResourceCallback

use of com.bumptech.glide.request.ResourceCallback in project glide by bumptech.

the class EngineJobTest method testNotifiesNewCallbackOfExceptionIfCallbackIsAddedDuringOnException.

@Test
public void testNotifiesNewCallbackOfExceptionIfCallbackIsAddedDuringOnException() {
    harness = new EngineJobHarness();
    final EngineJob<Object> job = harness.getJob();
    final ResourceCallback existingCallback = mock(ResourceCallback.class);
    final ResourceCallback newCallback = mock(ResourceCallback.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            job.addCallback(newCallback);
            return null;
        }
    }).when(existingCallback).onLoadFailed(any(GlideException.class));
    GlideException exception = new GlideException("test");
    job.addCallback(existingCallback);
    job.start(harness.decodeJob);
    job.onLoadFailed(exception);
    verify(newCallback).onLoadFailed(eq(exception));
}
Also used : ResourceCallback(com.bumptech.glide.request.ResourceCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 10 with ResourceCallback

use of com.bumptech.glide.request.ResourceCallback in project glide by bumptech.

the class EngineJobTest method testRemovingCallbackDuringOnResourceReadyIsIgnoredIfCallbackHasAlreadyBeenCalled.

@Test
public void testRemovingCallbackDuringOnResourceReadyIsIgnoredIfCallbackHasAlreadyBeenCalled() {
    final EngineJob<Object> job = harness.getJob();
    final ResourceCallback cb = mock(ResourceCallback.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            job.removeCallback(cb);
            return null;
        }
    }).when(cb).onResourceReady(anyResource(), isADataSource());
    job.addCallback(cb);
    job.start(harness.decodeJob);
    job.onResourceReady(harness.resource, harness.dataSource);
    verify(cb, times(1)).onResourceReady(anyResource(), isADataSource());
}
Also used : ResourceCallback(com.bumptech.glide.request.ResourceCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Aggregations

ResourceCallback (com.bumptech.glide.request.ResourceCallback)12 Test (org.junit.Test)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 Synthetic (com.bumptech.glide.util.Synthetic)2