CookieConverter implements Serializable { String getCookieString(Cookie cookie) { StringBuilder builder = new StringBuilder(); builder.append(cookie.getName()); builder.append("="); builder.append(cookie.getValue()); if (cookie.getVersion() > 0) { builder.append(";" + VERSION + "=").append(cookie.getVersion()); } if (StringUtils.hasText(cookie.getPath())) { builder.append(";" + PATH + "=").append(cookie.getPath()); } if (StringUtils.hasText(cookie.getDomain())) { builder.append(";" + DOMAIN + "=").append(cookie.getDomain()); } if (cookie.getMaxAge() > 0) { builder.append(";" + MAX_AGE + "=").append(cookie.getMaxAge()); } if (StringUtils.hasText(cookie.getComment())) { builder.append(";" + COMMENT + "=").append(cookie.getComment()); } if (cookie.getSecure()) { builder.append(";" + SECURE); } if (cookie.isHttpOnly()) { builder.append(";" + HTTP_ONLY); } return builder.toString(); }    }
@Test public void testCookieStringContainsVersion(){ cookie.setVersion(42); String expectedCookieString = "foo=bar;Version=42"; final String cookieString = cookieConverter.getCookieString(cookie); assertEquals(cookieString, expectedCookieString); }
@Test public void testCookieStringContainsPath(){ cookie.setPath("/foo/bar"); String expectedCookieString = "foo=bar;Path=/foo/bar"; final String cookieString = cookieConverter.getCookieString(cookie); assertEquals(cookieString, expectedCookieString); }
@Test public void testCookieStringContainsDomain(){ cookie.setDomain("localhost"); String expectedCookieString = "foo=bar;Domain=localhost"; final String cookieString = cookieConverter.getCookieString(cookie); assertEquals(cookieString, expectedCookieString); }
@Test public void testCookieStringContainsMaxAge(){ cookie.setMaxAge(42); String expectedCookieString = "foo=bar;Max-Age=42"; final String cookieString = cookieConverter.getCookieString(cookie); assertEquals(cookieString, expectedCookieString); }
@Test public void testCookieStringContainsComment(){ cookie.setComment("whatever"); String expectedCookieString = "foo=bar;Comment=whatever"; final String cookieString = cookieConverter.getCookieString(cookie); assertEquals(cookieString, expectedCookieString); }
@Test public void testCookieStringContainsSecure(){ cookie.setSecure(true); String expectedCookieString = "foo=bar;Secure"; final String cookieString = cookieConverter.getCookieString(cookie); assertEquals(cookieString, expectedCookieString); }
@Test public void testCookieStringContainsHttpOnly(){ cookie.setHttpOnly(true); String expectedCookieString = "foo=bar;HttpOnly"; final String cookieString = cookieConverter.getCookieString(cookie); assertEquals(cookieString, expectedCookieString); }