CookieHeaderDelegate implements RuntimeDelegate.HeaderDelegate<Cookie> { @Override public Cookie fromString(String header) { if (header == null) { throw new IllegalArgumentException(); } List<Cookie> cookies = HeaderHelper.parseCookies(header); return Iterables.getFirst(cookies, null); }  @Override Cookie fromString(String header); @Override String toString(Cookie cookie);  }
@Test public void parsesCookieHeader() throws Exception { Cookie cookie = cookieHeaderDelegate.fromString("foo=bar"); assertEquals(new Cookie("foo", "bar"), cookie); }
@Test public void parsesCookieHeaderAndReturnsFirstIfMoreThanOneIsParsed() throws Exception { Cookie cookie = cookieHeaderDelegate.fromString("foo=bar;xxx=yyy"); assertEquals(new Cookie("foo", "bar"), cookie); }
@Test public void returnsNullIfHeaderDoesNotContainsCookie() throws Exception { Cookie cookie = cookieHeaderDelegate.fromString(""); assertNull(cookie); }
@Test(expected = IllegalArgumentException.class) public void throwsExceptionWhenCookieHeaderIsNull() throws Exception { cookieHeaderDelegate.fromString(null); }