模拟 mvc 检查会话中不存在对象
mock mvc check that object doesn't exist in session
我有以下测试
@Test
public void exitTest() throws Exception {
mvc.perform(MockMvcRequestBuilders
.get("/exit")
.sessionAttr(CardController.CREDIT_CARD, mock(CreditCard.class))
.accept(MediaType.TEXT_HTML))
.andExpect(status().is(302))
.andExpect(view().name("redirect:/")).andExpect(MockMvcResultMatchers.model().attributeDoesNotExist(CardController.CREDIT_CARD));
}
我想检查 CardController.CREDIT_CARD
在请求后会话中不存在。
我的代码正确吗?
.get("/exit")
.sessionAttr(CardController.CREDIT_CARD, mock(CreditCard.class))
.accept(MediaType.TEXT_HTML))
.andExpect(status().is(302))
.andExpect(view().name("redirect:/"))
.andReturn()
.getRequest()
.getSession();
assertNull(session.getAttribute(CardController.CREDIT_CARD));
我有以下测试
@Test
public void exitTest() throws Exception {
mvc.perform(MockMvcRequestBuilders
.get("/exit")
.sessionAttr(CardController.CREDIT_CARD, mock(CreditCard.class))
.accept(MediaType.TEXT_HTML))
.andExpect(status().is(302))
.andExpect(view().name("redirect:/")).andExpect(MockMvcResultMatchers.model().attributeDoesNotExist(CardController.CREDIT_CARD));
}
我想检查 CardController.CREDIT_CARD
在请求后会话中不存在。
我的代码正确吗?
.get("/exit")
.sessionAttr(CardController.CREDIT_CARD, mock(CreditCard.class))
.accept(MediaType.TEXT_HTML))
.andExpect(status().is(302))
.andExpect(view().name("redirect:/"))
.andReturn()
.getRequest()
.getSession();
assertNull(session.getAttribute(CardController.CREDIT_CARD));