diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java index 4d7dec542d6..f48de0d4bab 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java @@ -153,6 +153,7 @@ public class RequestResultMatchers { /** * Assert the given session attributes do not exist. + * @since 5.2.1 */ public ResultMatcher sessionAttributeDoesNotExist(String... names) { return result -> { diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/SessionAttributeAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/SessionAttributeAssertionTests.java index e65be2e0cb2..e72288fb592 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/SessionAttributeAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/SessionAttributeAssertionTests.java @@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.SessionAttributes; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -68,7 +69,13 @@ public class SessionAttributeAssertionTests { @Test public void testSessionAttributeDoesNotExist() throws Exception { this.mockMvc.perform(get("/")) - .andExpect(request().sessionAttributeDoesNotExist("myAttr1", "myAttr2")); + .andExpect(request().sessionAttributeDoesNotExist("bogus", "enigma")); + + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> + this.mockMvc.perform(get("/")) + .andExpect(request().sessionAttributeDoesNotExist("locale"))) + .withMessage("Session attribute 'locale' exists"); }