### Question:
PersonController extends AbstractController { @RequestMapping(value = "/person/edit/{id}", method = RequestMethod.GET) public String showEditPersonForm(@PathVariable("id") Long id, Model model, RedirectAttributes attributes) { LOGGER.debug("Rendering edit person form for person with id: " + id); Person person = personService.findById(id); if (person == null) { LOGGER.debug("No person found with id: " + id); addErrorMessage(attributes, ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND); return createRedirectViewPath(REQUEST_MAPPING_LIST); } model.addAttribute(MODEL_ATTIRUTE_PERSON, constructFormObject(person)); return PERSON_EDIT_FORM_VIEW; }  @RequestMapping(value="/person/count", method = RequestMethod.POST) @ResponseBody Long count(@RequestBody SearchDTO searchCriteria); @RequestMapping(value = "/person/delete/{id}", method = RequestMethod.GET) String delete(@PathVariable("id") Long id, RedirectAttributes attributes); @RequestMapping(value = "/person/search/page", method = RequestMethod.POST) @ResponseBody List<PersonDTO> search(@RequestBody SearchDTO searchCriteria); @RequestMapping(value = "/person/create", method = RequestMethod.GET) String showCreatePersonForm(Model model); @RequestMapping(value = "/person/create", method = RequestMethod.POST) String submitCreatePersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO created, BindingResult bindingResult, RedirectAttributes attributes); @RequestMapping(value = "/person/edit/{id}", method = RequestMethod.GET) String showEditPersonForm(@PathVariable("id") Long id, Model model, RedirectAttributes attributes); @RequestMapping(value = "/person/edit", method = RequestMethod.POST) String submitEditPersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO updated, BindingResult bindingResult, RedirectAttributes attributes); @RequestMapping(value = REQUEST_MAPPING_LIST, method = RequestMethod.GET) String showList(Model model); @RequestMapping(value = "/person/search", method=RequestMethod.POST) String showSearchResultPage(@ModelAttribute(MODEL_ATTRIBUTE_SEARCH_CRITERIA) SearchDTO searchCriteria, Model model);  }### Answer:
@Test public void showEditPersonForm() { Person person = PersonTestUtil.createModelObject(PERSON_ID, FIRST_NAME, LAST_NAME); when(personServiceMock.findById(PERSON_ID)).thenReturn(person); Model model = new BindingAwareModelMap(); RedirectAttributes attributes = new RedirectAttributesModelMap(); String view = controller.showEditPersonForm(PERSON_ID, model, attributes); verify(personServiceMock, times(1)).findById(PERSON_ID); verifyNoMoreInteractions(personServiceMock); assertEquals(PersonController.PERSON_EDIT_FORM_VIEW, view); PersonDTO formObject = (PersonDTO) model.asMap().get(PersonController.MODEL_ATTIRUTE_PERSON); assertNotNull(formObject); assertEquals(person.getId(), formObject.getId()); assertEquals(person.getFirstName(), formObject.getFirstName()); assertEquals(person.getLastName(), formObject.getLastName()); }
@Test public void showEditPersonFormWhenPersonIsNotFound() { when(personServiceMock.findById(PERSON_ID)).thenReturn(null); initMessageSourceForErrorMessage(PersonController.ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND); Model model = new BindingAwareModelMap(); RedirectAttributes attributes = new RedirectAttributesModelMap(); String view = controller.showEditPersonForm(PERSON_ID, model, attributes); verify(personServiceMock, times(1)).findById(PERSON_ID); verifyNoMoreInteractions(personServiceMock); String expectedView = createExpectedRedirectViewPath(PersonController.REQUEST_MAPPING_LIST); assertEquals(expectedView, view); assertErrorMessage(attributes, PersonController.ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND); }