### Question:
DownloadChain implements Runnable { @NonNull public synchronized DownloadConnection getConnectionOrCreate() throws IOException { if (cache.isInterrupt()) throw InterruptException.SIGNAL; if (connection == null) { final String url; final String redirectLocation = cache.getRedirectLocation(); if (redirectLocation != null) { url = redirectLocation; } else { url = info.getUrl(); } Util.d(TAG, "create connection on url: " + url); connection = OkDownload.with().connectionFactory().create(url); } return connection; } private  DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info,
                          @NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLength(); void setResponseContentLength(long responseContentLength); void cancel(); @NonNull DownloadTask getTask(); @NonNull BreakpointInfo getInfo(); int getBlockIndex(); synchronized void setConnection(@NonNull DownloadConnection connection); @NonNull DownloadCache getCache(); void setRedirectLocation(String location); MultiPointOutputStream getOutputStream(); @Nullable synchronized DownloadConnection getConnection(); @NonNull synchronized DownloadConnection getConnectionOrCreate(); void increaseCallbackBytes(long increaseBytes); void flushNoCallbackIncreaseBytes(); void resetConnectForRetry(); synchronized void releaseConnection(); DownloadConnection.Connected processConnect(); long processFetch(); long loopFetch(); @NonNull DownloadStore getDownloadStore(); @Override void run();  }### Answer:
@Test public void getConnectionOrCreate() throws IOException { final String infoUrl = "infoUrl"; final DownloadConnection.Factory connectionFactory = OkDownload.with().connectionFactory(); final BreakpointInfo info = mock(BreakpointInfo.class); when(info.getUrl()).thenReturn(infoUrl); DownloadChain chain = DownloadChain.createChain(0, mock(DownloadTask.class), info, mock(DownloadCache.class), store); final DownloadConnection connection = chain.getConnectionOrCreate(); verify(connectionFactory).create(infoUrl); assertThat(chain.getConnectionOrCreate()).isEqualTo(connection); final String redirectLocation = "redirectLocation"; final DownloadCache cache = mock(DownloadCache.class); when(cache.getRedirectLocation()).thenReturn(redirectLocation); chain = DownloadChain.createChain(0, mock(DownloadTask.class), info, cache, store); chain.getConnectionOrCreate(); verify(connectionFactory).create(redirectLocation); }