### Question:
DownloadDispatcher { boolean inspectCompleted(@NonNull DownloadTask task) { return inspectCompleted(task, 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 inspectCompleted() throws IOException { mockOkDownload(); final CallbackDispatcher callbackDispatcher = OkDownload.with().callbackDispatcher(); final DownloadTask task = mock(DownloadTask.class); when(task.isPassIfAlreadyCompleted()).thenReturn(true); when(task.getId()).thenReturn(0); when(task.getUrl()).thenReturn("url"); when(task.getParentFile()).thenReturn(existFile.getParentFile()); final BreakpointStore store = OkDownload.with().breakpointStore(); doReturn(existFile.getName()).when(store).getResponseFilename("url"); final DownloadStrategy downloadStrategy = OkDownload.with().downloadStrategy(); doReturn(false).when(downloadStrategy).validFilenameFromStore(task); assertThat(dispatcher.inspectCompleted(task)).isFalse(); verify(callbackDispatcher, never()).dispatch(); doReturn(true).when(downloadStrategy).validFilenameFromStore(task); assertThat(dispatcher.inspectCompleted(task)).isTrue(); final DownloadListener listener = callbackDispatcher.dispatch(); verify(listener).taskEnd(eq(task), eq(EndCause.COMPLETED), nullable(Exception.class)); verify(downloadStrategy).validInfoOnCompleted(eq(task), eq(this.store)); }
@Test public void inspectCompleted_collection() throws IOException { mockOkDownload(); final DownloadStrategy downloadStrategy = OkDownload.with().downloadStrategy(); final CallbackDispatcher callbackDispatcher = OkDownload.with().callbackDispatcher(); final DownloadListener listener = callbackDispatcher.dispatch(); final DownloadTask task = mock(DownloadTask.class); when(task.isPassIfAlreadyCompleted()).thenReturn(true); when(task.getId()).thenReturn(0); when(task.getUrl()).thenReturn("url"); when(task.getParentFile()).thenReturn(existFile.getParentFile()); final BreakpointStore store = OkDownload.with().breakpointStore(); doReturn(existFile.getName()).when(store).getResponseFilename("url"); doReturn(true).when(downloadStrategy).validFilenameFromStore(task); final Collection<DownloadTask> completedCollection = new ArrayList<>(); assertThat(dispatcher.inspectCompleted(task, completedCollection)).isTrue(); verify(listener, never()).taskEnd(eq(task), any(EndCause.class), nullable(Exception.class)); assertThat(completedCollection).containsExactly(task); }