### Question:
CallbackDispatcher { public void endTasksWithError(@NonNull final Collection<DownloadTask> errorCollection, @NonNull final Exception realCause) { if (errorCollection.size() <= 0) return; Util.d(TAG, "endTasksWithError error[" + errorCollection.size() + "] realCause: " + realCause); final Iterator<DownloadTask> iterator = errorCollection.iterator(); while (iterator.hasNext()) { final DownloadTask task = iterator.next(); if (!task.isAutoCallbackToUIThread()) { task.getListener().taskEnd(task, EndCause.ERROR, realCause); iterator.remove(); } } uiHandler.post(new Runnable() { @Override public void run() { for (DownloadTask task : errorCollection) { task.getListener().taskEnd(task, EndCause.ERROR, realCause); } } }); } CallbackDispatcher(@NonNull Handler handler, @NonNull DownloadListener transmit);  CallbackDispatcher(); boolean isFetchProcessMoment(DownloadTask task); void endTasksWithError(@NonNull final Collection<DownloadTask> errorCollection,
                                  @NonNull final Exception realCause); void endTasks(@NonNull final Collection<DownloadTask> completedTaskCollection,
                         @NonNull final Collection<DownloadTask> sameTaskConflictCollection,
                         @NonNull final Collection<DownloadTask> fileBusyCollection); void endTasksWithCanceled(@NonNull final Collection<DownloadTask> canceledCollection); DownloadListener dispatch();  }### Answer:
@Test public void endTasksWithError() { final Collection<DownloadTask> errorCollection = new ArrayList<>(); final Exception realCause = mock(Exception.class); final DownloadTask autoUiTask = mock(DownloadTask.class); final DownloadTask nonUiTask = mock(DownloadTask.class); final DownloadListener nonUiListener = mock(DownloadListener.class); final DownloadListener autoUiListener = mock(DownloadListener.class); when(autoUiTask.getListener()).thenReturn(autoUiListener); when(autoUiTask.isAutoCallbackToUIThread()).thenReturn(true); when(nonUiTask.getListener()).thenReturn(nonUiListener); when(nonUiTask.isAutoCallbackToUIThread()).thenReturn(false); errorCollection.add(autoUiTask); errorCollection.add(nonUiTask); dispatcher.endTasksWithError(errorCollection, realCause); verify(nonUiListener).taskEnd(eq(nonUiTask), eq(EndCause.ERROR), eq(realCause)); verify(handler).post(any(Runnable.class)); verify(autoUiListener).taskEnd(eq(autoUiTask), eq(EndCause.ERROR), eq(realCause)); }