### Question:
BankStatementService { public void sendBankStatement(Customer customer) { List<NotificationChannel> preferredChannels = customerRepository.getPreferredNotificationChannels(customer); BankStatement bankStatement = bankStatementRepository.getCustomerBankStatement(customer); preferredChannels.forEach( channel -> { if ("email".equals(channel.getChannelName())) { notificationService.sendByEmail(bankStatement); } else if ("fax".equals(channel.getChannelName())) { notificationService.sendByFax(bankStatement); } } ); } BankStatementService(NotificationService notificationService, CustomerRepository customerRepository, BankStatementRepository bankStatementRepository); void sendBankStatement(Customer customer);  }### Answer:
@Test public void theBankStatementIsSendUsingThePreferredNotificationChannels() throws Exception { NotificationService notificationService = mock(NotificationService.class); BankStatement bankStatement = mock(BankStatement.class); Customer customer = Mockito.mock(Customer.class); CustomerRepository customerRepository = mock(CustomerRepository.class); List<NotificationChannel> preferredNotificationChannels = new ArrayList<>(); NotificationChannel emailChannel = mock(NotificationChannel.class); NotificationChannel faxChannel = mock(NotificationChannel.class); when(emailChannel.getChannelName()).thenReturn("email"); when(faxChannel.getChannelName()).thenReturn("fax"); preferredNotificationChannels.add(emailChannel); preferredNotificationChannels.add(faxChannel); when(customerRepository.getPreferredNotificationChannels(customer)).thenReturn(preferredNotificationChannels); BankStatementRepository bankStatementRepository = mock(BankStatementRepository.class); when(bankStatementRepository.getCustomerBankStatement(customer)).thenReturn(bankStatement); BankStatementService bankStatementService = new BankStatementService(notificationService, customerRepository, bankStatementRepository); bankStatementService.sendBankStatement(customer); verify(customerRepository, times(1)).getPreferredNotificationChannels(customer); verify(notificationService, times(1)).sendByEmail(bankStatement); verify(notificationService, times(1)).sendByFax(bankStatement); }