Browse Source

Polish contribution

See gh-23756
pull/23931/head
Sam Brannen 6 years ago
parent
commit
82f64f6a8d
  1. 1
      spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java
  2. 9
      spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/SessionAttributeAssertionTests.java

1
spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java

@ -153,6 +153,7 @@ public class RequestResultMatchers { @@ -153,6 +153,7 @@ public class RequestResultMatchers {
/**
* Assert the given session attributes do not exist.
* @since 5.2.1
*/
public <T> ResultMatcher sessionAttributeDoesNotExist(String... names) {
return result -> {

9
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; @@ -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 { @@ -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");
}

Loading…
Cancel
Save