### Question:
CacheControlHeaderProvider implements HeaderDelegate<CacheControl> { public String toString(CacheControl c) { String separator = getSeparator(); StringBuilder sb = new StringBuilder(); if (c.isPrivate()) { sb.append(PRIVATE); handleFields(c.getPrivateFields(), sb); sb.append(separator); } if (c.isNoCache()) { sb.append(NO_CACHE); handleFields(c.getNoCacheFields(), sb); sb.append(separator); } if (c.isNoStore()) { sb.append(NO_STORE).append(separator); } if (c.isNoTransform()) { sb.append(NO_TRANSFORM).append(separator); } if (c.isMustRevalidate()) { sb.append(MUST_REVALIDATE).append(separator); } if (c.isProxyRevalidate()) { sb.append(PROXY_REVALIDATE).append(separator); } if (c.getMaxAge() != -1) { sb.append(MAX_AGE).append('=').append(c.getMaxAge()).append(separator); } if (c.getSMaxAge() != -1) { sb.append(SMAX_AGE).append('=').append(c.getSMaxAge()).append(separator); } Map<String, String> exts = c.getCacheExtension(); for (Map.Entry<String, String> entry : exts.entrySet()) { sb.append(entry.getKey()); String v = entry.getValue(); if (v != null) { sb.append('='); if (v.indexOf(' ') != -1) { sb.append('\"').append(v).append('\"'); } else { sb.append(v); } } sb.append(separator); } String s = sb.toString(); return s.endsWith(separator) ? s.substring(0, s.length() - 1) : s; }  CacheControl fromString(String c); String toString(CacheControl c); static final String CACHE_CONTROL_SEPARATOR_PROPERTY; }### Answer:
@Test public void testToString() { String s = "private=\"foo\",no-cache=\"bar\",no-store,no-transform," + "must-revalidate,proxy-revalidate,max-age=2,s-maxage=3"; String parsed = CacheControl.valueOf(s).toString(); assertEquals(s, parsed); }
@Test public void testNoCacheEnabled() { CacheControl cc = new CacheControl(); cc.setNoCache(true); assertEquals("no-cache,no-transform", cc.toString()); }
@Test public void testNoCacheDisabled() { CacheControl cc = new CacheControl(); cc.setNoCache(false); assertEquals("no-transform", cc.toString()); }
@Test public void testMultiplePrivateFields() { CacheControl cc = new CacheControl(); cc.setPrivate(true); cc.getPrivateFields().add("a"); cc.getPrivateFields().add("b"); assertTrue(cc.toString().contains("private=\"a,b\"")); }
@Test public void testMultipleNoCacheFields() { CacheControl cc = new CacheControl(); cc.setNoCache(true); cc.getNoCacheFields().add("c"); cc.getNoCacheFields().add("d"); assertTrue(cc.toString().contains("no-cache=\"c,d\"")); }
@Test public void testCacheExtensionToString() { CacheControl cc = new CacheControl(); cc.getCacheExtension().put("ext1", null); cc.getCacheExtension().put("ext2", "value2"); cc.getCacheExtension().put("ext3", "value 3"); String value = cc.toString(); assertTrue(value.indexOf("ext1") != -1 && value.indexOf("ext1=") == -1); assertTrue(value.indexOf("ext2=value2") != -1); assertTrue(value.indexOf("ext3=\"value 3\"") != -1); }