/** * Test one cookie header. * * @param headerValue The cookie header value. * @throws IOException */ private void testCookieValues(String headerValue) throws IOException { CookieReader cr = new CookieReader(headerValue); List<Cookie> cookies = new ArrayList<Cookie>(); Cookie cookie = cr.readValue(); while (cookie != null) { cookies.add(cookie); cookie = cr.readValue(); } // Rewrite the header String newHeaderValue = CookieWriter.write(cookies); // Reparse List<Cookie> cookies2 = new ArrayList<Cookie>(); cr = new CookieReader(newHeaderValue); cookie = cr.readValue(); while (cookie != null) { cookies2.add(cookie); cookie = cr.readValue(); } // Compare initial and new cookies assertEquals(cookies.size(), cookies2.size()); for (int i = 0; i < cookies.size(); i++) { assertEquals(cookies.get(i).getName(), cookies2.get(i).getName()); assertEquals(cookies.get(i).getValue(), cookies2.get(i).getValue()); } }
/** * Test one cookie header. * * @param headerValue The cookie header value. * @throws IOException */ private void testCookie(String headerValue) throws IOException { CookieReader cr = new CookieReader(headerValue); List<Cookie> cookies = new ArrayList<Cookie>(); Cookie cookie = cr.readValue(); while (cookie != null) { cookies.add(cookie); cookie = cr.readValue(); } // Rewrite the header String newHeaderValue = CookieWriter.write(cookies); // Compare initial and new headers assertEquals(headerValue, newHeaderValue); }