CacheAdapter implements InternalCache { @Override public Response get(Request request) throws IOException { CacheResponse javaResponse = getJavaCachedResponse(request); if (javaResponse == null) { return null; } return JavaApiConverter.createOkResponseForCacheGet(request, javaResponse); } CacheAdapter(ResponseCache delegate); ResponseCache getDelegate(); @Override Response get(Request request); @Override CacheRequest put(Response response); @Override void remove(Request request); @Override void update(Response cached, Response network); @Override void trackConditionalCacheHit(); @Override void trackResponse(CacheStrategy cacheStrategy);  }
@Test public void get_httpGet() throws Exception { final URL serverUrl = configureServer(new MockResponse()); assertEquals("http", serverUrl.getProtocol()); ResponseCache responseCache = new AbstractResponseCache() { @Override public CacheResponse get( URI uri, String method, Map<String, List<String>> headers) throws IOException { assertEquals(toUri(serverUrl), uri); assertEquals("GET", method); assertTrue("Arbitrary standard header not present", headers.containsKey("User-Agent")); assertEquals(Collections.singletonList("value1"), headers.get("key1")); return null; } }; setInternalCache(new CacheAdapter(responseCache)); connection = new OkUrlFactory(client).open(serverUrl); connection.setRequestProperty("key1", "value1"); executeGet(connection); }
@Test public void get_httpsGet() throws Exception { final URL serverUrl = configureHttpsServer(new MockResponse()); assertEquals("https", serverUrl.getProtocol()); ResponseCache responseCache = new AbstractResponseCache() { @Override public CacheResponse get(URI uri, String method, Map<String, List<String>> headers) throws IOException { assertEquals("https", uri.getScheme()); assertEquals(toUri(serverUrl), uri); assertEquals("GET", method); assertTrue("Arbitrary standard header not present", headers.containsKey("User-Agent")); assertEquals(Collections.singletonList("value1"), headers.get("key1")); return null; } }; setInternalCache(new CacheAdapter(responseCache)); client = client.newBuilder() .sslSocketFactory(sslContext.getSocketFactory()) .hostnameVerifier(hostnameVerifier) .build(); connection = new OkUrlFactory(client).open(serverUrl); connection.setRequestProperty("key1", "value1"); executeGet(connection); }