### Question:
PrivateMessageController { @RequestMapping(value = "/pm/drafts/{pmId}/edit", method = RequestMethod.GET) public ModelAndView editDraftPage(@PathVariable(PM_ID) Long id) throws NotFoundException { PrivateMessage pm = pmService.get(id); if (!pm.getStatus().equals(PrivateMessageStatus.DRAFT)) { throw new NotFoundException("Edit allowed only for draft messages."); } return new ModelAndView(PM_FORM).addObject(DTO, PrivateMessageDto.getFullPmDtoFor(pm)); } @Autowired  PrivateMessageController(PrivateMessageService pmService, BBCodeService bbCodeService,
                                    UserService userService); @InitBinder void initBinder(WebDataBinder binder); @RequestMapping(value = {"/inbox","/pm"}, method = RequestMethod.GET) ModelAndView inboxPage(@RequestParam(value = "page", defaultValue = "1", required = false) String page); @RequestMapping(value = "/outbox", method = RequestMethod.GET) ModelAndView outboxPage(@RequestParam(value = "page", defaultValue = "1", required = false) String page); @RequestMapping(value = "/drafts", method = RequestMethod.GET) ModelAndView draftsPage(@RequestParam(value = "page", defaultValue = "1", required = false) String page); @RequestMapping(value = "/pm/new", method = RequestMethod.GET) ModelAndView newPmPage(@RequestParam(value = "recipientId", required = false) Long recipientId); @RequestMapping(value = "/reply/{pmId}", method = RequestMethod.GET) ModelAndView replyPage(@PathVariable(PM_ID) Long id); @RequestMapping(value = "/quote/{pmId}", method = RequestMethod.GET) ModelAndView quotePage(@PathVariable(PM_ID) Long id); @RequestMapping(value = "/pm/new", method = RequestMethod.POST) ModelAndView sendMessage(@Valid @ModelAttribute PrivateMessageDto pmDto,
                                    BindingResult result); @RequestMapping(value = {"/pm/inbox/{pmId}", "/pm/outbox/{pmId}"}, method = RequestMethod.GET) ModelAndView showPmPage(@PathVariable(PM_ID) Long id); @RequestMapping(value = "/pm/drafts/{pmId}/edit", method = RequestMethod.GET) ModelAndView editDraftPage(@PathVariable(PM_ID) Long id); @RequestMapping(value = "/pm/save", method = {RequestMethod.POST, RequestMethod.GET}) ModelAndView saveDraft(@Valid @ModelAttribute("privateMessageDto") PrivateMessageDraftDto pmDto, BindingResult result); @RequestMapping(value = "/pm", method = {RequestMethod.DELETE}) String deleteMessages(@RequestParam(PM_IDENTIFIERS) List<Long> ids); static final String PM_IDENTIFIERS; }### Answer:
@Test public void editDraftPage() throws NotFoundException { PrivateMessage pm = getPrivateMessage(); pm.setId(PM_ID); pm.setStatus(PrivateMessageStatus.DRAFT); when(pmService.get(PM_ID)).thenReturn(pm); ModelAndView mav = controller.editDraftPage(PM_ID); verify(pmService).get(PM_ID); assertViewName(mav, "pm/pmForm"); PrivateMessageDto dto = assertAndReturnModelAttributeOfType(mav, "privateMessageDto", PrivateMessageDto.class); assertEquals(dto.getId(), PM_ID); }
@Test(expectedExceptions = NotFoundException.class) public void editDraftPageNotDraft() throws NotFoundException { PrivateMessage pm = getPrivateMessage(); when(pmService.get(PM_ID)).thenReturn(pm); controller.editDraftPage(PM_ID); }