### Question:
AbstractHttpCache implements HttpCache { public boolean addResponse(HttpRequest request, HttpResponse response) { if (isCacheable(request, response)) { HttpResponseBuilder responseBuilder = new HttpResponseBuilder(response); int forcedTtl = request.getCacheTtl(); if (forcedTtl != -1) { responseBuilder.setCacheTtl(forcedTtl); } response = responseBuilder.create(); String keyString = createKey(request); addResponseImpl(keyString, response); return true; } return false; }  final HttpResponse getResponse(HttpRequest request); boolean addResponse(HttpRequest request, HttpResponse response); HttpResponse removeResponse(HttpRequest request); String createKey(HttpRequest request);  }### Answer:
@Test public void addResponse() { HttpRequest request = new HttpRequest(DEFAULT_URI); HttpResponse response = new HttpResponse("normal"); String key = cache.createKey(request); assertTrue("response should have been cached", cache.addResponse(request, response)); assertEquals(response, cache.map.get(key)); }
@Test public void addResponseIgnoreCache() { HttpRequest request = new HttpRequest(DEFAULT_URI) .setIgnoreCache(true); HttpResponse response = new HttpResponse("does not matter"); assertFalse("response should not have been cached", cache.addResponse(request, response)); assertEquals(0, cache.map.size()); }
@Test public void addResponseNotCacheable() { HttpRequest request = new HttpRequest(DEFAULT_URI); HttpResponse response = new HttpResponseBuilder().setStrictNoCache().create(); assertFalse(cache.addResponse(request, response)); assertEquals(0, cache.map.size()); }
@Test public void addResponseIfModifiedSince() { HttpRequest request = new HttpRequest(DEFAULT_URI); HttpResponse response = new HttpResponseBuilder().setHttpStatusCode(HttpResponse.SC_NOT_MODIFIED).create(); assertFalse(cache.addResponse(request, response)); assertEquals(0, cache.map.size()); }
@Test public void addResponseUsingPost() { HttpRequest request = new HttpRequest(DEFAULT_URI) .setMethod("POST"); HttpResponse response = new HttpResponse("does not matter"); assertFalse(cache.addResponse(request, response)); assertEquals(0, cache.map.size()); }