@Test public void theNotificationChannelsAreSavedByTheDataRepository() throws Exception { NotificationType channelOne = NotificationType.EMAIL; NotificationType channelTwo = NotificationType.FAX; CustomerRepository customerRepository = Mockito.mock(CustomerRepository.class); CustomerService customerService = new CustomerService(customerRepository); List<NotificationType> notificationChannels = new ArrayList(); notificationChannels.add(channelOne); notificationChannels.add(channelTwo); Customer customer = Mockito.mock(Customer.class); customerService.savePreferredNotificationChannels(customer, notificationChannels); Mockito.verify(customerRepository, Mockito.times(1)).savePreferredChannel(customer, channelOne); Mockito.verify(customerRepository, Mockito.times(1)).savePreferredChannel(customer, channelTwo); }
public void savePreferredNotificationChannels(Customer customer, List<NotificationType> notificationChannels) { notificationChannels.forEach(notificationChannel -> customerRepository.savePreferredChannel(customer, notificationChannel)); }
CustomerService { public void savePreferredNotificationChannels(Customer customer, List<NotificationType> notificationChannels) { notificationChannels.forEach(notificationChannel -> customerRepository.savePreferredChannel(customer, notificationChannel)); } }
CustomerService { public void savePreferredNotificationChannels(Customer customer, List<NotificationType> notificationChannels) { notificationChannels.forEach(notificationChannel -> customerRepository.savePreferredChannel(customer, notificationChannel)); } CustomerService(CustomerRepository customerRepository); }
CustomerService { public void savePreferredNotificationChannels(Customer customer, List<NotificationType> notificationChannels) { notificationChannels.forEach(notificationChannel -> customerRepository.savePreferredChannel(customer, notificationChannel)); } CustomerService(CustomerRepository customerRepository); void savePreferredNotificationChannels(Customer customer, List<NotificationType> notificationChannels); }
CustomerService { public void savePreferredNotificationChannels(Customer customer, List<NotificationType> notificationChannels) { notificationChannels.forEach(notificationChannel -> customerRepository.savePreferredChannel(customer, notificationChannel)); } CustomerService(CustomerRepository customerRepository); void savePreferredNotificationChannels(Customer customer, List<NotificationType> notificationChannels);  }