diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java index bafe7e6260f..32df6ac00c2 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java @@ -199,12 +199,13 @@ public class CookieResultMatchers { } /** - * Assert whether the cookie must be httpOnly. + * Assert whether the cookie must be HTTP only. + * @since 4.3.9 */ public ResultMatcher httpOnly(final String name, final boolean httpOnly) { return result -> { Cookie cookie = result.getResponse().getCookie(name); - assertEquals("Response cookie httpOnly", httpOnly, cookie.isHttpOnly()); + assertEquals("Response cookie '" + name + "' httpOnly", httpOnly, cookie.isHttpOnly()); }; } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/CookieAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/CookieAssertionTests.java index d68325e00f9..a315482244b 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/CookieAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/CookieAssertionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; * Examples of expectations on response cookies values. * * @author Rossen Stoyanchev + * @author Nikola Yovchev */ public class CookieAssertionTests { @@ -47,6 +48,7 @@ public class CookieAssertionTests { CookieLocaleResolver localeResolver = new CookieLocaleResolver(); localeResolver.setCookieDomain("domain"); localeResolver.setCookieHttpOnly(true); + this.mockMvc = standaloneSetup(new SimpleController()) .addInterceptors(new LocaleChangeInterceptor()) .setLocaleResolver(localeResolver) @@ -55,6 +57,7 @@ public class CookieAssertionTests { .build(); } + @Test public void testExists() throws Exception { this.mockMvc.perform(get("/")).andExpect(cookie().exists(COOKIE_NAME)); @@ -106,6 +109,7 @@ public class CookieAssertionTests { this.mockMvc.perform(get("/")).andExpect(cookie().httpOnly(COOKIE_NAME, true)); } + @Controller private static class SimpleController { @@ -114,4 +118,5 @@ public class CookieAssertionTests { return "home"; } } + }