@Test public void mockedLottery() { EmailsReader emailsReader = Mockito.mock(EmailsReader.class); LotteryMachine lotteryMachine = Mockito.mock(LotteryMachine.class); String seedString = "May the Test be with you"; when(emailsReader.get()).thenReturn(Arrays.asList("0", "1", "2", "3", "4")); when(lotteryMachine.setSeed(seedString)).thenReturn(lotteryMachine); Lottery lottery = new Lottery(emailsReader, lotteryMachine, seedString); lottery.run(); Mockito.verify(emailsReader, Mockito.times(1)).get(); Mockito.verify(lotteryMachine, Mockito.times(1)).setSeed(seedString); Mockito.verify(lotteryMachine, Mockito.never()).dispose(); }
void run() { List<String> emails = emailsSource.get(); System.out.println("Emails count: " + emails.size()); List<String> winners = machine.setSeed(seedString).draw(emails); System.out.println("Winners:"); winners.forEach(System.out::println); }
Lottery { void run() { List<String> emails = emailsSource.get(); System.out.println("Emails count: " + emails.size()); List<String> winners = machine.setSeed(seedString).draw(emails); System.out.println("Winners:"); winners.forEach(System.out::println); } }
Lottery { void run() { List<String> emails = emailsSource.get(); System.out.println("Emails count: " + emails.size()); List<String> winners = machine.setSeed(seedString).draw(emails); System.out.println("Winners:"); winners.forEach(System.out::println); } Lottery(Supplier<List<String>> emailsSource,
            LotteryMachine machine,
            String seedString); }
Lottery { void run() { List<String> emails = emailsSource.get(); System.out.println("Emails count: " + emails.size()); List<String> winners = machine.setSeed(seedString).draw(emails); System.out.println("Winners:"); winners.forEach(System.out::println); } Lottery(Supplier<List<String>> emailsSource,
            LotteryMachine machine,
            String seedString);  }
Lottery { void run() { List<String> emails = emailsSource.get(); System.out.println("Emails count: " + emails.size()); List<String> winners = machine.setSeed(seedString).draw(emails); System.out.println("Winners:"); winners.forEach(System.out::println); } Lottery(Supplier<List<String>> emailsSource,
            LotteryMachine machine,
            String seedString);   }