### Question:
ConnectTrial { boolean isNeedTrialHeadMethodForInstanceLength( long oldInstanceLength, @NonNull DownloadConnection.Connected connected) { if (oldInstanceLength != CHUNKED_CONTENT_LENGTH) { return false; } final String contentRange = connected.getResponseHeaderField(CONTENT_RANGE); if (contentRange != null && contentRange.length() > 0) { return false; } final boolean isChunked = parseTransferEncoding( connected.getResponseHeaderField(TRANSFER_ENCODING)); if (isChunked) { return false; } final String contentLengthField = connected.getResponseHeaderField(CONTENT_LENGTH); if (contentLengthField == null || contentLengthField.length() <= 0) { return false; } return true; } 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 isNeedTrialHeadMethodForInstanceLength_oldOneIsValid_false() { assertThat(connectTrial.isNeedTrialHeadMethodForInstanceLength(1, connected)).isFalse(); }
@Test public void isNeedTrialHeadMethodForInstanceLength_contentRangeValid_false() { when(connected.getResponseHeaderField(CONTENT_RANGE)).thenReturn("has value"); assertThat(connectTrial .isNeedTrialHeadMethodForInstanceLength(CHUNKED_CONTENT_LENGTH, connected)) .isFalse(); }
@Test public void isNeedTrialHeadMethodForInstanceLength_chunked_false() { when(connected.getResponseHeaderField(TRANSFER_ENCODING)).thenReturn(VALUE_CHUNKED); assertThat(connectTrial .isNeedTrialHeadMethodForInstanceLength(CHUNKED_CONTENT_LENGTH, connected)) .isFalse(); }
@Test public void isNeedTrialHeadMethodForInstanceLength_contentLengthNotResponse_false() { when(connected.getResponseHeaderField(CONTENT_LENGTH)).thenReturn(null); assertThat(connectTrial .isNeedTrialHeadMethodForInstanceLength(CHUNKED_CONTENT_LENGTH, connected)) .isFalse(); }
@Test public void isNeedTrialHeadMethodForInstanceLength_true() { when(connected.getResponseHeaderField(CONTENT_RANGE)).thenReturn(null); when(connected.getResponseHeaderField(TRANSFER_ENCODING)).thenReturn("not chunked"); when(connected.getResponseHeaderField(CONTENT_LENGTH)).thenReturn("1"); assertThat(connectTrial .isNeedTrialHeadMethodForInstanceLength(CHUNKED_CONTENT_LENGTH, connected)) .isTrue(); }