### Question:
BreakpointInterceptor implements Interceptor.Connect, Interceptor.Fetch { @Override public long interceptFetch(DownloadChain chain) throws IOException { final long contentLength = chain.getResponseContentLength(); final int blockIndex = chain.getBlockIndex(); final boolean isNotChunked = contentLength != CHUNKED_CONTENT_LENGTH; long fetchLength = 0; long processFetchLength; final MultiPointOutputStream outputStream = chain.getOutputStream(); try { while (true) { processFetchLength = chain.loopFetch(); if (processFetchLength == -1) { break; } fetchLength += processFetchLength; } } finally { chain.flushNoCallbackIncreaseBytes(); if (!chain.getCache().isUserCanceled()) outputStream.done(blockIndex); } if (isNotChunked) { outputStream.inspectComplete(blockIndex); if (fetchLength != contentLength) { throw new IOException("Fetch-length isn't equal to the response content-length, " + fetchLength + "!= " + contentLength); } } return fetchLength; }  @NonNull @Override DownloadConnection.Connected interceptConnect(DownloadChain chain); @Override long interceptFetch(DownloadChain chain);  }### Answer:
@Test public void interceptFetch_finish() throws IOException { BlockInfo blockInfo2 = new BlockInfo(10, 20); when(chain.getResponseContentLength()).thenReturn(new Long(10)); when(chain.getInfo()).thenReturn(info); when(chain.getOutputStream()).thenReturn(mock(MultiPointOutputStream.class)); when(chain.getBlockIndex()).thenReturn(1); when(info.getBlock(1)).thenReturn(blockInfo2); when(info.getBlockCount()).thenReturn(2); when(chain.loopFetch()).thenReturn(1L, 1L, 2L, 1L, 5L, -1L); final long contentLength = interceptor.interceptFetch(chain); verify(chain, times(6)).loopFetch(); verify(chain).flushNoCallbackIncreaseBytes(); assertThat(contentLength).isEqualTo(10); }
@Test public void interceptFetch_chunked() throws IOException { final BlockInfo blockInfo = new BlockInfo(0, 0); when(chain.getResponseContentLength()).thenReturn(Long.valueOf(CHUNKED_CONTENT_LENGTH)); when(chain.getInfo()).thenReturn(info); when(chain.getOutputStream()).thenReturn(mock(MultiPointOutputStream.class)); when(info.getBlock(anyInt())).thenReturn(blockInfo); when(chain.loopFetch()).thenReturn(1L, 1L, 2L, 1L, 5L, -1L); final long contentLength = interceptor.interceptFetch(chain); verify(chain, times(6)).loopFetch(); assertThat(contentLength).isEqualTo(10); }