### Question:
DisplaySpannersController { @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.GET) public String displaySpanners(ModelMap model) { Collection<Spanner> spanners = spannersService.findAll(); String greeting = timeOfDayGreeting(); model.addAttribute(MODEL_ATTRIBUTE_SPANNERS, spanners); model.addAttribute(MODEL_ATTRIBUTE_GREETING, greeting); return VIEW_DISPLAY_SPANNERS; }  @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.GET) String displaySpanners(ModelMap model); @RequestMapping(value = "/deleteSpanner", method = RequestMethod.GET) String deleteSpanner(@RequestParam Long id, ModelMap model);  }### Answer:
@Test public void testDisplaySpanners() { when(spannersService.findAll()).thenReturn(SPANNERS); ModelMap model = new ModelMap(); String view = controller.displaySpanners(model); assertEquals("view name", VIEW_DISPLAY_SPANNERS, view); @SuppressWarnings("unchecked") List<Spanner> spannersInModel = (List<Spanner>)model.get(MODEL_ATTRIBUTE_SPANNERS); assertNotNull(MODEL_ATTRIBUTE_SPANNERS + " is null", spannersInModel); assertEquals(SPANNERS, spannersInModel); }
@Test public void testTimeOfDayGreetingMorning() { when(currentTime.get()).thenReturn(LocalTime.of(9,0)); ModelMap model = new ModelMap(); controller.displaySpanners(model); String greeting = (String)model.get(MODEL_ATTRIBUTE_GREETING); assertEquals(GREETING_MORNING, greeting); }
@Test public void testTimeOfDayGreetingAfternoon() { when(currentTime.get()).thenReturn(LocalTime.of(14,0)); ModelMap model = new ModelMap(); controller.displaySpanners(model); String greeting = (String)model.get(MODEL_ATTRIBUTE_GREETING); assertEquals(GREETING_AFTERNOON, greeting); }
@Test public void testTimeOfDayGreetingEvening() { when(currentTime.get()).thenReturn(LocalTime.of(20,0)); ModelMap model = new ModelMap(); controller.displaySpanners(model); String greeting = (String)model.get(MODEL_ATTRIBUTE_GREETING); assertEquals(GREETING_EVENING, greeting); }