### Question:
MultiPointOutputStream { public synchronized void cancel() { if (requireStreamBlocks == null) return; if (canceled) return; canceled = true; noMoreStreamList.addAll(requireStreamBlocks); try { if (allNoSyncLength.get() <= 0) return; if (syncFuture != null && !syncFuture.isDone()) { inspectValidPath(); OkDownload.with().processFileStrategy().getFileLock().increaseLock(path); try { ensureSync(true, -1); } finally { OkDownload.with().processFileStrategy().getFileLock().decreaseLock(path); } } } finally { for (Integer blockIndex : requireStreamBlocks) { try { close(blockIndex); } catch (IOException e) { Util.d(TAG, "OutputStream close failed task[" + task.getId() + "] block[" + blockIndex + "]" + e); } } store.onTaskEnd(task.getId(), EndCause.CANCELED, null); } } MultiPointOutputStream(@NonNull final DownloadTask task,
                           @NonNull BreakpointInfo info,
                           @NonNull DownloadStore store,
                           @Nullable Runnable syncRunnable);  MultiPointOutputStream(@NonNull DownloadTask task,
                                  @NonNull BreakpointInfo info,
                                  @NonNull DownloadStore store); synchronized void write(int blockIndex, byte[] bytes, int length); void cancelAsync(); synchronized void cancel(); void done(int blockIndex); void inspectComplete(int blockIndex); void setRequireStreamBlocks(List<Integer> requireStreamBlocks); void catchBlockConnectException(int blockIndex);  }### Answer:
@Test public void cancel() throws IOException { multiPointOutputStream.requireStreamBlocks = new ArrayList<Integer>() {{ add(0); add(1); }}; multiPointOutputStream.noSyncLengthMap.put(0, new AtomicLong()); multiPointOutputStream.noSyncLengthMap.put(1, new AtomicLong()); multiPointOutputStream.allNoSyncLength.set(1); final ProcessFileStrategy strategy = OkDownload.with().processFileStrategy(); final FileLock fileLock = mock(FileLock.class); when(strategy.getFileLock()).thenReturn(fileLock); doNothing().when(multiPointOutputStream).close(anyInt()); doNothing().when(multiPointOutputStream).ensureSync(true, -1); multiPointOutputStream.cancel(); assertThat(multiPointOutputStream.noMoreStreamList).containsExactly(0, 1); verify(multiPointOutputStream).ensureSync(eq(true), eq(-1)); verify(multiPointOutputStream).close(eq(0)); verify(multiPointOutputStream).close(eq(1)); verify(fileLock).increaseLock(eq(existFile.getAbsolutePath())); verify(fileLock).decreaseLock(eq(existFile.getAbsolutePath())); verify(store).onTaskEnd(eq(task.getId()), eq(EndCause.CANCELED), nullable(Exception.class)); }