CookieHeaderDelegate implements RuntimeDelegate.HeaderDelegate<Cookie> { @Override public String toString(Cookie cookie) { if (cookie == null) { throw new IllegalArgumentException(); } StringBuilder sb = new StringBuilder(); sb.append("$Version=").append(cookie.getVersion()).append(';'); sb.append(cookie.getName()).append('=').append(addQuotesIfHasWhitespace(cookie.getValue())); if (cookie.getDomain() != null) { sb.append(';').append("$Domain=").append(addQuotesIfHasWhitespace(cookie.getDomain())); } if (cookie.getPath() != null) { sb.append(';').append("$Path=").append(addQuotesIfHasWhitespace(cookie.getPath())); } return sb.toString(); }  @Override Cookie fromString(String header); @Override String toString(Cookie cookie);  }
@Test public void testToString() throws Exception { Cookie cookie = new Cookie("foo", "bar", "/aaa", "andrew.com"); assertEquals("$Version=1;foo=bar;$Domain=andrew.com;$Path=/aaa", cookieHeaderDelegate.toString(cookie)); }
@Test(expected = IllegalArgumentException.class) public void throwsExceptionWhenCookieIsNull() throws Exception { cookieHeaderDelegate.toString(null); }