### Question:
MessagesController extends AbstractController { @RequestMapping("/messages") public ModelAndView showAllMessagesPage(final Model model) { model.addAttribute("referralMessages", messageService.getMessagesByType(MessageType.REFERRAL_SHARE)); return new ModelAndView("messages/index"); } MessagesController(final MessageService messageService); @RequestMapping("/messages") ModelAndView showAllMessagesPage(final Model model); @RequestMapping("/messages/{type}") ModelAndView showMessagesOfTypePage(final Model model, @PathVariable String type); @RequestMapping("/messages/{type}/add") ModelAndView showAddMessageToTypePage(final Model model, @PathVariable String type); @RequestMapping("/messages/{type}/{name}/edit") ModelAndView showEditPage(final Model model, @PathVariable String type, @PathVariable String name); @PostMapping("/messages/{type}/add") ModelAndView add(WebRequest request, @PathVariable String type, RedirectAttributes redirectAttributes); @PostMapping("/messages/{type}/{name}/edit") ModelAndView update(WebRequest request, @PathVariable String type, @PathVariable String name, RedirectAttributes redirectAttributes); @PostMapping("/messages/{type}/{name}/delete") ModelAndView delete(final Model model, @PathVariable String type, @PathVariable String name, RedirectAttributes redirectAttributes);  }### Answer:
@Test public void showAllMessagesPage() throws Exception { MessageDto messageDto1 = mock(MessageDto.class); MessageDto messageDto2 = mock(MessageDto.class); MessageDto messageDto3 = mock(MessageDto.class); List<MessageDto> messages = Arrays.asList(messageDto1, messageDto2, messageDto3); when(messageService.getMessagesByType(MessageType.REFERRAL_SHARE)).thenReturn(messages); this.mockMvc.perform(get("/messages")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.model().attribute("referralMessages", messages)) .andExpect(MockMvcResultMatchers.view().name("messages/index")); }