ObserverCallbacks implements LoaderManager.LoaderCallbacks<Result<D>> { @SuppressWarnings("unchecked") @Override public void onLoadFinished(final Loader<Result<D>> loader, final Result<D> result) { AsyncObserver<D> observer = description.getObserver(loaderId); try { if (observer == null) { Log.w("EnroscarAsync", "There is no observer for loader results " + loaderId); if (result.error != null) { throw new AsyncException(result.error); } return; } if (result.error != null) { observer.onError(result.error); } else { observer.onResult(result.data); } } finally { if (destroyOnFinish) { operatorContext.loaderManager.destroyLoader(loader.getId()); } } } ObserverCallbacks(final AsyncProvider<D> asyncProvider,
                           final OperatorContext<?> operatorContext,
                           final LoaderDescription description,
                           final int loaderId,
                           final boolean destroyOnFinish); @Override Loader<Result<D>> onCreateLoader(final int id, final Bundle args); @SuppressWarnings("unchecked") @Override void onLoadFinished(final Loader<Result<D>> loader, final Result<D> result); @SuppressWarnings("unchecked") @Override void onLoaderReset(final Loader<Result<D>> loader);  }
@Test public void throwIfNoCallbacks() { Exception e = new Exception("test"); try { callbacks.onLoadFinished(null, new WrapAsyncLoader.Result<Thing>(null, e)); fail("Error not thrown"); } catch (Exception thrown) { assertThat(thrown.getCause()).isSameAs(e); } }