### Question:
BalanceService { public void sendBalance(Customer customer) { List<NotificationType> preferredChannels = customer.getPreferredNotificationChannels(); Balance balance = balanceRepository.findByCustomer(customer); preferredChannels.forEach( channel -> notificationChannelFactory.getNotificationChannel(channel).send(balance) ); } BalanceService(NotificationChannelFactory notificationChannelFactory, BalanceRepository balanceRepository); void sendBalance(Customer customer);  }### Answer:
@Test public void theBalanceIsSendUsingThePreferredNotificationChannels() throws Exception { Balance balance = mock(Balance.class); Customer customer = mock(Customer.class); when(customer.getPreferredNotificationChannels()).thenReturn(getListOfNotificationTypes()); BalanceRepository balanceRepository = mock(BalanceRepository.class); when(balanceRepository.findByCustomer(customer)).thenReturn(balance); BalanceService balanceService = new BalanceService(notificationChannelsFactory, balanceRepository); balanceService.sendBalance(customer); verify(emailChannel, times(1)).send(balance); verify(faxChannel, times(1)).send(balance); }