Polish contribution

See gh-23756
This commit is contained in:
Sam Brannen 2019-10-23 12:27:51 +02:00
parent e73344fc71
commit 82f64f6a8d
2 changed files with 9 additions and 1 deletions

View File

@ -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 -> {

View File

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