### Question:
CacheControlHeaderDelegate implements HeaderDelegate<CacheControl> { public String toString(CacheControl header) { if (header == null) throw new IllegalArgumentException(Messages.getMessage("headerIsNull", "CacheControl")); StringBuffer cacheControlHeader = new StringBuffer(); if (header.isPrivate()) { appendDirectiveWithValues(cacheControlHeader, PRIVATE, generateDirectiveValuesList(header.getPrivateFields())); } if (header.isNoCache()) { appendDirectiveWithValues(cacheControlHeader, NO_CACHE, generateDirectiveValuesList(header.getNoCacheFields())); } if (header.isNoStore()) { appendDirective(cacheControlHeader, NO_STORE); } if (header.isNoTransform()) { appendDirective(cacheControlHeader, NO_TRANSFORM); } if (header.isMustRevalidate()) { appendDirective(cacheControlHeader, MUST_REVALIDATE); } if (header.isProxyRevalidate()) { appendDirective(cacheControlHeader, PROXY_REVALIDATE); } if (header.getMaxAge() != -1) { appendDirective(cacheControlHeader, MAX_AGE, header.getMaxAge()); } if (header.getSMaxAge() != -1) { appendDirective(cacheControlHeader, S_MAXAGE, header.getSMaxAge()); } Set<Entry<String, String>> entrySet = header.getCacheExtension().entrySet(); if (entrySet != null && entrySet.size() > 0) { for (Entry<String, String> entry : entrySet) { appendExtentionDirective(cacheControlHeader, entry.getKey(), quoteValue(entry .getValue())); } } return cacheControlHeader.toString(); }  CacheControl fromString(String value); String toString(CacheControl header);  }### Answer:
@Test public void testSerializeCacheControlHeader() { RuntimeDelegate rd = RuntimeDelegate.getInstance(); HeaderDelegate<CacheControl> cacheControlHeaderDelegate = rd.createHeaderDelegate(CacheControl.class); if (cacheControlHeaderDelegate == null) { fail("CacheControl header delegate is not regestered in RuntimeDelegateImpl"); } String expectedCacheControlHeader = "private=\"privateField1\", " + "no-cache=\"noCachefield1, noCachefield2\", " + "no-store, " + "no-transform, " + "must-revalidate, " + "proxy-revalidate, " + "max-age=21600, " + "s-maxage=3000, " + "extension=value, " + "extension3, " + "extension2=\"value with space\""; CacheControl cc = new CacheControl(); cc.setMaxAge(21600); cc.setMustRevalidate(true); cc.setNoCache(true); cc.setNoStore(true); cc.setNoTransform(true); cc.setPrivate(true); cc.setProxyRevalidate(true); cc.setSMaxAge(3000); cc.getCacheExtension().put("extension", "value"); cc.getCacheExtension().put("extension2", "value with space"); cc.getCacheExtension().put("extension3", null); cc.getNoCacheFields().add("noCachefield1"); cc.getNoCacheFields().add("noCachefield2"); cc.getPrivateFields().add("privateField1"); String[] cache_out = cacheControlHeaderDelegate.toString(cc).split(","); String[] cache_expected = expectedCacheControlHeader.split(","); Arrays.sort(cache_expected); Arrays.sort(cache_out); assertArrayEquals(cache_expected, cache_out); try { cacheControlHeaderDelegate.toString(null); fail("CacheControl Header is null - IllegalArgumentException must be thrown"); } catch (IllegalArgumentException e) { } }