@Test public void testRegisterUser() throws Exception { mockMvc.perform(post("/register").accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(redirectedUrl("register?registered=true")) .andExpect(model().attributeExists("aUser")) .andExpect(status().isFound()); verify(userService, times(1)) .saveUser(any(UserEntity.class)); verifyNoMoreInteractions(userService); }
@RequestMapping(method = RequestMethod.POST) public String registerUser( @Valid @ModelAttribute("aUser") UserEntity userEntity, BindingResult results) { if (results.hasErrors()) { return "register"; } userService.saveUser(userEntity); return "redirect:register?registered=true"; }
RegisterController { @RequestMapping(method = RequestMethod.POST) public String registerUser( @Valid @ModelAttribute("aUser") UserEntity userEntity, BindingResult results) { if (results.hasErrors()) { return "register"; } userService.saveUser(userEntity); return "redirect:register?registered=true"; } }
RegisterController { @RequestMapping(method = RequestMethod.POST) public String registerUser( @Valid @ModelAttribute("aUser") UserEntity userEntity, BindingResult results) { if (results.hasErrors()) { return "register"; } userService.saveUser(userEntity); return "redirect:register?registered=true"; } @Autowired  RegisterController(IUserService userService); }
RegisterController { @RequestMapping(method = RequestMethod.POST) public String registerUser( @Valid @ModelAttribute("aUser") UserEntity userEntity, BindingResult results) { if (results.hasErrors()) { return "register"; } userService.saveUser(userEntity); return "redirect:register?registered=true"; } @Autowired  RegisterController(IUserService userService); @RequestMapping String showRegisterForm(Model model); @RequestMapping(method = RequestMethod.POST) String registerUser(
            @Valid @ModelAttribute("aUser") UserEntity userEntity,
            BindingResult results); @RequestMapping("is-available") @ResponseBody String available(@RequestParam String username); }
RegisterController { @RequestMapping(method = RequestMethod.POST) public String registerUser( @Valid @ModelAttribute("aUser") UserEntity userEntity, BindingResult results) { if (results.hasErrors()) { return "register"; } userService.saveUser(userEntity); return "redirect:register?registered=true"; } @Autowired  RegisterController(IUserService userService); @RequestMapping String showRegisterForm(Model model); @RequestMapping(method = RequestMethod.POST) String registerUser(
            @Valid @ModelAttribute("aUser") UserEntity userEntity,
            BindingResult results); @RequestMapping("is-available") @ResponseBody String available(@RequestParam String username);  }