### Question:
SimplePageController { @RequestMapping(value = "/pages/{pagePathName}/edit", method = RequestMethod.POST) public ModelAndView update(@Valid @ModelAttribute SimplePageDto simplePageDto, BindingResult result, @PathVariable(PAGE_PATH_NAME) String pagePathName) throws NotFoundException { if (result.hasErrors()) { return new ModelAndView("simplePageEditor") .addObject(PAGE_PATH_NAME, pagePathName); } SimplePageInfoContainer simplePageInfoContainer = simplePageDto.getSimplePageInfoContainer(); simplePageService.updatePage(simplePageInfoContainer); return new ModelAndView("redirect:/pages/" + pagePathName); } @Autowired  SimplePageController(SimplePageService simplePageService, UserService userService); @InitBinder void initBinder(WebDataBinder binder); @RequestMapping(value = "/pages/{pagePathName}", method = RequestMethod.GET) ModelAndView showPage(@PathVariable(PAGE_PATH_NAME) String pagePathName); @RequestMapping(value = "/pages/{pagePathName}/edit", method = RequestMethod.GET) ModelAndView showEditPage(@PathVariable(PAGE_PATH_NAME) String pagePathName); @RequestMapping(value = "/pages/{pagePathName}/edit", method = RequestMethod.POST) ModelAndView update(@Valid @ModelAttribute SimplePageDto simplePageDto,
                               BindingResult result,
                               @PathVariable(PAGE_PATH_NAME) String pagePathName); @RequestMapping(value = "/pages/create/{pagePathName}", method = RequestMethod.GET) ModelAndView createPage(@PathVariable(PAGE_PATH_NAME) String pagePathName);  }### Answer:
@Test public void updatePageTest() throws NotFoundException { SimplePageDto pageDto = new SimplePageDto(); pageDto.setId(PAGE_ID); pageDto.setNameText(NAME); pageDto.setContentText(CONTENT); pageDto.setPathName(PATH_NAME); BindingResult bindingResult = new BeanPropertyBindingResult(pageDto, "simplePageDto"); ModelAndView mav = controller.update(pageDto, bindingResult, PATH_NAME); assertViewName(mav, "redirect:/pages/" + PATH_NAME); verify(simplePageService).updatePage(any(SimplePageInfoContainer.class)); }
@Test public void updatePageWithErrorTest() throws NotFoundException { SimplePageDto pageDto = new SimplePageDto(); pageDto.setId(PAGE_ID); pageDto.setNameText(NAME); pageDto.setContentText(CONTENT); pageDto.setPathName(PATH_NAME); BeanPropertyBindingResult resultWithErrors = mock(BeanPropertyBindingResult.class); when(resultWithErrors.hasErrors()).thenReturn(true); ModelAndView mav = controller.update(pageDto, resultWithErrors, PATH_NAME); assertViewName(mav, "simplePageEditor"); verify(simplePageService, never()).updatePage(any(SimplePageInfoContainer.class)); }