### Question:
HttpHeadersImpl implements HttpHeaders { public Map<String, Cookie> getCookies() { List<String> values = headers.get(HttpHeaders.COOKIE); if (values == null || values.isEmpty()) { return Collections.emptyMap(); } Map<String, Cookie> cl = new HashMap<>(); for (String value : values) { if (value == null) { continue; } List<String> cs = getHeaderValues(HttpHeaders.COOKIE, value, getCookieSeparator(value)); for (String c : cs) { Cookie cookie = Cookie.valueOf(c); cl.put(cookie.getName(), cookie); } } return cl; } HttpHeadersImpl(Message message); List<MediaType> getAcceptableMediaTypes(); Map<String, Cookie> getCookies(); Locale getLanguage(); MediaType getMediaType(); MultivaluedMap<String, String> getRequestHeaders(); List<Locale> getAcceptableLanguages(); List<String> getRequestHeader(String name); Date getDate(); String getHeaderString(String headerName); int getLength();  }### Answer:
@Test public void testGetCookies() throws Exception { Message m = createMessage(createHeader(HttpHeaders.COOKIE, "a=$b;c=d")); HttpHeaders h = new HttpHeadersImpl(m); Map<String, Cookie> cookies = h.getCookies(); assertEquals(2, cookies.size()); assertEquals("$b", cookies.get("a").getValue()); assertEquals("d", cookies.get("c").getValue()); }
@Test public void testGetCookieWithAttributes() throws Exception { Message m = createMessage(createHeader(HttpHeaders.COOKIE, "$Version=1;a=b")); HttpHeaders h = new HttpHeadersImpl(m); Map<String, Cookie> cookies = h.getCookies(); assertEquals(1, cookies.size()); Cookie cookie = cookies.get("a"); assertEquals("b", cookie.getValue()); assertEquals(1, cookie.getVersion()); }
@Test public void testGetCookiesWithAttributes() throws Exception { Message m = createMessage(createHeader(HttpHeaders.COOKIE, "$Version=1;a=b, $Version=1;c=d")); HttpHeaders h = new HttpHeadersImpl(m); Map<String, Cookie> cookies = h.getCookies(); assertEquals(2, cookies.size()); Cookie cookieA = cookies.get("a"); assertEquals("b", cookieA.getValue()); assertEquals(1, cookieA.getVersion()); Cookie cookieC = cookies.get("c"); assertEquals("d", cookieC.getValue()); assertEquals(1, cookieA.getVersion()); }
@Test public void testGetCookiesWithComma() throws Exception { Message m = createMessage(createHeader(HttpHeaders.COOKIE, "a=b,c=d")); Exchange ex = new ExchangeImpl(); ex.setInMessage(m); ex.put(HttpHeadersImpl.COOKIE_SEPARATOR_PROPERTY, ","); m.setExchange(ex); HttpHeaders h = new HttpHeadersImpl(m); Map<String, Cookie> cookies = h.getCookies(); assertEquals(2, cookies.size()); assertEquals("b", cookies.get("a").getValue()); assertEquals("d", cookies.get("c").getValue()); }
@Test public void testGetCookiesWithCRLF() throws Exception { Message m = createMessage(createHeader(HttpHeaders.COOKIE, "a=b\r\nc=d")); Exchange ex = new ExchangeImpl(); ex.setInMessage(m); ex.put(HttpHeadersImpl.COOKIE_SEPARATOR_PROPERTY, "crlf"); m.setExchange(ex); HttpHeaders h = new HttpHeadersImpl(m); Map<String, Cookie> cookies = h.getCookies(); assertEquals(2, cookies.size()); assertEquals("b", cookies.get("a").getValue()); assertEquals("d", cookies.get("c").getValue()); }
@Test(expected = InternalServerErrorException.class) public void testInvalidCookieSeparator() throws Exception { Message m = createMessage(createHeader(HttpHeaders.COOKIE, "a=b,c=d")); Exchange ex = new ExchangeImpl(); ex.setInMessage(m); ex.put(HttpHeadersImpl.COOKIE_SEPARATOR_PROPERTY, "(e+)+"); m.setExchange(ex); HttpHeaders h = new HttpHeadersImpl(m); h.getCookies(); }