DefaultConnection implements Connection { @Override public int sendRequest(URL url, Session session, @Nullable ZonedDateTime ifModifiedSince) throws AcmeException { return sendRequest(url, session, MIME_JSON, ifModifiedSince); } DefaultConnection(HttpConnector httpConnector); @Override void resetNonce(Session session); @Override int sendRequest(URL url, Session session, @Nullable ZonedDateTime ifModifiedSince); @Override int sendCertificateRequest(URL url, Login login); @Override int sendSignedPostAsGetRequest(URL url, Login login); @Override int sendSignedRequest(URL url, JSONBuilder claims, Login login); @Override int sendSignedRequest(URL url, JSONBuilder claims, Session session, KeyPair keypair); @Override JSON readJsonResponse(); @Override List<X509Certificate> readCertificates(); @Override void handleRetryAfter(String message); @Override @Nullable String getNonce(); @Override @Nullable URL getLocation(); @Override Optional<ZonedDateTime> getLastModified(); @Override Optional<ZonedDateTime> getExpiration(); @Override Collection<URL> getLinks(String relation); @Override void close();  }
@Test public void testSendRequest() throws Exception { when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK); try (DefaultConnection conn = new DefaultConnection(mockHttpConnection) { @Override public String getNonce() { return null; } }) { conn.sendRequest(requestUrl, session, null); } verify(mockUrlConnection).setRequestMethod("GET"); verify(mockUrlConnection).setRequestProperty("Accept", "application/json"); verify(mockUrlConnection).setRequestProperty("Accept-Charset", "utf-8"); verify(mockUrlConnection).setRequestProperty("Accept-Language", "ja-JP"); verify(mockUrlConnection).setDoOutput(false); verify(mockUrlConnection).connect(); verify(mockUrlConnection).getResponseCode(); verify(mockUrlConnection, atLeast(0)).getHeaderFields(); verifyNoMoreInteractions(mockUrlConnection); }
@Test public void testSendRequestIfModifiedSince() throws Exception { ZonedDateTime ifModifiedSince = ZonedDateTime.now(ZoneId.of("UTC")); when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_NOT_MODIFIED); try (DefaultConnection conn = new DefaultConnection(mockHttpConnection) { @Override public String getNonce() { return null; } }) { int rc = conn.sendRequest(requestUrl, session, ifModifiedSince); assertThat(rc, is(HttpURLConnection.HTTP_NOT_MODIFIED)); } verify(mockUrlConnection).setRequestMethod("GET"); verify(mockUrlConnection).setRequestProperty("Accept", "application/json"); verify(mockUrlConnection).setRequestProperty("Accept-Charset", "utf-8"); verify(mockUrlConnection).setRequestProperty("Accept-Language", "ja-JP"); verify(mockUrlConnection).setRequestProperty("If-Modified-Since", ifModifiedSince.format(RFC_1123_DATE_TIME)); verify(mockUrlConnection).setDoOutput(false); verify(mockUrlConnection).connect(); verify(mockUrlConnection).getResponseCode(); verify(mockUrlConnection, atLeast(0)).getHeaderFields(); verifyNoMoreInteractions(mockUrlConnection); }