parent
e73344fc71
commit
82f64f6a8d
|
|
@ -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 -> {
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue