@Test public void theUserNotificationChannelsAreAddedAsPartOfTheModel() throws Exception { Model model = mock(Model.class); String username = "foo"; List<NotificationType> preferredChannels = new ArrayList<>(); Customer customer = new Customer(); customer.setPreferredNotificationChannels(preferredChannels); when(customerRepository.findByUsername(username)).thenReturn(Optional.of(customer)); User loggedInUser = mock(User.class); when(loggedInUser.getUsername()).thenReturn(username); manageChannels.manageNotificationChannels(model, loggedInUser); verify(model, times(1)).addAttribute("preferredChannels", preferredChannels); }
@RequestMapping(value = "/notifications", method = RequestMethod.GET) public String manageNotificationChannels(Model model, @AuthenticationPrincipal User loggedInUser) { Customer customer = customerRepository.findByUsername(loggedInUser.getUsername()).get(); model.addAttribute("preferredChannels", customer.getPreferredNotificationChannels()); return "customers/notification-channels"; }
ManageChannels { @RequestMapping(value = "/notifications", method = RequestMethod.GET) public String manageNotificationChannels(Model model, @AuthenticationPrincipal User loggedInUser) { Customer customer = customerRepository.findByUsername(loggedInUser.getUsername()).get(); model.addAttribute("preferredChannels", customer.getPreferredNotificationChannels()); return "customers/notification-channels"; } }
ManageChannels { @RequestMapping(value = "/notifications", method = RequestMethod.GET) public String manageNotificationChannels(Model model, @AuthenticationPrincipal User loggedInUser) { Customer customer = customerRepository.findByUsername(loggedInUser.getUsername()).get(); model.addAttribute("preferredChannels", customer.getPreferredNotificationChannels()); return "customers/notification-channels"; } @Autowired  ManageChannels(CustomerRepository customerRepository); }
ManageChannels { @RequestMapping(value = "/notifications", method = RequestMethod.GET) public String manageNotificationChannels(Model model, @AuthenticationPrincipal User loggedInUser) { Customer customer = customerRepository.findByUsername(loggedInUser.getUsername()).get(); model.addAttribute("preferredChannels", customer.getPreferredNotificationChannels()); return "customers/notification-channels"; } @Autowired  ManageChannels(CustomerRepository customerRepository); @RequestMapping(value = "/notifications", method = RequestMethod.GET) String manageNotificationChannels(Model model, @AuthenticationPrincipal User loggedInUser); }
ManageChannels { @RequestMapping(value = "/notifications", method = RequestMethod.GET) public String manageNotificationChannels(Model model, @AuthenticationPrincipal User loggedInUser) { Customer customer = customerRepository.findByUsername(loggedInUser.getUsername()).get(); model.addAttribute("preferredChannels", customer.getPreferredNotificationChannels()); return "customers/notification-channels"; } @Autowired  ManageChannels(CustomerRepository customerRepository); @RequestMapping(value = "/notifications", method = RequestMethod.GET) String manageNotificationChannels(Model model, @AuthenticationPrincipal User loggedInUser);  }