UserFormController extends BaseFormController { @ModelAttribute @RequestMapping(method = RequestMethod.GET) protected User getUser(HttpServletRequest request) { String userId = request.getParameter("id"); if ((userId != null) && !userId.equals("")) { return userManager.getUser(userId); } else { return new User(); } }  @RequestMapping(method = RequestMethod.POST) String onSubmit(User user, BindingResult result, HttpServletRequest request);  }
@Test public void testEdit() throws Exception { log.debug("testing edit..."); when(userManager.getUser("1")).thenReturn(user); mockMvc.perform(get("/userform").param("id", "1")) .andExpect(status().isOk()) .andExpect(model().attributeExists("user")) .andExpect(model().attribute("user", hasProperty("firstName", is("Matt")))) .andExpect(view().name("userform")); verify(userManager, times(1)).getUser("1"); }