BrowserCompatSpec extends CookieSpecBase { public List<Header> formatCookies(final List<Cookie> cookies) { if (cookies == null) { throw new IllegalArgumentException("List of cookies may not be null"); } if (cookies.isEmpty()) { throw new IllegalArgumentException("List of cookies may not be empty"); } CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size()); buffer.append(SM.COOKIE); buffer.append(": "); for (int i = 0; i < cookies.size(); i++) { Cookie cookie = cookies.get(i); if (i > 0) { buffer.append("; "); } buffer.append(cookie.getName()); buffer.append("="); String s = cookie.getValue(); if (s != null) { buffer.append(s); } } List<Header> headers = new ArrayList<Header>(1); headers.add(new BufferedHeader(buffer)); return headers; } BrowserCompatSpec(final String[] datepatterns);  BrowserCompatSpec(); List<Cookie> parse(final Header header, final CookieOrigin origin); List<Header> formatCookies(final List<Cookie> cookies); int getVersion(); Header getVersionHeader(); @Override String toString();  }
@Test public void testNullCookieValueFormatting() { BasicClientCookie cookie = new BasicClientCookie("name", null); cookie.setDomain(".whatever.com"); cookie.setAttribute(ClientCookie.DOMAIN_ATTR, cookie.getDomain()); cookie.setPath("/"); cookie.setAttribute(ClientCookie.PATH_ATTR, cookie.getPath()); CookieSpec cookiespec = new BrowserCompatSpec(); List<Cookie> cookies = new ArrayList<Cookie>(1); cookies.add(cookie); List<Header> headers = cookiespec.formatCookies(cookies); Assert.assertNotNull(headers); Assert.assertEquals(1, headers.size()); Assert.assertEquals("name=", headers.get(0).getValue()); }