### Question:
MultiPointOutputStream { void flushProcess() throws IOException { boolean success; final int size; synchronized (noSyncLengthMap) { size = noSyncLengthMap.size(); } final SparseArray<Long> increaseLengthMap = new SparseArray<>(size); try { for (int i = 0; i < size; i++) { final int blockIndex = outputStreamMap.keyAt(i); final long noSyncLength = noSyncLengthMap.get(blockIndex).get(); if (noSyncLength > 0) { increaseLengthMap.put(blockIndex, noSyncLength); final DownloadOutputStream outputStream = outputStreamMap .get(blockIndex); outputStream.flushAndSync(); } } success = true; } catch (IOException ex) { Util.w(TAG, "OutputStream flush and sync data to filesystem failed " + ex); success = false; } if (success) { final int increaseLengthSize = increaseLengthMap.size(); long allIncreaseLength = 0; for (int i = 0; i < increaseLengthSize; i++) { final int blockIndex = increaseLengthMap.keyAt(i); final long noSyncLength = increaseLengthMap.valueAt(i); store.onSyncToFilesystemSuccess(info, blockIndex, noSyncLength); allIncreaseLength += noSyncLength; noSyncLengthMap.get(blockIndex).addAndGet(-noSyncLength); Util.d(TAG, "OutputStream sync success (" + task.getId() + ") " + "block(" + blockIndex + ") " + " syncLength(" + noSyncLength + ")" + " currentOffset(" + info.getBlock(blockIndex).getCurrentOffset() + ")"); } allNoSyncLength.addAndGet(-allIncreaseLength); lastSyncTimestamp.set(SystemClock.uptimeMillis()); } } 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 flushProcess() throws IOException { final DownloadOutputStream outputStream = mock(DownloadOutputStream.class); doReturn(outputStream).when(multiPointOutputStream).outputStream(1); when(info.getBlock(1)).thenReturn(mock(BlockInfo.class)); multiPointOutputStream.allNoSyncLength.addAndGet(10); multiPointOutputStream.noSyncLengthMap.put(1, new AtomicLong(10)); multiPointOutputStream.outputStreamMap.put(1, mock(DownloadOutputStream.class)); multiPointOutputStream.flushProcess(); verify(store).onSyncToFilesystemSuccess(info, 1, 10); assertThat(multiPointOutputStream.allNoSyncLength.get()).isZero(); assertThat(multiPointOutputStream.noSyncLengthMap.get(1).get()).isZero(); }