CookieJar { public static Map<String, String> decodeCookies(String header) { Map<String, String> cookies = new HashMap<>(); String [] cookiePairs = header.split(";"); if (cookiePairs.length != 0) { for (String cookiePair : cookiePairs) { String[] keyVal = cookiePair.split("="); if (keyVal.length == 2) { cookies.put(keyVal[0].trim(), keyVal[1].trim()); } } } return cookies; }  void add(URI uri, Cookie cookie); Map<String, String> list(URI uri); static String encodeCookies(Map<String, String> cookies); static Map<String, String> decodeCookies(String header); boolean isEmpty();  }
@Test public void testCookieDecode() { String cookieString = "key1=val1; key2=val2"; Map<String, String> cookies = CookieJar.decodeCookies(cookieString); assertEquals(cookies.get("key1"), "val1"); assertEquals(cookies.get("key2"), "val2"); cookieString = "foo=bar"; cookies = CookieJar.decodeCookies(cookieString); assertEquals(cookies.get("foo"), "bar"); cookieString = ""; cookies = CookieJar.decodeCookies(cookieString); assertEquals(cookies.size(), 0); cookieString = ";"; cookies = CookieJar.decodeCookies(cookieString); assertEquals(cookies.size(), 0); cookieString = "foo=;foo=bar"; cookies = CookieJar.decodeCookies(cookieString); assertEquals(cookies.size(), 1); assertEquals(cookies.get("foo"), "bar"); }