hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r966642 [2/5] - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/client/cache/ main/java/org/apache/http/impl/client/cache/ test/java/org/apache/http/impl/client/cache/
Date Thu, 22 Jul 2010 13:16:30 GMT
Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java Thu Jul 22 13:16:29 2010
@@ -26,38 +26,29 @@
  */
 package org.apache.http.impl.client.cache;
 
-import java.util.Date;
 import java.util.Set;
 
 import org.apache.http.Header;
-import org.apache.http.ProtocolVersion;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.impl.cookie.DateUtils;
+import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.message.BasicHeader;
 import org.junit.Assert;
 import org.junit.Test;
 
 public class TestCacheEntry {
 
-    private static final ProtocolVersion HTTP_1_1 = new ProtocolVersion("HTTP",1,1);
-
     @Test
     public void testGetHeadersReturnsCorrectHeaders() {
         Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
                 new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
         Assert.assertEquals(2, entry.getHeaders("bar").length);
     }
 
-    private CacheEntry getEntry(Header[] headers) {
-        return getEntry(new Date(), new Date(), headers);
-    }
-
     @Test
     public void testGetFirstHeaderReturnsCorrectHeader() {
         Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
                 new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
 
         Assert.assertEquals("barValue1", entry.getFirstHeader("bar").getValue());
     }
@@ -67,8 +58,7 @@ public class TestCacheEntry {
         Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
                 new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
 
-
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
 
         Assert.assertEquals(0, entry.getHeaders("baz").length);
     }
@@ -77,334 +67,23 @@ public class TestCacheEntry {
     public void testGetFirstHeaderReturnsNullIfNoneMatch() {
         Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
                 new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
-        CacheEntry entry = getEntry(headers);
-
+        CacheEntry entry = new CacheEntry(headers);
 
         Assert.assertEquals(null, entry.getFirstHeader("quux"));
     }
 
     @Test
-    public void testApparentAgeIsMaxIntIfDateHeaderNotPresent() {
-        Header[] headers = new Header[0];
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(2147483648L, entry.getApparentAgeSecs());
-    }
-
-    @Test
-    public void testApparentAgeIsResponseReceivedTimeLessDateHeader() {
-        Date now = new Date();
-        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-
-        Header[] headers = new Header[] { new BasicHeader("Date", DateUtils
-                .formatDate(tenSecondsAgo)) };
-
-
-
-        CacheEntry entry = getEntry(now, sixSecondsAgo, headers);
-
-        Assert.assertEquals(4, entry.getApparentAgeSecs());
-    }
-
-    private CacheEntry getEntry(Date requestDate, Date responseDate, Header[] headers) {
-        return new CacheEntry(requestDate, responseDate, HTTP_1_1, headers,
-                new ByteArrayEntity(new byte[] {}), 200, "OK");
-    }
-
-    @Test
-    public void testNegativeApparentAgeIsBroughtUpToZero() {
-        Date now = new Date();
-        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-
-        Header[] headers = new Header[] { new BasicHeader("Date", DateUtils
-                .formatDate(sixSecondsAgo)) };
-
-        CacheEntry entry  = getEntry(now,tenSecondsAgo,headers);
-        Assert.assertEquals(0, entry.getApparentAgeSecs());
-    }
-
-    @Test
-    public void testCorrectedReceivedAgeIsAgeHeaderIfLarger() {
-        Header[] headers = new Header[] { new BasicHeader("Age", "10"), };
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1,
-                headers, new ByteArrayEntity(new byte[] {}), 200, "OK") {
-
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            protected long getApparentAgeSecs() {
-                return 6;
-            }
-        };
-
-
-        Assert.assertEquals(10, entry.getCorrectedReceivedAgeSecs());
-    }
-
-    @Test
-    public void testCorrectedReceivedAgeIsApparentAgeIfLarger() {
-        Header[] headers = new Header[] { new BasicHeader("Age", "6"), };
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1,
-                headers, new ByteArrayEntity(new byte[] {}), 200 ,"OK") {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            protected long getApparentAgeSecs() {
-                return 10;
-            }
-        };
-
-        Assert.assertEquals(10, entry.getCorrectedReceivedAgeSecs());
-    }
-
-    @Test
-    public void testResponseDelayIsDifferenceBetweenResponseAndRequestTimes() {
-        Date now = new Date();
-        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-
-        Header[] headers = new Header[]{};
-
-        CacheEntry entry = new CacheEntry(tenSecondsAgo, sixSecondsAgo,
-                new ProtocolVersion("HTTP",1,1), headers, new ByteArrayEntity(new byte[] {}),
-                200, "OK");
-
-
-        Assert.assertEquals(4, entry.getResponseDelaySecs());
-    }
-
-    @Test
-    public void testCorrectedInitialAgeIsCorrectedReceivedAgePlusResponseDelay() {
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1, new Header[] {},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            protected long getCorrectedReceivedAgeSecs() {
-                return 7;
-            }
-
-            @Override
-            protected long getResponseDelaySecs() {
-                return 13;
-            }
-        };
-        Assert.assertEquals(20, entry.getCorrectedInitialAgeSecs());
-    }
-
-    @Test
-    public void testResidentTimeSecondsIsTimeSinceResponseTime() {
-        final Date now = new Date();
-        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-
-        CacheEntry entry = new CacheEntry(new Date(), sixSecondsAgo, HTTP_1_1, new Header[]{},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            protected Date getCurrentDate() {
-                return now;
-            }
-        };
-
-        Assert.assertEquals(6, entry.getResidentTimeSecs());
-    }
-
-    @Test
-    public void testCurrentAgeIsCorrectedInitialAgePlusResidentTime() {
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1, new Header[]{},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            protected long getCorrectedInitialAgeSecs() {
-                return 11;
-            }
-
-            @Override
-            protected long getResidentTimeSecs() {
-                return 17;
-            }
-        };
-        Assert.assertEquals(28, entry.getCurrentAgeSecs());
-    }
-
-    @Test
-    public void testFreshnessLifetimeIsSMaxAgeIfPresent() {
-        Header[] headers = new Header[] { new BasicHeader("Cache-Control", "s-maxage=10") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
-    }
-
-    @Test
-    public void testFreshnessLifetimeIsMaxAgeIfPresent() {
-        Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=10") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
-    }
-
-    @Test
-    public void testFreshnessLifetimeIsMostRestrictiveOfMaxAgeAndSMaxAge() {
-        Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=10"),
-                new BasicHeader("Cache-Control", "s-maxage=20") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
-
-        headers = new Header[] { new BasicHeader("Cache-Control", "max-age=20"),
-                new BasicHeader("Cache-Control", "s-maxage=10") };
-        entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
-    }
-
-    @Test
-    public void testFreshnessLifetimeIsMaxAgeEvenIfExpiresIsPresent() {
-        Date now = new Date();
-        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=10"),
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
-                new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
-
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
-    }
-
-    @Test
-    public void testFreshnessLifetimeIsSMaxAgeEvenIfExpiresIsPresent() {
-        Date now = new Date();
-        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        Header[] headers = new Header[] { new BasicHeader("Cache-Control", "s-maxage=10"),
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
-                new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
-
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
-    }
-
-    @Test
-    public void testFreshnessLifetimeIsFromExpiresHeaderIfNoMaxAge() {
-        Date now = new Date();
-        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
-                new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
-
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(4, entry.getFreshnessLifetimeSecs());
-    }
-
-    @Test
-    public void testResponseIsFreshIfFreshnessLifetimeExceedsCurrentAge() {
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1, new Header[]{},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public long getCurrentAgeSecs() {
-                return 6;
-            }
-
-            @Override
-            public long getFreshnessLifetimeSecs() {
-                return 10;
-            }
-        };
-
-        Assert.assertTrue(entry.isResponseFresh());
-    }
-
-    @Test
-    public void testResponseIsNotFreshIfFreshnessLifetimeEqualsCurrentAge() {
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1, new Header[]{},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public long getCurrentAgeSecs() {
-                return 6;
-            }
-
-            @Override
-            public long getFreshnessLifetimeSecs() {
-                return 6;
-            }
-        };
-
-        Assert.assertFalse(entry.isResponseFresh());
-    }
-
-    @Test
-    public void testResponseIsNotFreshIfCurrentAgeExceedsFreshnessLifetime() {
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1, new Header[] {},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public long getCurrentAgeSecs() {
-                return 10;
-            }
-
-            @Override
-            public long getFreshnessLifetimeSecs() {
-                return 6;
-            }
-        };
-
-        Assert.assertFalse(entry.isResponseFresh());
-    }
-
-    @Test
-    public void testCacheEntryIsRevalidatableIfHeadersIncludeETag() {
-
-        Header[] headers = {
-                new BasicHeader("Expires", DateUtils.formatDate(new Date())),
-                new BasicHeader("ETag", "somevalue")};
-
-        CacheEntry entry = getEntry(headers);
-
-        Assert.assertTrue(entry.isRevalidatable());
-    }
-
-    @Test
-    public void testCacheEntryIsRevalidatableIfHeadersIncludeLastModifiedDate() {
-
-        Header[] headers = {
-                new BasicHeader("Expires", DateUtils.formatDate(new Date())),
-                new BasicHeader("Last-Modified", DateUtils.formatDate(new Date())) };
-
-        CacheEntry entry = getEntry(headers);
-        Assert.assertTrue(entry.isRevalidatable());
-    }
-
-    @Test
-    public void testCacheEntryIsNotRevalidatableIfNoAppropriateHeaders() {
-
-        Header[] headers =  {
-                new BasicHeader("Expires", DateUtils.formatDate(new Date())),
-                new BasicHeader("Cache-Control", "public") };
-
-        CacheEntry entry = getEntry(headers);
-        Assert.assertFalse(entry.isRevalidatable());
-    }
-
-
-
-    @Test
     public void testCacheEntryWithNoVaryHeaderDoesNotHaveVariants() {
         Header[] headers = new Header[0];
 
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
         Assert.assertFalse(entry.hasVariants());
     }
 
     @Test
     public void testCacheEntryWithOneVaryHeaderHasVariants() {
         Header[] headers = { new BasicHeader("Vary", "User-Agent") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
         Assert.assertTrue(entry.hasVariants());
     }
 
@@ -412,14 +91,14 @@ public class TestCacheEntry {
     public void testCacheEntryWithMultipleVaryHeadersHasVariants() {
         Header[] headers = { new BasicHeader("Vary", "User-Agent"),
                 new BasicHeader("Vary", "Accept-Encoding") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
         Assert.assertTrue(entry.hasVariants());
     }
 
     @Test
     public void testCacheEntryWithVaryStarHasVariants(){
         Header[] headers = { new BasicHeader("Vary", "*") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
         Assert.assertTrue(entry.hasVariants());
     }
 
@@ -427,10 +106,10 @@ public class TestCacheEntry {
     public void testCacheEntryCanStoreMultipleVariantUris() {
 
         Header[] headers = new Header[]{};
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
 
-        CacheEntry addedOne = entry.copyWithVariant("foo");
-        CacheEntry addedTwo = addedOne.copyWithVariant("bar");
+        HttpCacheEntry addedOne = HttpCacheEntry.copyWithVariant(entry, "foo");
+        HttpCacheEntry addedTwo = HttpCacheEntry.copyWithVariant(addedOne, "bar");
 
         Set<String> variants = addedTwo.getVariantURIs();
 
@@ -438,99 +117,4 @@ public class TestCacheEntry {
         Assert.assertTrue(variants.contains("bar"));
     }
 
-    @Test
-    public void testMalformedDateHeaderIsIgnored() {
-
-        Header[] headers = new Header[] { new BasicHeader("Date", "asdf") };
-        CacheEntry entry = getEntry(headers);
-
-        Date d = entry.getDateValue();
-
-        Assert.assertNull(d);
-    }
-
-    @Test
-    public void testMalformedContentLengthReturnsNegativeOne() {
-
-        Header[] headers = new Header[] { new BasicHeader("Content-Length", "asdf") };
-        CacheEntry entry = getEntry(headers);
-
-        long length = entry.getContentLengthValue();
-
-        Assert.assertEquals(-1, length);
-    }
-
-    @Test
-    public void testNegativeAgeHeaderValueReturnsMaxAge() {
-
-        Header[] headers = new Header[] { new BasicHeader("Age", "-100") };
-        CacheEntry entry = getEntry(headers);
-
-        long length = entry.getAgeValue();
-
-        Assert.assertEquals(CacheEntry.MAX_AGE, length);
-    }
-
-    @Test
-    public void testMalformedAgeHeaderValueReturnsMaxAge() {
-
-        Header[] headers = new Header[] { new BasicHeader("Age", "asdf") };
-        CacheEntry entry = getEntry(headers);
-
-        long length = entry.getAgeValue();
-
-        Assert.assertEquals(CacheEntry.MAX_AGE, length);
-    }
-
-    @Test
-    public void testMalformedCacheControlMaxAgeHeaderReturnsZero() {
-
-        Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=asdf") };
-        CacheEntry entry = getEntry(headers);
-
-        long maxage = entry.getMaxAge();
-
-        Assert.assertEquals(0, maxage);
-    }
-
-    @Test
-    public void testMalformedExpirationDateReturnsNull() {
-        Header[] headers = new Header[] { new BasicHeader("Expires", "asdf") };
-        CacheEntry entry = getEntry(headers);
-
-        Date expirationDate = entry.getExpirationDate();
-
-        Assert.assertNull(expirationDate);
-    }
-
-    @Test
-    public void testMustRevalidateIsFalseIfDirectiveNotPresent() {
-        Header[] headers = new Header[] { new BasicHeader("Cache-Control","public") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertFalse(entry.mustRevalidate());
-    }
-
-    @Test
-    public void testMustRevalidateIsTrueWhenDirectiveIsPresent() {
-        Header[] headers = new Header[] { new BasicHeader("Cache-Control","public, must-revalidate") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertTrue(entry.mustRevalidate());
-    }
-
-    @Test
-    public void testProxyRevalidateIsFalseIfDirectiveNotPresent() {
-        Header[] headers = new Header[] { new BasicHeader("Cache-Control","public") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertFalse(entry.proxyRevalidate());
-    }
-
-    @Test
-    public void testProxyRevalidateIsTrueWhenDirectiveIsPresent() {
-        Header[] headers = new Header[] { new BasicHeader("Cache-Control","public, proxy-revalidate") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertTrue(entry.proxyRevalidate());
-    }
-
-
-
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryGenerator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryGenerator.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryGenerator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryGenerator.java Thu Jul 22 13:16:29 2010
@@ -32,6 +32,7 @@ import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.ProtocolVersion;
+import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.message.BasicHttpResponse;
 import org.junit.Assert;
@@ -51,7 +52,7 @@ public class TestCacheEntryGenerator {
 
         response.setHeader("fooHeader", "fooHeaderValue");
 
-        CacheEntry entry = gen.generateEntry(new Date(), new Date(), response, new byte[] {});
+        HttpCacheEntry entry = gen.generateEntry(new Date(), new Date(), response, new byte[] {});
 
         Assert.assertEquals("HTTP", entry.getProtocolVersion().getProtocol());
         Assert.assertEquals(1, entry.getProtocolVersion().getMajor());

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java Thu Jul 22 13:16:29 2010
@@ -29,13 +29,13 @@ package org.apache.http.impl.client.cach
 import org.apache.http.Header;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolVersion;
-import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.message.BasicStatusLine;
-import org.easymock.classextension.EasyMock;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -48,59 +48,28 @@ import static junit.framework.Assert.ass
 
 public class TestCacheEntryUpdater {
 
-
-    private static final ProtocolVersion HTTP_1_1 = new ProtocolVersion("HTTP", 1, 1);
-
-
-    private HttpResponse mockResponse;
-    private CacheEntry mockCacheEntry;
     private Date requestDate;
     private Date responseDate;
 
-    private boolean implMocked = false;
     private CacheEntryUpdater impl;
 
     @Before
     public void setUp() throws Exception {
-        mockResponse = EasyMock.createMock(HttpResponse.class);
-        mockCacheEntry = EasyMock.createMock(CacheEntry.class);
-
         requestDate = new Date(System.currentTimeMillis() - 1000);
         responseDate = new Date();
 
         impl = new CacheEntryUpdater();
     }
 
-    private void replayMocks() {
-        EasyMock.replay(mockResponse);
-        EasyMock.replay(mockCacheEntry);
-        if (implMocked) {
-            EasyMock.replay(impl);
-        }
-    }
-
-    private void verifyMocks() {
-        EasyMock.verify(mockResponse);
-        EasyMock.verify(mockCacheEntry);
-        if (implMocked) {
-            EasyMock.verify(impl);
-        }
-    }
-
     @Test
     public void testUpdateCacheEntryReturnsDifferentEntryInstance() throws IOException {
 
-        CacheEntry entry = getEntry(new Header[]{});
-        BasicHttpResponse response = new BasicHttpResponse(HTTP_1_1, 200, "OK");
+        CacheEntry entry = new CacheEntry();
+        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
 
-        replayMocks();
-
-        CacheEntry newEntry = impl.updateCacheEntry(entry, requestDate, responseDate, response);
-
-        verifyMocks();
+        HttpCacheEntry newEntry = impl.updateCacheEntry(entry, requestDate, responseDate, response);
 
         assertNotSame(newEntry, entry);
-
     }
 
     @Test
@@ -110,13 +79,13 @@ public class TestCacheEntryUpdater {
                 new BasicHeader("Date", DateUtils.formatDate(responseDate)),
                 new BasicHeader("ETag", "\"etag\"")};
 
-        CacheEntry cacheEntry = getEntry(headers);
+        CacheEntry cacheEntry = new CacheEntry(headers);
 
         HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion(
                 "http", 1, 1), HttpStatus.SC_NOT_MODIFIED, ""));
         response.setHeaders(new Header[]{});
 
-        CacheEntry updatedEntry = impl.updateCacheEntry(cacheEntry, new Date(), new Date(), response);
+        HttpCacheEntry updatedEntry = impl.updateCacheEntry(cacheEntry, new Date(), new Date(), response);
 
         Assert.assertEquals(2, updatedEntry.getAllHeaders().length);
 
@@ -133,7 +102,7 @@ public class TestCacheEntryUpdater {
                 new BasicHeader("Cache-Control", "private"), new BasicHeader("ETag", "\"etag\""),
                 new BasicHeader("Last-Modified", DateUtils.formatDate(requestDate)),
                 new BasicHeader("Cache-Control", "max-age=0"),};
-        CacheEntry cacheEntry = getEntry(headers);
+        CacheEntry cacheEntry = new CacheEntry(headers);
 
         HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion(
                 "http", 1, 1), HttpStatus.SC_NOT_MODIFIED, ""));
@@ -141,7 +110,7 @@ public class TestCacheEntryUpdater {
                 new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
                 new BasicHeader("Cache-Control", "public"),});
 
-        CacheEntry updatedEntry = impl.updateCacheEntry(cacheEntry, new Date(), new Date(), response);
+        HttpCacheEntry updatedEntry = impl.updateCacheEntry(cacheEntry, new Date(), new Date(), response);
 
 
         Assert.assertEquals(4, updatedEntry.getAllHeaders().length);
@@ -160,14 +129,14 @@ public class TestCacheEntryUpdater {
                 new BasicHeader("Date", DateUtils.formatDate(requestDate)),
                 new BasicHeader("ETag", "\"etag\"")};
 
-        CacheEntry cacheEntry = getEntry(headers);
+        CacheEntry cacheEntry = new CacheEntry(headers);
         HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion(
                 "http", 1, 1), HttpStatus.SC_NOT_MODIFIED, ""));
         response.setHeaders(new Header[]{
                 new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
                 new BasicHeader("Cache-Control", "public"),});
 
-        CacheEntry updatedEntry = impl.updateCacheEntry(cacheEntry, new Date(), new Date(), response);
+        HttpCacheEntry updatedEntry = impl.updateCacheEntry(cacheEntry, new Date(), new Date(), response);
 
 
         Assert.assertEquals(4, updatedEntry.getAllHeaders().length);
@@ -191,23 +160,17 @@ public class TestCacheEntryUpdater {
         Date twoSecondsAgo = new Date(now.getTime() - 2000L);
         Date oneSecondAgo = new Date(now.getTime() - 1000L);
 
-        Header[] headers = new Header[]{};
+        CacheEntry entry = new CacheEntry(tenSecondsAgo, eightSecondsAgo);
 
-        CacheEntry entry = new CacheEntry(tenSecondsAgo, eightSecondsAgo, HTTP_1_1, headers,
-                new ByteArrayEntity(new byte[] {}), 200, "OK");
+        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
 
-        HttpResponse response = new BasicHttpResponse(HTTP_1_1, 200, "OK");
-
-        CacheEntry updated = impl.updateCacheEntry(entry, twoSecondsAgo, oneSecondAgo, response);
+        HttpCacheEntry updated = impl.updateCacheEntry(entry, twoSecondsAgo, oneSecondAgo, response);
 
         assertEquals(twoSecondsAgo, updated.getRequestDate());
         assertEquals(oneSecondAgo, updated.getResponseDate());
 
     }
 
-
-    // UTILITY
-
     private void headersContain(Header[] headers, String name, String value) {
         for (Header header : headers) {
             if (header.getName().equals(name)) {
@@ -219,13 +182,4 @@ public class TestCacheEntryUpdater {
         Assert.fail("Header [" + name + ": " + value + "] not found in headers.");
     }
 
-
-    private CacheEntry getEntry(Header[] headers) {
-        return getEntry(new Date(), new Date(), headers);
-    }
-
-    private CacheEntry getEntry(Date requestDate, Date responseDate, Header[] headers) {
-        return new CacheEntry(requestDate, responseDate, HTTP_1_1, headers,
-                new ByteArrayEntity(new byte[] {}), 200, "OK");
-    }
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheInvalidator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheInvalidator.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheInvalidator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheInvalidator.java Thu Jul 22 13:16:29 2010
@@ -46,14 +46,11 @@ public class TestCacheInvalidator {
     private static final ProtocolVersion HTTP_1_1 = new ProtocolVersion("HTTP", 1, 1);
 
     private CacheInvalidator impl;
-    private HttpCache<String, CacheEntry> mockCache;
+    private HttpCache mockCache;
     private HttpHost host;
     private URIExtractor extractor;
     private CacheEntry mockEntry;
 
-    private boolean mockedImpl;
-
-    @SuppressWarnings("unchecked")
     @Before
     public void setUp() {
         host = new HttpHost("foo.example.com");
@@ -67,17 +64,11 @@ public class TestCacheInvalidator {
     private void replayMocks() {
         EasyMock.replay(mockCache);
         EasyMock.replay(mockEntry);
-
-        if (mockedImpl)
-            EasyMock.replay(impl);
     }
 
     private void verifyMocks() {
         EasyMock.verify(mockCache);
         EasyMock.verify(mockEntry);
-
-        if (mockedImpl)
-            EasyMock.verify(impl);
     }
 
     // Tests

Copied: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheValidityPolicy.java (from r965979, httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheValidityPolicy.java?p2=httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheValidityPolicy.java&p1=httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java&r1=965979&r2=966642&rev=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheValidityPolicy.java Thu Jul 22 13:16:29 2010
@@ -27,67 +27,21 @@
 package org.apache.http.impl.client.cache;
 
 import java.util.Date;
-import java.util.Set;
 
 import org.apache.http.Header;
-import org.apache.http.ProtocolVersion;
-import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHeader;
 import org.junit.Assert;
 import org.junit.Test;
 
-public class TestCacheEntry {
-
-    private static final ProtocolVersion HTTP_1_1 = new ProtocolVersion("HTTP",1,1);
-
-    @Test
-    public void testGetHeadersReturnsCorrectHeaders() {
-        Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
-                new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(2, entry.getHeaders("bar").length);
-    }
-
-    private CacheEntry getEntry(Header[] headers) {
-        return getEntry(new Date(), new Date(), headers);
-    }
-
-    @Test
-    public void testGetFirstHeaderReturnsCorrectHeader() {
-        Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
-                new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
-        CacheEntry entry = getEntry(headers);
-
-        Assert.assertEquals("barValue1", entry.getFirstHeader("bar").getValue());
-    }
-
-    @Test
-    public void testGetHeadersReturnsEmptyArrayIfNoneMatch() {
-        Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
-                new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
-
-
-        CacheEntry entry = getEntry(headers);
-
-        Assert.assertEquals(0, entry.getHeaders("baz").length);
-    }
-
-    @Test
-    public void testGetFirstHeaderReturnsNullIfNoneMatch() {
-        Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
-                new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
-        CacheEntry entry = getEntry(headers);
-
-
-        Assert.assertEquals(null, entry.getFirstHeader("quux"));
-    }
+public class TestCacheValidityPolicy {
 
     @Test
     public void testApparentAgeIsMaxIntIfDateHeaderNotPresent() {
-        Header[] headers = new Header[0];
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(2147483648L, entry.getApparentAgeSecs());
+        CacheEntry entry = new CacheEntry();
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        Assert.assertEquals(2147483648L, impl.getApparentAgeSecs(entry));
     }
 
     @Test
@@ -99,16 +53,10 @@ public class TestCacheEntry {
         Header[] headers = new Header[] { new BasicHeader("Date", DateUtils
                 .formatDate(tenSecondsAgo)) };
 
+        CacheEntry entry = new CacheEntry(now, sixSecondsAgo, headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
 
-
-        CacheEntry entry = getEntry(now, sixSecondsAgo, headers);
-
-        Assert.assertEquals(4, entry.getApparentAgeSecs());
-    }
-
-    private CacheEntry getEntry(Date requestDate, Date responseDate, Header[] headers) {
-        return new CacheEntry(requestDate, responseDate, HTTP_1_1, headers,
-                new ByteArrayEntity(new byte[] {}), 200, "OK");
+        Assert.assertEquals(4, impl.getApparentAgeSecs(entry));
     }
 
     @Test
@@ -120,42 +68,43 @@ public class TestCacheEntry {
         Header[] headers = new Header[] { new BasicHeader("Date", DateUtils
                 .formatDate(sixSecondsAgo)) };
 
-        CacheEntry entry  = getEntry(now,tenSecondsAgo,headers);
-        Assert.assertEquals(0, entry.getApparentAgeSecs());
+        CacheEntry entry  = new CacheEntry(now,tenSecondsAgo,headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        Assert.assertEquals(0, impl.getApparentAgeSecs(entry));
     }
 
     @Test
     public void testCorrectedReceivedAgeIsAgeHeaderIfLarger() {
         Header[] headers = new Header[] { new BasicHeader("Age", "10"), };
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1,
-                headers, new ByteArrayEntity(new byte[] {}), 200, "OK") {
+        CacheEntry entry = new CacheEntry(headers);
 
-            private static final long serialVersionUID = 1L;
+        CacheValidityPolicy impl = new CacheValidityPolicy() {
 
             @Override
-            protected long getApparentAgeSecs() {
+            protected long getApparentAgeSecs(HttpCacheEntry entry) {
                 return 6;
             }
-        };
 
+        };
 
-        Assert.assertEquals(10, entry.getCorrectedReceivedAgeSecs());
+        Assert.assertEquals(10, impl.getCorrectedReceivedAgeSecs(entry));
     }
 
     @Test
     public void testCorrectedReceivedAgeIsApparentAgeIfLarger() {
         Header[] headers = new Header[] { new BasicHeader("Age", "6"), };
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1,
-                headers, new ByteArrayEntity(new byte[] {}), 200 ,"OK") {
-            private static final long serialVersionUID = 1L;
+        CacheEntry entry = new CacheEntry(headers);
+
+        CacheValidityPolicy impl = new CacheValidityPolicy() {
 
             @Override
-            protected long getApparentAgeSecs() {
+            protected long getApparentAgeSecs(HttpCacheEntry entry) {
                 return 10;
             }
+
         };
 
-        Assert.assertEquals(10, entry.getCorrectedReceivedAgeSecs());
+        Assert.assertEquals(10, impl.getCorrectedReceivedAgeSecs(entry));
     }
 
     @Test
@@ -164,97 +113,96 @@ public class TestCacheEntry {
         Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
         Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        Header[] headers = new Header[]{};
-
-        CacheEntry entry = new CacheEntry(tenSecondsAgo, sixSecondsAgo,
-                new ProtocolVersion("HTTP",1,1), headers, new ByteArrayEntity(new byte[] {}),
-                200, "OK");
+        CacheEntry entry = new CacheEntry(tenSecondsAgo, sixSecondsAgo);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
 
-
-        Assert.assertEquals(4, entry.getResponseDelaySecs());
+        Assert.assertEquals(4, impl.getResponseDelaySecs(entry));
     }
 
     @Test
     public void testCorrectedInitialAgeIsCorrectedReceivedAgePlusResponseDelay() {
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1, new Header[] {},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-            private static final long serialVersionUID = 1L;
+        CacheEntry entry = new CacheEntry();
+        CacheValidityPolicy impl = new CacheValidityPolicy() {
 
             @Override
-            protected long getCorrectedReceivedAgeSecs() {
+            protected long getCorrectedReceivedAgeSecs(HttpCacheEntry entry) {
                 return 7;
             }
 
             @Override
-            protected long getResponseDelaySecs() {
+            protected long getResponseDelaySecs(HttpCacheEntry entry) {
                 return 13;
             }
+
         };
-        Assert.assertEquals(20, entry.getCorrectedInitialAgeSecs());
+        Assert.assertEquals(20, impl.getCorrectedInitialAgeSecs(entry));
     }
 
     @Test
     public void testResidentTimeSecondsIsTimeSinceResponseTime() {
         final Date now = new Date();
-        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
+        final Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
+
+        CacheEntry entry = new CacheEntry(now, sixSecondsAgo);
 
-        CacheEntry entry = new CacheEntry(new Date(), sixSecondsAgo, HTTP_1_1, new Header[]{},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-            private static final long serialVersionUID = 1L;
+        CacheValidityPolicy impl = new CacheValidityPolicy() {
 
             @Override
             protected Date getCurrentDate() {
                 return now;
             }
+
         };
 
-        Assert.assertEquals(6, entry.getResidentTimeSecs());
+        Assert.assertEquals(6, impl.getResidentTimeSecs(entry));
     }
 
     @Test
     public void testCurrentAgeIsCorrectedInitialAgePlusResidentTime() {
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1, new Header[]{},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-            private static final long serialVersionUID = 1L;
+        CacheEntry entry = new CacheEntry();
+        CacheValidityPolicy impl = new CacheValidityPolicy() {
 
             @Override
-            protected long getCorrectedInitialAgeSecs() {
+            protected long getCorrectedInitialAgeSecs(HttpCacheEntry entry) {
                 return 11;
             }
 
             @Override
-            protected long getResidentTimeSecs() {
+            protected long getResidentTimeSecs(HttpCacheEntry entry) {
                 return 17;
             }
         };
-        Assert.assertEquals(28, entry.getCurrentAgeSecs());
+        Assert.assertEquals(28, impl.getCurrentAgeSecs(entry));
     }
 
     @Test
     public void testFreshnessLifetimeIsSMaxAgeIfPresent() {
         Header[] headers = new Header[] { new BasicHeader("Cache-Control", "s-maxage=10") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        Assert.assertEquals(10, impl.getFreshnessLifetimeSecs(entry));
     }
 
     @Test
     public void testFreshnessLifetimeIsMaxAgeIfPresent() {
         Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=10") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        Assert.assertEquals(10, impl.getFreshnessLifetimeSecs(entry));
     }
 
     @Test
     public void testFreshnessLifetimeIsMostRestrictiveOfMaxAgeAndSMaxAge() {
         Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=10"),
                 new BasicHeader("Cache-Control", "s-maxage=20") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        Assert.assertEquals(10, impl.getFreshnessLifetimeSecs(entry));
 
         headers = new Header[] { new BasicHeader("Cache-Control", "max-age=20"),
                 new BasicHeader("Cache-Control", "s-maxage=10") };
-        entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
+        entry = new CacheEntry(headers);
+        Assert.assertEquals(10, impl.getFreshnessLifetimeSecs(entry));
     }
 
     @Test
@@ -266,8 +214,9 @@ public class TestCacheEntry {
                 new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
                 new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
 
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        Assert.assertEquals(10, impl.getFreshnessLifetimeSecs(entry));
     }
 
     @Test
@@ -279,8 +228,9 @@ public class TestCacheEntry {
                 new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
                 new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
 
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        Assert.assertEquals(10, impl.getFreshnessLifetimeSecs(entry));
     }
 
     @Test
@@ -292,69 +242,66 @@ public class TestCacheEntry {
                 new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
                 new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
 
-        CacheEntry entry = getEntry(headers);
-        Assert.assertEquals(4, entry.getFreshnessLifetimeSecs());
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        Assert.assertEquals(4, impl.getFreshnessLifetimeSecs(entry));
     }
 
     @Test
     public void testResponseIsFreshIfFreshnessLifetimeExceedsCurrentAge() {
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1, new Header[]{},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-            private static final long serialVersionUID = 1L;
+        CacheEntry entry = new CacheEntry();
+        CacheValidityPolicy impl = new CacheValidityPolicy() {
 
             @Override
-            public long getCurrentAgeSecs() {
+            public long getCurrentAgeSecs(HttpCacheEntry entry) {
                 return 6;
             }
 
             @Override
-            public long getFreshnessLifetimeSecs() {
+            public long getFreshnessLifetimeSecs(HttpCacheEntry entry) {
                 return 10;
             }
         };
 
-        Assert.assertTrue(entry.isResponseFresh());
+        Assert.assertTrue(impl.isResponseFresh(entry));
     }
 
     @Test
     public void testResponseIsNotFreshIfFreshnessLifetimeEqualsCurrentAge() {
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1, new Header[]{},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-
-            private static final long serialVersionUID = 1L;
+        CacheEntry entry = new CacheEntry();
+        CacheValidityPolicy impl = new CacheValidityPolicy() {
 
             @Override
-            public long getCurrentAgeSecs() {
+            public long getCurrentAgeSecs(HttpCacheEntry entry) {
                 return 6;
             }
 
             @Override
-            public long getFreshnessLifetimeSecs() {
+            public long getFreshnessLifetimeSecs(HttpCacheEntry entry) {
                 return 6;
             }
         };
 
-        Assert.assertFalse(entry.isResponseFresh());
+        Assert.assertFalse(impl.isResponseFresh(entry));
     }
 
     @Test
     public void testResponseIsNotFreshIfCurrentAgeExceedsFreshnessLifetime() {
-        CacheEntry entry = new CacheEntry(new Date(), new Date(), HTTP_1_1, new Header[] {},
-                new ByteArrayEntity(new byte[] {}), 200, "OK") {
-            private static final long serialVersionUID = 1L;
+        CacheEntry entry = new CacheEntry();
+        CacheValidityPolicy impl = new CacheValidityPolicy() {
 
             @Override
-            public long getCurrentAgeSecs() {
+            public long getCurrentAgeSecs(HttpCacheEntry entry) {
                 return 10;
             }
 
             @Override
-            public long getFreshnessLifetimeSecs() {
+            public long getFreshnessLifetimeSecs(HttpCacheEntry entry) {
                 return 6;
             }
         };
 
-        Assert.assertFalse(entry.isResponseFresh());
+        Assert.assertFalse(impl.isResponseFresh(entry));
     }
 
     @Test
@@ -364,9 +311,10 @@ public class TestCacheEntry {
                 new BasicHeader("Expires", DateUtils.formatDate(new Date())),
                 new BasicHeader("ETag", "somevalue")};
 
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
 
-        Assert.assertTrue(entry.isRevalidatable());
+        Assert.assertTrue(impl.isRevalidatable(entry));
     }
 
     @Test
@@ -376,8 +324,10 @@ public class TestCacheEntry {
                 new BasicHeader("Expires", DateUtils.formatDate(new Date())),
                 new BasicHeader("Last-Modified", DateUtils.formatDate(new Date())) };
 
-        CacheEntry entry = getEntry(headers);
-        Assert.assertTrue(entry.isRevalidatable());
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+
+        Assert.assertTrue(impl.isRevalidatable(entry));
     }
 
     @Test
@@ -387,64 +337,20 @@ public class TestCacheEntry {
                 new BasicHeader("Expires", DateUtils.formatDate(new Date())),
                 new BasicHeader("Cache-Control", "public") };
 
-        CacheEntry entry = getEntry(headers);
-        Assert.assertFalse(entry.isRevalidatable());
-    }
-
-
-
-    @Test
-    public void testCacheEntryWithNoVaryHeaderDoesNotHaveVariants() {
-        Header[] headers = new Header[0];
-
-        CacheEntry entry = getEntry(headers);
-        Assert.assertFalse(entry.hasVariants());
-    }
-
-    @Test
-    public void testCacheEntryWithOneVaryHeaderHasVariants() {
-        Header[] headers = { new BasicHeader("Vary", "User-Agent") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertTrue(entry.hasVariants());
-    }
-
-    @Test
-    public void testCacheEntryWithMultipleVaryHeadersHasVariants() {
-        Header[] headers = { new BasicHeader("Vary", "User-Agent"),
-                new BasicHeader("Vary", "Accept-Encoding") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertTrue(entry.hasVariants());
-    }
-
-    @Test
-    public void testCacheEntryWithVaryStarHasVariants(){
-        Header[] headers = { new BasicHeader("Vary", "*") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertTrue(entry.hasVariants());
-    }
-
-    @Test
-    public void testCacheEntryCanStoreMultipleVariantUris() {
-
-        Header[] headers = new Header[]{};
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
 
-        CacheEntry addedOne = entry.copyWithVariant("foo");
-        CacheEntry addedTwo = addedOne.copyWithVariant("bar");
-
-        Set<String> variants = addedTwo.getVariantURIs();
-
-        Assert.assertTrue(variants.contains("foo"));
-        Assert.assertTrue(variants.contains("bar"));
+        Assert.assertFalse(impl.isRevalidatable(entry));
     }
 
     @Test
     public void testMalformedDateHeaderIsIgnored() {
 
         Header[] headers = new Header[] { new BasicHeader("Date", "asdf") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
 
-        Date d = entry.getDateValue();
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        Date d = impl.getDateValue(entry);
 
         Assert.assertNull(d);
     }
@@ -453,9 +359,10 @@ public class TestCacheEntry {
     public void testMalformedContentLengthReturnsNegativeOne() {
 
         Header[] headers = new Header[] { new BasicHeader("Content-Length", "asdf") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
 
-        long length = entry.getContentLengthValue();
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        long length = impl.getContentLengthValue(entry);
 
         Assert.assertEquals(-1, length);
     }
@@ -464,9 +371,10 @@ public class TestCacheEntry {
     public void testNegativeAgeHeaderValueReturnsMaxAge() {
 
         Header[] headers = new Header[] { new BasicHeader("Age", "-100") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
 
-        long length = entry.getAgeValue();
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        long length = impl.getAgeValue(entry);
 
         Assert.assertEquals(CacheEntry.MAX_AGE, length);
     }
@@ -475,9 +383,10 @@ public class TestCacheEntry {
     public void testMalformedAgeHeaderValueReturnsMaxAge() {
 
         Header[] headers = new Header[] { new BasicHeader("Age", "asdf") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
 
-        long length = entry.getAgeValue();
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        long length = impl.getAgeValue(entry);
 
         Assert.assertEquals(CacheEntry.MAX_AGE, length);
     }
@@ -486,9 +395,10 @@ public class TestCacheEntry {
     public void testMalformedCacheControlMaxAgeHeaderReturnsZero() {
 
         Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=asdf") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
 
-        long maxage = entry.getMaxAge();
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        long maxage = impl.getMaxAge(entry);
 
         Assert.assertEquals(0, maxage);
     }
@@ -496,9 +406,10 @@ public class TestCacheEntry {
     @Test
     public void testMalformedExpirationDateReturnsNull() {
         Header[] headers = new Header[] { new BasicHeader("Expires", "asdf") };
-        CacheEntry entry = getEntry(headers);
+        CacheEntry entry = new CacheEntry(headers);
 
-        Date expirationDate = entry.getExpirationDate();
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+        Date expirationDate = impl.getExpirationDate(entry);
 
         Assert.assertNull(expirationDate);
     }
@@ -506,31 +417,37 @@ public class TestCacheEntry {
     @Test
     public void testMustRevalidateIsFalseIfDirectiveNotPresent() {
         Header[] headers = new Header[] { new BasicHeader("Cache-Control","public") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertFalse(entry.mustRevalidate());
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+
+        Assert.assertFalse(impl.mustRevalidate(entry));
     }
 
     @Test
     public void testMustRevalidateIsTrueWhenDirectiveIsPresent() {
         Header[] headers = new Header[] { new BasicHeader("Cache-Control","public, must-revalidate") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertTrue(entry.mustRevalidate());
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+
+        Assert.assertTrue(impl.mustRevalidate(entry));
     }
 
     @Test
     public void testProxyRevalidateIsFalseIfDirectiveNotPresent() {
         Header[] headers = new Header[] { new BasicHeader("Cache-Control","public") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertFalse(entry.proxyRevalidate());
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
+
+        Assert.assertFalse(impl.proxyRevalidate(entry));
     }
 
     @Test
     public void testProxyRevalidateIsTrueWhenDirectiveIsPresent() {
         Header[] headers = new Header[] { new BasicHeader("Cache-Control","public, proxy-revalidate") };
-        CacheEntry entry = getEntry(headers);
-        Assert.assertTrue(entry.proxyRevalidate());
-    }
-
+        CacheEntry entry = new CacheEntry(headers);
+        CacheValidityPolicy impl = new CacheValidityPolicy();
 
+        Assert.assertTrue(impl.proxyRevalidate(entry));
+    }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java Thu Jul 22 13:16:29 2010
@@ -30,26 +30,45 @@ import java.util.Date;
 
 import org.apache.http.Header;
 import org.apache.http.HttpResponse;
-import org.apache.http.ProtocolVersion;
-import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHeader;
+import org.easymock.classextension.EasyMock;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
 public class TestCachedHttpResponseGenerator {
 
+    private CacheEntry entry;
+    private CacheValidityPolicy mockValidityPolicy;
+    private CachedHttpResponseGenerator impl;
+
+    @Before
+    public void setUp() {
+        Date now = new Date();
+        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
+        Date eightSecondsAgo = new Date(now.getTime() - 8 * 1000L);
+        Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        Date tenSecondsFromNow = new Date(now.getTime() + 10 * 1000L);
+        Header[] hdrs = { new BasicHeader("Date", DateUtils.formatDate(eightSecondsAgo)),
+                new BasicHeader("Expires", DateUtils.formatDate(tenSecondsFromNow)),
+                new BasicHeader("Content-Length", "150") };
+
+        entry = new CacheEntry(tenSecondsAgo, sixSecondsAgo, hdrs);
+        mockValidityPolicy = EasyMock.createMock(CacheValidityPolicy.class);
+        impl = new CachedHttpResponseGenerator(mockValidityPolicy);
+    }
+
+    public void replayMocks() {
+        EasyMock.replay(mockValidityPolicy);
+    }
+
     @Test
     public void testResponseHasContentLength() {
-
-        Header[] hdrs = new Header[] {};
         byte[] buf = new byte[] { 1, 2, 3, 4, 5 };
-        CacheEntry entry = new CacheEntry(
-                new Date(), new Date(), new ProtocolVersion("HTTP", 1, 1), hdrs,
-                new ByteArrayEntity(buf), 200, "OK");
+        CacheEntry entry = new CacheEntry(buf);
 
-        CachedHttpResponseGenerator gen = new CachedHttpResponseGenerator();
-        HttpResponse response = gen.generateResponse(entry);
+        HttpResponse response = impl.generateResponse(entry);
 
         Header length = response.getFirstHeader("Content-Length");
         Assert.assertNotNull("Content-Length Header is missing", length);
@@ -63,13 +82,9 @@ public class TestCachedHttpResponseGener
 
         Header[] hdrs = new Header[] { new BasicHeader("Transfer-Encoding", "chunked") };
         byte[] buf = new byte[] { 1, 2, 3, 4, 5 };
-        CacheEntry entry = new CacheEntry(
-                new Date(), new Date(), new ProtocolVersion("HTTP", 1, 1), hdrs,
-                new ByteArrayEntity(buf), 200, "OK");
-
+        CacheEntry entry = new CacheEntry(hdrs, buf);
 
-        CachedHttpResponseGenerator gen = new CachedHttpResponseGenerator();
-        HttpResponse response = gen.generateResponse(entry);
+        HttpResponse response = impl.generateResponse(entry);
 
         Header length = response.getFirstHeader("Content-Length");
 
@@ -78,10 +93,7 @@ public class TestCachedHttpResponseGener
 
     @Test
     public void testResponseMatchesCacheEntry() {
-        CacheEntry entry = buildEntry();
-
-        CachedHttpResponseGenerator gen = new CachedHttpResponseGenerator();
-        HttpResponse response = gen.generateResponse(entry);
+        HttpResponse response = impl.generateResponse(entry);
 
         Assert.assertTrue(response.containsHeader("Content-Length"));
 
@@ -92,36 +104,29 @@ public class TestCachedHttpResponseGener
 
     @Test
     public void testResponseStatusCodeMatchesCacheEntry() {
-        CacheEntry entry = buildEntry();
-
-        CachedHttpResponseGenerator gen = new CachedHttpResponseGenerator();
-        HttpResponse response = gen.generateResponse(entry);
+        HttpResponse response = impl.generateResponse(entry);
 
         Assert.assertEquals(entry.getStatusCode(), response.getStatusLine().getStatusCode());
     }
 
     @Test
     public void testAgeHeaderIsPopulatedWithCurrentAgeOfCacheEntryIfNonZero() {
-        final long currAge = 10L;
-
-        CacheEntry entry = buildEntryWithCurrentAge(currAge);
+        currentAge(10L);
+        replayMocks();
 
-        CachedHttpResponseGenerator gen = new CachedHttpResponseGenerator();
-        HttpResponse response = gen.generateResponse(entry);
+        HttpResponse response = impl.generateResponse(entry);
 
         Header ageHdr = response.getFirstHeader("Age");
         Assert.assertNotNull(ageHdr);
-        Assert.assertEquals(currAge, Long.parseLong(ageHdr.getValue()));
+        Assert.assertEquals(10L, Long.parseLong(ageHdr.getValue()));
     }
 
     @Test
     public void testAgeHeaderIsNotPopulatedIfCurrentAgeOfCacheEntryIsZero() {
-        final long currAge = 0L;
-
-        CacheEntry entry = buildEntryWithCurrentAge(currAge);
+        currentAge(0L);
+        replayMocks();
 
-        CachedHttpResponseGenerator gen = new CachedHttpResponseGenerator();
-        HttpResponse response = gen.generateResponse(entry);
+        HttpResponse response = impl.generateResponse(entry);
 
         Header ageHdr = response.getFirstHeader("Age");
         Assert.assertNull(ageHdr);
@@ -129,53 +134,19 @@ public class TestCachedHttpResponseGener
 
     @Test
     public void testAgeHeaderIsPopulatedWithMaxAgeIfCurrentAgeTooBig() {
+        currentAge(CacheEntry.MAX_AGE + 1L);
+        replayMocks();
 
-        CacheEntry entry = buildEntryWithCurrentAge(CacheEntry.MAX_AGE + 1L);
-
-        CachedHttpResponseGenerator gen = new CachedHttpResponseGenerator();
-        HttpResponse response = gen.generateResponse(entry);
+        HttpResponse response = impl.generateResponse(entry);
 
         Header ageHdr = response.getFirstHeader("Age");
         Assert.assertNotNull(ageHdr);
         Assert.assertEquals(CacheEntry.MAX_AGE, Long.parseLong(ageHdr.getValue()));
     }
 
-    private CacheEntry buildEntry() {
-        Date now = new Date();
-        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        Date eightSecondsAgo = new Date(now.getTime() - 8 * 1000L);
-        Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        Date tenSecondsFromNow = new Date(now.getTime() + 10 * 1000L);
-        Header[] hdrs = { new BasicHeader("Date", DateUtils.formatDate(eightSecondsAgo)),
-                new BasicHeader("Expires", DateUtils.formatDate(tenSecondsFromNow)),
-                new BasicHeader("Content-Length", "150") };
-
-        return new CacheEntry(tenSecondsAgo, sixSecondsAgo, new ProtocolVersion("HTTP", 1, 1),
-                hdrs, new ByteArrayEntity(new byte[] {}), 200, "OK");
+    private void currentAge(long sec) {
+        EasyMock.expect(
+                mockValidityPolicy.getCurrentAgeSecs(entry)).andReturn(sec);
     }
 
-
-    private CacheEntry buildEntryWithCurrentAge(final long currAge){
-                Date now = new Date();
-        Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        Date eightSecondsAgo = new Date(now.getTime() - 8 * 1000L);
-        Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        Date tenSecondsFromNow = new Date(now.getTime() + 10 * 1000L);
-        Header[] hdrs = { new BasicHeader("Date", DateUtils.formatDate(eightSecondsAgo)),
-                new BasicHeader("Expires", DateUtils.formatDate(tenSecondsFromNow)),
-                new BasicHeader("Content-Length", "150") };
-
-
-        return new CacheEntry(tenSecondsAgo, sixSecondsAgo, new ProtocolVersion("HTTP", 1, 1),
-                hdrs, new ByteArrayEntity(new byte[] {}), 200, "OK"){
-
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public long getCurrentAgeSecs() {
-                return currAge;
-            }
-
-        };
-    }
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedResponseSuitabilityChecker.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedResponseSuitabilityChecker.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedResponseSuitabilityChecker.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedResponseSuitabilityChecker.java Thu Jul 22 13:16:29 2010
@@ -26,7 +26,6 @@
  */
 package org.apache.http.impl.client.cache;
 
-import org.apache.http.Header;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.message.BasicHeader;
@@ -38,28 +37,28 @@ import org.junit.Test;
 
 public class TestCachedResponseSuitabilityChecker {
 
-    private CachedResponseSuitabilityChecker impl;
     private HttpHost host;
     private HttpRequest request;
-    private CacheEntry mockEntry;
-    private HttpRequest mockRequest;
+    private CacheEntry entry;
+    private CacheValidityPolicy mockValidityPolicy;
+    private CachedResponseSuitabilityChecker impl;
 
     @Before
     public void setUp() {
         host = new HttpHost("foo.example.com");
         request = new BasicHttpRequest("GET", "/foo");
-        mockEntry = EasyMock.createMock(CacheEntry.class);
-        mockRequest = EasyMock.createMock(HttpRequest.class);
+        mockValidityPolicy = EasyMock.createMock(CacheValidityPolicy.class);
+        entry = new CacheEntry();
 
-        impl = new CachedResponseSuitabilityChecker();
+        impl = new CachedResponseSuitabilityChecker(mockValidityPolicy);
     }
 
     public void replayMocks() {
-        EasyMock.replay(mockEntry, mockRequest);
+        EasyMock.replay(mockValidityPolicy);
     }
 
     public void verifyMocks() {
-        EasyMock.verify(mockEntry, mockRequest);
+        EasyMock.verify(mockValidityPolicy);
     }
 
     @Test
@@ -68,7 +67,7 @@ public class TestCachedResponseSuitabili
         contentLengthMatchesActualLength(false);
 
         replayMocks();
-        boolean result = impl.canCachedResponseBeUsed(host, request, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
 
         verifyMocks();
 
@@ -82,7 +81,7 @@ public class TestCachedResponseSuitabili
         modifiedSince(false, request);
 
         replayMocks();
-        boolean result = impl.canCachedResponseBeUsed(host, request, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
 
         verifyMocks();
 
@@ -97,7 +96,7 @@ public class TestCachedResponseSuitabili
 
         replayMocks();
 
-        boolean result = impl.canCachedResponseBeUsed(host, request, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
 
         verifyMocks();
 
@@ -109,7 +108,7 @@ public class TestCachedResponseSuitabili
         responseIsFresh(false);
         replayMocks();
 
-        boolean result = impl.canCachedResponseBeUsed(host, request, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
 
         verifyMocks();
 
@@ -125,7 +124,7 @@ public class TestCachedResponseSuitabili
 
         replayMocks();
 
-        boolean result = impl.canCachedResponseBeUsed(host, request, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
         verifyMocks();
         Assert.assertFalse(result);
     }
@@ -136,11 +135,11 @@ public class TestCachedResponseSuitabili
         responseIsFresh(true);
         contentLengthMatchesActualLength(true);
         modifiedSince(false, request);
+        currentAge(20L);
 
-        org.easymock.EasyMock.expect(mockEntry.getCurrentAgeSecs()).andReturn(20L);
         replayMocks();
 
-        boolean result = impl.canCachedResponseBeUsed(host, request, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
         verifyMocks();
         Assert.assertFalse(result);
     }
@@ -151,11 +150,11 @@ public class TestCachedResponseSuitabili
         responseIsFresh(true);
         contentLengthMatchesActualLength(true);
         modifiedSince(false, request);
+        currentAge(5L);
 
-        org.easymock.EasyMock.expect(mockEntry.getCurrentAgeSecs()).andReturn(5L);
         replayMocks();
 
-        boolean result = impl.canCachedResponseBeUsed(host, request, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
         verifyMocks();
         Assert.assertTrue(result);
     }
@@ -166,11 +165,11 @@ public class TestCachedResponseSuitabili
         responseIsFresh(true);
         contentLengthMatchesActualLength(true);
         modifiedSince(false, request);
+        freshnessLifetime(15L);
 
-        org.easymock.EasyMock.expect(mockEntry.getFreshnessLifetimeSecs()).andReturn(15L);
         replayMocks();
 
-        boolean result = impl.canCachedResponseBeUsed(host, request, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
         verifyMocks();
         Assert.assertTrue(result);
     }
@@ -181,11 +180,11 @@ public class TestCachedResponseSuitabili
         responseIsFresh(true);
         contentLengthMatchesActualLength(true);
         modifiedSince(false, request);
+        freshnessLifetime(5L);
 
-        org.easymock.EasyMock.expect(mockEntry.getFreshnessLifetimeSecs()).andReturn(5L);
         replayMocks();
 
-        boolean result = impl.canCachedResponseBeUsed(host, request, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
         verifyMocks();
         Assert.assertFalse(result);
     }
@@ -199,23 +198,21 @@ public class TestCachedResponseSuitabili
 
         replayMocks();
 
-        boolean result = impl.canCachedResponseBeUsed(host, request, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
         verifyMocks();
         Assert.assertFalse(result);
     }
 
     @Test
     public void testMalformedCacheControlMaxAgeRequestHeaderCausesUnsuitableEntry() {
-
-        Header[] hdrs = new Header[] { new BasicHeader("Cache-Control", "max-age=foo") };
+        request.addHeader(new BasicHeader("Cache-Control", "max-age=foo"));
         responseIsFresh(true);
         contentLengthMatchesActualLength(true);
-        modifiedSince(false, mockRequest);
+        modifiedSince(false, request);
 
-        org.easymock.EasyMock.expect(mockRequest.getHeaders("Cache-Control")).andReturn(hdrs);
         replayMocks();
 
-        boolean result = impl.canCachedResponseBeUsed(host, mockRequest, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
 
         verifyMocks();
 
@@ -224,32 +221,43 @@ public class TestCachedResponseSuitabili
 
     @Test
     public void testMalformedCacheControlMinFreshRequestHeaderCausesUnsuitableEntry() {
+        request.addHeader(new BasicHeader("Cache-Control", "min-fresh=foo"));
 
-        Header[] hdrs = new Header[] { new BasicHeader("Cache-Control", "min-fresh=foo") };
         responseIsFresh(true);
         contentLengthMatchesActualLength(true);
-        modifiedSince(false, mockRequest);
+        modifiedSince(false, request);
 
-        org.easymock.EasyMock.expect(mockRequest.getHeaders("Cache-Control")).andReturn(hdrs);
         replayMocks();
 
-        boolean result = impl.canCachedResponseBeUsed(host, mockRequest, mockEntry);
+        boolean result = impl.canCachedResponseBeUsed(host, request, entry);
 
         verifyMocks();
 
         Assert.assertFalse(result);
     }
 
+    private void currentAge(long sec) {
+        EasyMock.expect(
+                mockValidityPolicy.getCurrentAgeSecs(entry)).andReturn(sec);
+    }
+
+    private void freshnessLifetime(long sec) {
+        EasyMock.expect(
+                mockValidityPolicy.getFreshnessLifetimeSecs(entry)).andReturn(sec);
+    }
+
     private void responseIsFresh(boolean fresh) {
-        org.easymock.EasyMock.expect(mockEntry.isResponseFresh()).andReturn(fresh);
+        EasyMock.expect(
+                mockValidityPolicy.isResponseFresh(entry)).andReturn(fresh);
     }
 
     private void modifiedSince(boolean modified, HttpRequest request) {
-        org.easymock.EasyMock.expect(mockEntry.modifiedSince(request)).andReturn(modified);
+        EasyMock.expect(
+                mockValidityPolicy.modifiedSince(entry, request)).andReturn(modified);
     }
 
     private void contentLengthMatchesActualLength(boolean b) {
-        org.easymock.EasyMock.expect(mockEntry.contentLengthHeaderMatchesActualLength()).andReturn(
-                b);
+        EasyMock.expect(
+                mockValidityPolicy.contentLengthHeaderMatchesActualLength(entry)).andReturn(b);
     }
 }
\ No newline at end of file



Mime
View raw message