### Question:
DownloadDispatcher { @SuppressWarnings("PMD.ForLoopsMustUseBraces") public void cancelAll() { skipProceedCallCount.incrementAndGet(); List<DownloadTask> taskList = new ArrayList<>(); for (DownloadCall call : readyAsyncCalls) taskList.add(call.task); for (DownloadCall call : runningAsyncCalls) taskList.add(call.task); for (DownloadCall call : runningSyncCalls) taskList.add(call.task); if (!taskList.isEmpty()) { DownloadTask[] tasks = new DownloadTask[taskList.size()]; cancelLocked(taskList.toArray(tasks)); } skipProceedCallCount.decrementAndGet(); } DownloadDispatcher();   DownloadDispatcher(List<DownloadCall> readyAsyncCalls,
                       List<DownloadCall> runningAsyncCalls,
                       List<DownloadCall> runningSyncCalls,
                       List<DownloadCall> finishingCalls); void setDownloadStore(@NonNull DownloadStore store); void enqueue(DownloadTask[] tasks); void enqueue(DownloadTask task); void execute(DownloadTask task); @SuppressWarnings("PMD.ForLoopsMustUseBraces") void cancelAll(); void cancel(IdentifiedTask[] tasks); boolean cancel(IdentifiedTask task); boolean cancel(int id); @Nullable synchronized DownloadTask findSameTask(DownloadTask task); synchronized boolean isRunning(DownloadTask task); synchronized boolean isPending(DownloadTask task); synchronized void flyingCanceled(DownloadCall call); synchronized void finish(DownloadCall call); synchronized boolean isFileConflictAfterRun(@NonNull DownloadTask task); static void setMaxParallelRunningCount(int maxParallelRunningCount);  }### Answer:
@Test public void cancelAll() { List<DownloadCall> mockReadyAsyncCalls = new ArrayList<>(); mockReadyAsyncCalls.add(spy(DownloadCall.create(mockTask(1), true, store))); mockReadyAsyncCalls.add(spy(DownloadCall.create(mockTask(2), true, store))); mockReadyAsyncCalls.add(spy(DownloadCall.create(mockTask(3), true, store))); mockReadyAsyncCalls.add(spy(DownloadCall.create(mockTask(4), true, store))); readyAsyncCalls.addAll(mockReadyAsyncCalls); runningAsyncCalls.add(spy(DownloadCall.create(mockTask(5), true, store))); runningAsyncCalls.add(spy(DownloadCall.create(mockTask(6), true, store))); runningAsyncCalls.add(spy(DownloadCall.create(mockTask(7), true, store))); runningAsyncCalls.add(spy(DownloadCall.create(mockTask(8), true, store))); runningSyncCalls.add(spy(DownloadCall.create(mockTask(9), false, store))); runningSyncCalls.add(spy(DownloadCall.create(mockTask(10), false, store))); runningSyncCalls.add(spy(DownloadCall.create(mockTask(11), false, store))); runningSyncCalls.add(spy(DownloadCall.create(mockTask(12), false, store))); dispatcher.cancelAll(); assertThat(readyAsyncCalls).isEmpty(); final ArgumentCaptor<Collection<DownloadTask>> callCaptor = ArgumentCaptor.forClass(Collection.class); verify(OkDownload.with().callbackDispatcher()).endTasksWithCanceled(callCaptor.capture()); assertThat(callCaptor.getValue()).hasSize(12); for (DownloadCall call : mockReadyAsyncCalls) { verify(call, never()).cancel(); } assertThat(runningAsyncCalls).hasSize(4); for (DownloadCall call : runningAsyncCalls) { verify(call).cancel(); } assertThat(runningSyncCalls).hasSize(4); for (DownloadCall call : runningSyncCalls) { verify(call).cancel(); } }