### Question:
NewCookieHeaderDelegate implements HeaderDelegate<NewCookie> { public NewCookie fromString(String cookie) throws IllegalArgumentException { if (cookie == null) { throw new IllegalArgumentException(Messages.getMessage("cookieIsNull")); } String tokens[] = cookie.split(";"); ModifiableCookie modifiableCookie = null; for (String token : tokens) { String[] subTokens = token.split("=", 2); String name = subTokens.length > 0 ? subTokens[0] : null; String value = subTokens.length > 1 ? subTokens[1] : null; if (value != null && value.startsWith("\"") && value.endsWith("\"") && value.length() > 1) { value = value.substring(1, value.length() - 1); } if (modifiableCookie == null) { if (name == null) { throw new IllegalArgumentException(Messages.getMessage("cookieNameNotValid", name)); } if (value == null) { throw new IllegalArgumentException( Messages.getMessage("cookieNameValueNotValid", value)); } modifiableCookie = new ModifiableCookie(); modifiableCookie.name = name; modifiableCookie.value = value; } else if (name.trim().startsWith("Version")) { modifiableCookie.version = Integer.parseInt(value); } else if (name.trim().startsWith("Path")) { modifiableCookie.path = value; } else if (name.trim().startsWith("Domain")) { modifiableCookie.domain = value; } else if (name.trim().startsWith("Comment")) { modifiableCookie.comment = value; } else if (name.trim().startsWith("Max-Age")) { modifiableCookie.maxAge = Integer.parseInt(value); } else if (name.trim().startsWith("Secure")) { modifiableCookie.secure = true; } } return buildNewCookie(modifiableCookie); }  NewCookie fromString(String cookie); String toString(NewCookie cookie);  }### Answer:
@Test public void testParseNewCookie() { RuntimeDelegate rd = RuntimeDelegate.getInstance(); HeaderDelegate<NewCookie> newCookieHeaderDelegate = rd.createHeaderDelegate(NewCookie.class); if (newCookieHeaderDelegate == null) { fail("NewCookie header delegate is not regestered in RuntimeDelegateImpl"); } NewCookie expectedNewCookie = new NewCookie("MyCookie", "MyCookieValue", ".", "mydomain", 1, "Comment", 21600, true); String cookieToParse = "MyCookie=MyCookieValue;Version=1; Path=.; Domain=mydomain; Comment=Comment; Max-Age=21600; Secure"; NewCookie parsedNewCookie = newCookieHeaderDelegate.fromString(cookieToParse); assertEquals(expectedNewCookie, parsedNewCookie); expectedNewCookie = new NewCookie("MyCookie", "", ".", "mydomain", 1, "Comment", 21600, true); cookieToParse = "MyCookie=\"\";Version=1; Path=.; Domain=mydomain; Comment=Comment; Max-Age=21600; Secure"; parsedNewCookie = newCookieHeaderDelegate.fromString(cookieToParse); assertEquals(expectedNewCookie, parsedNewCookie); try { newCookieHeaderDelegate.fromString(null); fail("NewCookie is null - IllegalArgumentException must be thrown"); } catch (IllegalArgumentException e) { } try { newCookieHeaderDelegate.fromString("Invalid Cookie"); fail("Invalid NewCookie - IllegalArgumentException must be thrown"); } catch (IllegalArgumentException e) { } try { newCookieHeaderDelegate .fromString("MyCookieName;Version=1; Path=.; Domain=mydomain; Comment=Comment; Max-Age=21600; Secure"); fail("Invalid NewCookie - IllegalArgumentException must be thrown"); } catch (IllegalArgumentException e) { } }