### Question:
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);   }### Answer:
@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(); }
@Test public void mockedWithSpy() { EmailsReader emailsReader = Mockito.mock(EmailsReader.class); LotteryMachine lotteryMachine = new LotteryMachine(5); LotteryMachine spyMachine = Mockito.spy(lotteryMachine); String seedString = "Test"; long longSeed = 1L; when(spyMachine.getSeed()).thenReturn(longSeed); Lottery lottery = new Lottery(emailsReader, spyMachine, seedString); lottery.run(); Assert.assertEquals(LotteryMachine.DEFAULT_SEED, lotteryMachine.getSeed()); Assert.assertEquals(longSeed, spyMachine.getSeed()); }