我有以下测试
@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
。
我的代码是否正确?
答案 0 :(得分:2)
.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));