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());
}
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);
}
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));
}
}
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));
}
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());
}
Aggregations