### Question:
CacheValidityPolicy { protected long getAgeValue(final HttpCacheEntry entry) { long ageValue = 0; for (final Header hdr : entry.getHeaders(HeaderConstants.AGE)) { long hdrAge; try { hdrAge = Long.parseLong(hdr.getValue()); if (hdrAge < 0) { hdrAge = MAX_AGE.toSeconds(); } } catch (final NumberFormatException nfe) { hdrAge = MAX_AGE.toSeconds(); } ageValue = (hdrAge > ageValue) ? hdrAge : ageValue; } return ageValue; } CacheValidityPolicy(); TimeValue getCurrentAge(final HttpCacheEntry entry, final Date now); TimeValue getFreshnessLifetime(final HttpCacheEntry entry); boolean isResponseFresh(final HttpCacheEntry entry, final Date now); boolean isResponseHeuristicallyFresh(final HttpCacheEntry entry,
            final Date now, final float coefficient, final TimeValue defaultLifetime); TimeValue getHeuristicFreshnessLifetime(final HttpCacheEntry entry,
            final float coefficient, final TimeValue defaultLifetime); boolean isRevalidatable(final HttpCacheEntry entry); boolean mustRevalidate(final HttpCacheEntry entry); boolean proxyRevalidate(final HttpCacheEntry entry); boolean mayReturnStaleWhileRevalidating(final HttpCacheEntry entry, final Date now); boolean mayReturnStaleIfError(final HttpRequest request, final HttpCacheEntry entry, final Date now); boolean hasCacheControlDirective(final HttpCacheEntry entry, final String directive); TimeValue getStaleness(final HttpCacheEntry entry, final Date now); static final TimeValue MAX_AGE; }### Answer:
@Test public void testNegativeAgeHeaderValueReturnsMaxAge() { final Header[] headers = new Header[] { new BasicHeader("Age", "-100") }; final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers); assertEquals(CacheValidityPolicy.MAX_AGE.toSeconds(), impl.getAgeValue(entry)); }
@Test public void testMalformedAgeHeaderValueReturnsMaxAge() { final Header[] headers = new Header[] { new BasicHeader("Age", "asdf") }; final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers); assertEquals(CacheValidityPolicy.MAX_AGE.toSeconds(), impl.getAgeValue(entry)); }