### Question:
SimplePageController { @RequestMapping(value = "/pages/{pagePathName}", method = RequestMethod.GET) public ModelAndView showPage(@PathVariable(PAGE_PATH_NAME) String pagePathName) { checkPermissionToCreateAndEditPage(); SimplePage page = null; try { page = simplePageService.getPageByPathName(pagePathName); } finally { if (page != null) { SimplePageDto pageDto = new SimplePageDto(page); return new ModelAndView("simplePage") .addObject(PAGE_DTO, pageDto) .addObject("simplePage", page); } else { return new ModelAndView(PAGE_NOT_FOUND) .addObject(PAGE_PATH_NAME, pagePathName) .addObject(CURRENT_USER_PARAMETER, userService.getCurrentUser()); } } } @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 showPageTest() throws NotFoundException { SimplePage simplePage = new SimplePage(NAME, CONTENT, PATH_NAME); when(simplePageService.getPageByPathName(PATH_NAME)).thenReturn(simplePage); ModelAndView modelAndView = controller.showPage(PATH_NAME); verify(simplePageService).getPageByPathName(PATH_NAME); assertViewName(modelAndView, "simplePage"); SimplePageDto actualSimplePage = assertAndReturnModelAttributeOfType(modelAndView, "simplePageDto", SimplePageDto.class); assertEqualsSimplePageAndSimplePageDto(actualSimplePage, simplePage); }
@Test public void showNotExistingPageTest() throws NotFoundException { JCUser user = new JCUser("username", "email", "password"); when(simplePageService.getPageByPathName(PATH_NAME)).thenThrow(new NotFoundException()); when(userService.getCurrentUser()).thenReturn(user); ModelAndView modelAndView = controller.showPage(PATH_NAME); assertViewName(modelAndView, SimplePageController.PAGE_NOT_FOUND); assertModelAttributeValue(modelAndView, SimplePageController.PAGE_PATH_NAME, PATH_NAME); assertModelAttributeValue(modelAndView, SimplePageController.CURRENT_USER_PARAMETER, user); }