CacheControlHeaderDelegate implements RuntimeDelegate.HeaderDelegate<CacheControl> { @Override public String toString(CacheControl header) { StringBuilder buff = new StringBuilder(); if (!header.isPrivate()) { appendString(buff, "public"); } if (header.isPrivate()) { appendWithParameters(buff, "private", header.getPrivateFields()); } if (header.isNoCache()) { appendWithParameters(buff, "no-cache", header.getNoCacheFields()); } if (header.isNoStore()) { appendString(buff, "no-store"); } if (header.isNoTransform()) { appendString(buff, "no-transform"); } if (header.isMustRevalidate()) { appendString(buff, "must-revalidate"); } if (header.isProxyRevalidate()) { appendString(buff, "proxy-revalidate"); } if (header.getMaxAge() >= 0) { appendString(buff, Integer.toString(header.getMaxAge())); } if (header.getSMaxAge() >= 0) { appendString(buff, Integer.toString(header.getSMaxAge())); } for (Map.Entry<String, String> entry : header.getCacheExtension().entrySet()) { appendWithSingleParameter(buff, entry.getKey(), entry.getValue()); } return buff.toString(); }  @Override CacheControl fromString(String header); @Override String toString(CacheControl header);  }
@Test public void testToStringCacheControlWithAllArguments() throws Exception { CacheControl cacheControl = aCacheControl() .withMaxAge(60) .withMustRevalidate(true) .withNoCache(true) .withNoStore(true) .withNoTransform(true) .withPrivate(true) .withProxyRevalidate(true) .withSMaxAge(60) .withPrivateFields(newArrayList("aaa")) .withNoCacheFields(newArrayList("bbb")) .withCacheExtension(ImmutableMap.of("foo", "bar")) .build(); assertEquals("private=\"aaa\", no-cache=\"bbb\", no-store, no-transform, must-revalidate, proxy-revalidate, 60, 60, foo=bar", cacheControlHeaderDelegate.toString(cacheControl)); }