import static org.hamcrest.Matchers.*; nullValue .andExpect(model().attribute("todo", hasProperty("id", nullValue()))) isEmptyOrNullString is hasSize allOf hasItem import static org.mockito.Mockito.*; verifyZeroInteractions when times verifyNoMoreInteractions ------------------------------------------------------------------------- org.springframework.test.web.servlet.request contentType .contentType(MediaType.APPLICATION_FORM_URLENCODED) content .content(TestUtil.convertObjectToFormUrlEncodedBytes(formObject)) sessionAttr .sessionAttr("todo", formObject) org.springframework.test.web.servlet.MockMvc perform(RequestBuilder requestBuilder) import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; get() .perform(get(“/”)) .perform(get("/todo/{id}", 1L)) post() .perform(post("/todo/add") -------------------------------------------------------------- org.springframework.test.web.servlet.ResultActions.andExpect(ResultMatcher matcher) import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.* status() .andExpect(status().isOk()) .andExpect(status().isNotFound()) view() .andExpect(view().name("todo/list")) .andExpect(view().name("redirect:todo/{id}")) forwardedUrl() .andExpect(forwardedUrl("/WEB-INF/jsp/todo/list.jsp")) redirectedUrl() .andExpect(redirectedUrl("/todo/1")) model() .andExpect(model().attribute("todos", hasSize(2))) .andExpect(model().attribute("todos", hasItem( allOf( hasProperty("id", is(1L)), hasProperty("description", is("Lorem ipsum")), hasProperty("title", is("Foo")) ) ))) .andExpect(model().attribute("todo", hasProperty("id", is(1L)))) .andExpect(model().attributeHasFieldErrors("todo", "title")) flash() .andExpect(flash().attribute("feedbackMessage", is("Todo entry: title was added."))); org.springframework.test.web.servlet.ResultActions.andDo(ResultHandler handler) import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; print()