### Question:
ConnectTrial { public void executeTrial() throws IOException { OkDownload.with().downloadStrategy().inspectNetworkOnWifi(task); OkDownload.with().downloadStrategy().inspectNetworkAvailable(); DownloadConnection connection = OkDownload.with().connectionFactory().create(task.getUrl()); boolean isNeedTrialHeadMethod; try { if (!Util.isEmpty(info.getEtag())) { connection.addHeader(IF_MATCH, info.getEtag()); } connection.addHeader(RANGE, "bytes=0-0"); final Map<String, List<String>> userHeader = task.getHeaderMapFields(); if (userHeader != null) Util.addUserRequestHeaderField(userHeader, connection); final DownloadListener listener = OkDownload.with().callbackDispatcher().dispatch(); final Map<String, List<String>> requestProperties = connection.getRequestProperties(); listener.connectTrialStart(task, requestProperties); final DownloadConnection.Connected connected = connection.execute(); task.setRedirectLocation(connected.getRedirectLocation()); Util.d(TAG, "task[" + task.getId() + "] redirect location: " + task.getRedirectLocation()); this.responseCode = connected.getResponseCode(); this.acceptRange = isAcceptRange(connected); this.instanceLength = findInstanceLength(connected); this.responseEtag = findEtag(connected); this.responseFilename = findFilename(connected); Map<String, List<String>> responseHeader = connected.getResponseHeaderFields(); if (responseHeader == null) responseHeader = new HashMap<>(); listener.connectTrialEnd(task, responseCode, responseHeader); isNeedTrialHeadMethod = isNeedTrialHeadMethodForInstanceLength(instanceLength, connected); } finally { connection.release(); } if (isNeedTrialHeadMethod) { trialHeadMethodForInstanceLength(); } } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String getResponseEtag(); @Nullable String getResponseFilename(); int getResponseCode(); boolean isEtagOverdue();  }### Answer:
@Test public void executeTrial() throws Exception { final String redirectLocation = "http: when(connected.getRedirectLocation()).thenReturn(redirectLocation); connectTrial.executeTrial(); final DownloadStrategy downloadStrategy = OkDownload.with().downloadStrategy(); verify(downloadStrategy).inspectNetworkOnWifi(eq(task)); verify(downloadStrategy).inspectNetworkAvailable(); verify(connection).addHeader(eq(IF_MATCH), eq(etag)); verify(connection).addHeader(eq(RANGE), eq("bytes=0-0")); verify(task).setRedirectLocation(redirectLocation); verify(connection).execute(); verify(connection).release(); }
@Test public void executeTrial_userHeader() throws Exception { Map<String, List<String>> userHeader = new HashMap<>(); List<String> values = new ArrayList<>(); values.add("header1-value1"); values.add("header1-value2"); userHeader.put("header1", values); values = new ArrayList<>(); values.add("header2-value"); userHeader.put("header2", values); when(task.getHeaderMapFields()).thenReturn(userHeader); connectTrial.executeTrial(); verify(connection).addHeader(eq("header1"), eq("header1-value1")); verify(connection).addHeader(eq("header1"), eq("header1-value2")); verify(connection).addHeader(eq("header2"), eq("header2-value")); }