### Question:
DownloadDispatcher { public synchronized boolean isRunning(DownloadTask task) { Util.d(TAG, "isRunning: " + task.getId()); for (DownloadCall call : runningSyncCalls) { if (call.isCanceled()) continue; if (call.equalsTask(task)) { return true; } } for (DownloadCall call : runningAsyncCalls) { if (call.isCanceled()) continue; if (call.equalsTask(task)) { return true; } } return false; } 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 isRunning_async_true() { final DownloadCall mockRunningCall = spy(DownloadCall.create(mockTask(), true, store)); runningAsyncCalls.add(mockRunningCall); when(mockRunningCall.isCanceled()).thenReturn(false); final boolean result = dispatcher.isRunning(mockRunningCall.task); assertThat(result).isEqualTo(true); }
@Test public void isRunning_async_false() { final DownloadCall mockRunningCall = spy(DownloadCall.create(mockTask(1), true, store)); runningAsyncCalls.add(mockRunningCall); when(mockRunningCall.isCanceled()).thenReturn(true); boolean result = dispatcher.isRunning(mockRunningCall.task); assertThat(result).isEqualTo(false); runningAsyncCalls.clear(); when(mockRunningCall.isCanceled()).thenReturn(false); result = dispatcher.isRunning(mockRunningCall.task); assertThat(result).isEqualTo(false); runningAsyncCalls.add(mockRunningCall); result = dispatcher.isRunning(mockTask(2)); assertThat(result).isEqualTo(false); }
@Test public void isRunning_sync_true() { final DownloadCall mockRunningCall = spy(DownloadCall.create(mockTask(), false, store)); runningSyncCalls.add(mockRunningCall); when(mockRunningCall.isCanceled()).thenReturn(false); final boolean result = dispatcher.isRunning(mockRunningCall.task); assertThat(result).isEqualTo(true); }
@Test public void isRunning_sync_false() { final DownloadCall mockRunningCall = spy(DownloadCall.create(mockTask(1), false, store)); runningSyncCalls.add(mockRunningCall); when(mockRunningCall.isCanceled()).thenReturn(true); boolean result = dispatcher.isRunning(mockRunningCall.task); assertThat(result).isEqualTo(false); runningSyncCalls.clear(); when(mockRunningCall.isCanceled()).thenReturn(false); result = dispatcher.isRunning(mockRunningCall.task); assertThat(result).isEqualTo(false); runningSyncCalls.add(mockRunningCall); result = dispatcher.isRunning(mockTask(2)); assertThat(result).isEqualTo(false); }