### Question:
RetryInterceptor implements Interceptor.Connect, Interceptor.Fetch { @NonNull @Override public DownloadConnection.Connected interceptConnect(DownloadChain chain) throws IOException { final DownloadCache cache = chain.getCache(); while (true) { try { if (cache.isInterrupt()) { throw InterruptException.SIGNAL; } return chain.processConnect(); } catch (IOException e) { if (e instanceof RetryException) { chain.resetConnectForRetry(); continue; } chain.getCache().catchException(e); chain.getOutputStream().catchBlockConnectException(chain.getBlockIndex()); throw e; } } }  @NonNull @Override DownloadConnection.Connected interceptConnect(DownloadChain chain); @Override long interceptFetch(DownloadChain chain);  }### Answer:
@Test public void interceptConnect_interrupt() throws IOException { when(cache.isInterrupt()).thenReturn(true); thrown.expect(InterruptException.class); interceptor.interceptConnect(chain); verify(chain, never()).processConnect(); verify(outputStream).catchBlockConnectException(chain.getBlockIndex()); }
@Test public void interceptConnect_retry() throws IOException { doThrow(RetryException.class).doReturn(connected).when(chain).processConnect(); interceptor.interceptConnect(chain); verify(chain, times(2)).processConnect(); verify(chain).resetConnectForRetry(); verify(cache, never()).catchException(any(IOException.class)); verify(outputStream, never()).catchBlockConnectException(chain.getBlockIndex()); }
@Test public void interceptConnect_userCanceled() throws IOException { doThrow(InterruptException.class).when(chain).processConnect(); when(cache.isUserCanceled()).thenReturn(true); thrown.expect(InterruptException.class); interceptor.interceptConnect(chain); verify(cache).catchException(any(IOException.class)); verify(outputStream).catchBlockConnectException(chain.getBlockIndex()); }
@Test public void interceptConnect_failedReleaseConnection() throws IOException { final DownloadConnection connection = mock(DownloadConnection.class); when(chain.getConnection()).thenReturn(connection); doThrow(IOException.class).doReturn(connected).when(chain).processConnect(); thrown.expect(IOException.class); interceptor.interceptConnect(chain); verify(cache).catchException(any(IOException.class)); verify(outputStream).catchBlockConnectException(anyInt()); }