### Question:
CallbackDispatcher { public void endTasksWithCanceled(@NonNull final Collection<DownloadTask> canceledCollection) { if (canceledCollection.size() <= 0) return; Util.d(TAG, "endTasksWithCanceled canceled[" + canceledCollection.size() + "]"); final Iterator<DownloadTask> iterator = canceledCollection.iterator(); while (iterator.hasNext()) { final DownloadTask task = iterator.next(); if (!task.isAutoCallbackToUIThread()) { task.getListener().taskEnd(task, EndCause.CANCELED, null); iterator.remove(); } } uiHandler.post(new Runnable() { @Override public void run() { for (DownloadTask task : canceledCollection) { task.getListener().taskEnd(task, EndCause.CANCELED, null); } } }); } 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 endTasksWithCanceled() { final Collection<DownloadTask> canceledCollection = new ArrayList<>(); 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); canceledCollection.add(autoUiTask); canceledCollection.add(nonUiTask); dispatcher.endTasksWithCanceled(canceledCollection); verify(nonUiListener) .taskEnd(eq(nonUiTask), eq(EndCause.CANCELED), nullable(Exception.class)); verify(handler).post(any(Runnable.class)); verify(autoUiListener) .taskEnd(eq(autoUiTask), eq(EndCause.CANCELED), nullable(Exception.class)); }