public static void addCookie( HttpServletRequest request, HttpServletResponse response, String name, String value, Integer maxAge, String path, String domain, Boolean secure) { Assert.notNull(request); Assert.notNull(response); Assert.hasText(name); try { name = URLEncoder.encode(name, "UTF-8"); value = URLEncoder.encode(value, "UTF-8"); Cookie cookie = new Cookie(name, value); if (maxAge != null) { cookie.setMaxAge(maxAge); } if (ValidateUtils.isValid(path)) { cookie.setPath(path); } if (ValidateUtils.isValid(domain)) { cookie.setDomain(domain); } if (secure != null) { cookie.setSecure(secure); } response.addCookie(cookie); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
public static void removeCookie( HttpServletRequest request, HttpServletResponse response, String name, String path, String domain) { Assert.notNull(request); Assert.notNull(response); Assert.hasText(name); try { name = URLEncoder.encode(name, "UTF-8"); Cookie cookie = new Cookie(name, null); cookie.setMaxAge(0); if (ValidateUtils.isValid(path)) { cookie.setPath(path); } if (ValidateUtils.isValid(domain)) { cookie.setDomain(domain); } response.addCookie(cookie); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
@Test(expected = Exception.class) public void test_validate_nulls() { ValidateUtils.notNulls(null, null); }
@Test public void test() { ValidateUtils.notNulls(new Object()); }