### Question:
EditSpannerController implements ApplicationEventPublisherAware { @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.GET) public ModelAndView displayPage(@RequestParam Long id) throws SpannerNotFoundException { Spanner spanner = spannersService.findOne(id); if (spanner == null) { throw new SpannerNotFoundException(id); } SpannerForm initializedForm = new SpannerForm(spanner); return new ModelAndView(VIEW_EDIT_SPANNER, MODEL_SPANNER, initializedForm); }  @Override void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher); @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.GET) ModelAndView displayPage(@RequestParam Long id); @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.POST) ModelAndView updateSpanner(@Valid @ModelAttribute(MODEL_SPANNER) SpannerForm formData, BindingResult validationResult); static final String VIEW_EDIT_SPANNER; static final String VIEW_UPDATE_SUCCESS; static final String VIEW_VALIDATION_ERRORS; static final String MODEL_SPANNER; static final String CONTROLLER_URL; }### Answer:
@Test public void testDisplayPage() throws Exception { when(spannersService.findOne(SPANNER_ID)).thenReturn(SPANNER); ModelAndView response = controller.displayPage(SPANNER_ID); assertNotNull("no response", response); assertEquals("view", VIEW_EDIT_SPANNER, response.getViewName()); SpannerForm spannerFormData = (SpannerForm)response.getModelMap().get(MODEL_SPANNER); assertSpannerEquals(SPANNER, spannerFormData); }
@Test public void testSpannerNotFound() { when(spannersService.findOne(SPANNER_ID)).thenReturn(null); try { controller.displayPage(SPANNER_ID); fail("Expected: SpannerNotFoundException"); } catch(SpannerNotFoundException notFoundEx) { assertEquals("Exception spanner id", SPANNER_ID, notFoundEx.getSpannerId()); } }