.build();
final ResourceFactory resourceFactory = new FileResourceFactory(cacheDir);
final HttpCacheStorage httpCacheStorage = new ManagedHttpCacheStorage(cacheConfig);
final ClientExecChain backend = EasyMock.createNiceMock(ClientExecChain.class);
final HttpRequestWrapper get = HttpRequestWrapper.wrap(new HttpGet("http://somehost/"));
final HttpClientContext context = HttpClientContext.create();
final HttpHost target = new HttpHost("somehost");
final HttpRoute route = new HttpRoute(target);
context.setTargetHost(target);
final Date now = new Date();
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.setEntity(HttpTestUtils.makeBody(128));
response.setHeader("Content-Length", "128");
response.setHeader("ETag", "\"etag\"");
response.setHeader("Cache-Control", "public, max-age=3600");
response.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
EasyMock.expect(backend.execute(
EasyMock.eq(route),
EasyMock.isA(HttpRequestWrapper.class),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(Proxies.enhanceResponse(response));
EasyMock.replay(backend);
final BasicHttpCache cache = new BasicHttpCache(resourceFactory, httpCacheStorage, cacheConfig);
final ClientExecChain t = createCachingExecChain(backend, cache, cacheConfig);
final HttpResponse response1 = t.execute(route, get, context, null);
Assert.assertEquals(200, response1.getStatusLine().getStatusCode());
IOUtils.consume(response1.getEntity());
EasyMock.verify(backend);
removeCache();
EasyMock.reset(backend);
EasyMock.expect(backend.execute(
EasyMock.eq(route),
EasyMock.isA(HttpRequestWrapper.class),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(Proxies.enhanceResponse(response));
EasyMock.replay(backend);
final HttpResponse response2 = t.execute(route, get, context, null);
Assert.assertEquals(200, response2.getStatusLine().getStatusCode());
IOUtils.consume(response2.getEntity());
EasyMock.verify(backend);
}