public void testNewerCacheableResponsesReplaceExistingCacheEntry() throws Exception {
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
final Date now = new Date();
final Date fiveSecondsAgo = new Date(now.getTime() - 5 * 1000L);
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
final HttpResponse resp1 = HttpTestUtils.make200Response();
resp1.setHeader("Date", DateUtils.formatDate(fiveSecondsAgo));
resp1.setHeader("Cache-Control", "max-age=3600");
resp1.setHeader("Etag", "\"old-etag\"");
backendExpectsAnyRequestAndReturn(resp1);
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
req2.setHeader("Cache-Control", "max-age=0");
final HttpResponse resp2 = HttpTestUtils.make200Response();
resp2.setHeader("ETag", "\"new-etag\"");
resp2.setHeader("Date", DateUtils.formatDate(now));
resp2.setHeader("Cache-Control", "max-age=3600");
backendExpectsAnyRequestAndReturn(resp2);
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
replayMocks();
impl.execute(route, req1, context, null);
impl.execute(route, req2, context, null);
final HttpResponse result = impl.execute(route, req3, context, null);