DefaultConnection implements Connection { @Override public Collection<URL> getLinks(String relation) { return collectLinks(relation).stream() .map(this::resolveRelative) .collect(toList()); } 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 testGetLink() throws Exception { Map<String, List<String>> headers = new HashMap<>(); headers.put("Content-Type", Arrays.asList("application/json")); headers.put("Location", Arrays.asList("https: headers.put("Link", Arrays.asList( "<https: "</recover-acct>;rel=recover", "<https: )); when(mockUrlConnection.getHeaderFields()).thenReturn(headers); when(mockUrlConnection.getURL()).thenReturn(new URL("https: try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { conn.conn = mockUrlConnection; assertThat(conn.getLinks("next"), containsInAnyOrder(new URL("https: assertThat(conn.getLinks("recover"), containsInAnyOrder(new URL("https: assertThat(conn.getLinks("terms-of-service"), containsInAnyOrder(new URL("https: assertThat(conn.getLinks("secret-stuff"), is(empty())); } }
@Test public void testGetMultiLink() { URL baseUrl = url("https: Map<String, List<String>> headers = new HashMap<>(); headers.put("Link", Arrays.asList( "<https: "<https: "<../terms3>; rel=\"terms-of-service\"" )); when(mockUrlConnection.getHeaderFields()).thenReturn(headers); when(mockUrlConnection.getURL()).thenReturn(baseUrl); try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { conn.conn = mockUrlConnection; assertThat(conn.getLinks("terms-of-service"), containsInAnyOrder( url("https: url("https: url("https: )); } }
@Test public void testGetNoLink() { Map<String, List<String>> headers = Collections.emptyMap(); when(mockUrlConnection.getHeaderFields()).thenReturn(headers); try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { conn.conn = mockUrlConnection; assertThat(conn.getLinks("something"), is(empty())); } }