### Question:
DownloadDispatcher { private boolean inspectForConflict(@NonNull DownloadTask task) { return inspectForConflict(task, null, null); } 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 inspectForConflict_sameTask() throws IOException { mockOkDownload(); final CallbackDispatcher callbackDispatcher = OkDownload.with().callbackDispatcher(); final DownloadListener listener = callbackDispatcher.dispatch(); DownloadTask task = mock(DownloadTask.class); final Collection<DownloadCall> calls = new ArrayList<>(); final Collection<DownloadTask> sameTaskList = new ArrayList<>(); final Collection<DownloadTask> fileBusyList = new ArrayList<>(); final DownloadCall call = mock(DownloadCall.class); when(call.equalsTask(task)).thenReturn(true); calls.add(call); assertThat(dispatcher.inspectForConflict(task, calls, sameTaskList, fileBusyList)).isTrue(); assertThat(sameTaskList).containsExactly(task); assertThat(fileBusyList).isEmpty(); verify(listener, never()).taskEnd(eq(task), any(EndCause.class), nullable(Exception.class)); }
@Test public void inspectForConflict_sameTask_isFinishing() { final DownloadTask task = mock(DownloadTask.class); final DownloadCall call = mock(DownloadCall.class); when(call.equalsTask(task)).thenReturn(true); when(call.isFinishing()).thenReturn(true); final Collection<DownloadCall> calls = new ArrayList<>(); final Collection<DownloadTask> sameTaskList = new ArrayList<>(); final Collection<DownloadTask> fileBusyList = new ArrayList<>(); calls.add(call); assertThat(dispatcher.inspectForConflict(task, calls, sameTaskList, fileBusyList)) .isFalse(); assertThat(fileBusyList).isEmpty(); assertThat(sameTaskList).isEmpty(); assertThat(finishingCalls).hasSize(1); }
@Test public void inspectForConflict_fileBusy() throws IOException { mockOkDownload(); final CallbackDispatcher callbackDispatcher = OkDownload.with().callbackDispatcher(); final DownloadListener listener = callbackDispatcher.dispatch(); DownloadTask task = mock(DownloadTask.class); final Collection<DownloadCall> calls = new ArrayList<>(); final Collection<DownloadTask> sameTaskList = new ArrayList<>(); final Collection<DownloadTask> fileBusyList = new ArrayList<>(); final DownloadCall call = mock(DownloadCall.class); final File file = mock(File.class); when(task.getFile()).thenReturn(file); when(call.getFile()).thenReturn(file); calls.add(call); assertThat(dispatcher.inspectForConflict(task, calls, sameTaskList, fileBusyList)).isTrue(); assertThat(sameTaskList).isEmpty(); assertThat(fileBusyList).containsExactly(task); verify(listener, never()).taskEnd(eq(task), any(EndCause.class), nullable(Exception.class)); }