### Question:
DownloadDispatcher { public synchronized void finish(DownloadCall call) { final boolean asyncExecuted = call.asyncExecuted; final Collection<DownloadCall> calls; if (finishingCalls.contains(call)) { calls = finishingCalls; } else if (asyncExecuted) { calls = runningAsyncCalls; } else { calls = runningSyncCalls; } if (!calls.remove(call)) throw new AssertionError("Call wasn't in-flight!"); if (asyncExecuted && call.isCanceled()) flyingCanceledAsyncCallCount.decrementAndGet(); if (asyncExecuted) processCalls(); } 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(expected = AssertionError.class) public void finish_removeFailed_exception() { dispatcher.finish(mock(DownloadCall.class)); }
@Test public void finish_removeCallFromRightList() { final DownloadCall finishingSyncCall = DownloadCall.create(mockTask(1), false, store); final DownloadCall finishingAsyncCall = DownloadCall.create(mockTask(2), true, store); final DownloadCall runningAsyncCall = DownloadCall.create(mockTask(3), true, store); final DownloadCall runningSyncCall = DownloadCall.create(mockTask(4), false, store); finishingCalls.add(finishingAsyncCall); finishingCalls.add(finishingSyncCall); runningAsyncCalls.add(runningAsyncCall); runningSyncCalls.add(runningSyncCall); dispatcher.finish(finishingAsyncCall); assertThat(finishingCalls).hasSize(1); verify(finishingCalls).remove(finishingAsyncCall); verify(runningAsyncCalls, never()).remove(any(DownloadCall.class)); verify(runningSyncCalls, never()).remove(any(DownloadCall.class)); dispatcher.finish(finishingSyncCall); assertThat(finishingCalls).hasSize(0); verify(finishingCalls).remove(finishingSyncCall); verify(runningAsyncCalls, never()).remove(any(DownloadCall.class)); verify(runningSyncCalls, never()).remove(any(DownloadCall.class)); dispatcher.finish(runningAsyncCall); verify(runningAsyncCalls).remove(runningAsyncCall); verify(runningSyncCalls, never()).remove(any(DownloadCall.class)); dispatcher.finish(runningSyncCall); verify(runningSyncCalls).remove(any(DownloadCall.class)); }