EncounterController { @GetMapping("/encounters") public String getEncounters(final Model model, @RequestParam(name = "type", required = false) final String type) { boolean confirmable = !StringUtils.equals(userService.getUser().getUsername(), "anonymousUser") && !StringUtils.equals("own", type); List<Encounter> encounters = encounterService.getEncounters(type); model.addAttribute("encounters", encounters); model.addAttribute("confirmable", confirmable); return "encounters"; }  @GetMapping("/encounters") String getEncounters(final Model model, @RequestParam(name = "type", required = false) final String type); @GetMapping("/encounter/create") @PreAuthorize("hasAnyRole('USER','ADMIN')") String createEncounter(@ModelAttribute final Encounter encounter); @PostMapping("/encounter/create") @PreAuthorize("hasAnyRole('USER','ADMIN')") String saveEncounter(@Valid final Encounter encounter, final Model model, final BindingResult result); @PostMapping("/encounter/delete") @PreAuthorize("hasAnyRole('USER','ADMIN')") ModelAndView deleteEncounter(final long encounterId); @GetMapping("/encounter/{id}") @PreAuthorize("hasAnyRole('USER','ADMIN')") String encounterById(@PathVariable("id") final long encounterId, final Model model,
                                final RedirectAttributes redirectAttributes);  }
@Test @WithMockUser(username = "arthur@dent.com", password = "arthur@dent.com", roles = "USER") public void listEncounters() throws Exception { given(encounterService.getEncounters(anyString())).willReturn(twoTestEncounters()); given(userService.getUser()).willReturn(new User("Test")); mvc.perform(get("/encounters")) .andExpect(status().isOk()) .andExpect(view().name("encounters")) .andExpect(model().attributeExists("encounters")) .andExpect(model().attribute("encounters", hasSize(2))); }