### Question:
TicketsDecayReminderJob { @Schedule(hour = "*", minute = "*/15", second = "*", persistent = false) public void execute() { if (runJobs.get()) { activityLogController.saveActivityLog(new ObjectId(), ActivityType.JOB_TICKET_DECAY, "text", "Starting TicketsDecayReminder job..."); ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Europe/Paris")); List<Lottery> closingLottery = lotteryManager.getLotteries().stream().filter(lottery -> lottery.getNextDrawing(null, null).isBefore(now.plusMinutes(MINUTES_BEFORE_DEADLINE_REMINDER))).collect(Collectors.toList()); if (closingLottery.isEmpty()) { return; } try { List<ShoppingCart> shoppingCarts = shoppingCartRepository.getAllShoppingsCartWithTickets(); for (ShoppingCart shoppingCart : shoppingCarts) { List<Ticket> tickets = shoppingCart.getTicketList().stream().filter(t -> t.getLottery().getNextDrawing(null, DrawingType.fromType(t.getDrawingType())).isBefore(t.getStartingDate().plusMinutes(MINUTES_BEFORE_DEADLINE_REMINDER))).collect(Collectors.toList()); if (! tickets.isEmpty()) { Player player = userRepository.findById(shoppingCart.getPlayerId()); mailController.sendTicketsDecayReminderMail(player); } } } catch (Exception ex) { logger.severe("Error occurred while executing TicketsDecayReminderJob.\r\n" + ex.getMessage()); } } }  @Schedule(hour = "*", minute = "*/15", second = "*", persistent = false) void execute();  }### Answer:
@Test public void thatSendMailWorks() { ZonedDateTime start = ZonedDateTime.now().plusMinutes(5); TicketsDecayReminderJob classUnderTest = new TicketsDecayReminderJob(); Whitebox.setInternalState(classUnderTest, "runJobs", createDummyInstance(true)); LotteryManager lotteryManagerMock = mock(LotteryManager.class); German6aus49Lottery german6aus49LotteryMock = mock(German6aus49Lottery.class); when(german6aus49LotteryMock.getNextDrawing(null, null)).thenReturn(start); when(lotteryManagerMock.getLotteries()).thenReturn(Collections.singletonList(german6aus49LotteryMock)); ShoppingCartRepository shoppingCartRepositoryMock = mock(ShoppingCartRepository.class); ShoppingCart shoppingCart = mock(ShoppingCart.class); when(shoppingCart.getPlayerId()).thenReturn(new ObjectId()); German6aus49Ticket ticketMock = mock(German6aus49Ticket.class); when(ticketMock.getLottery()).thenReturn(german6aus49LotteryMock); when(ticketMock.getStartingDate()).thenReturn(start); when(shoppingCart.getTicketList()).thenReturn(Collections.singletonList(ticketMock)); when(shoppingCartRepositoryMock.getAllShoppingsCartWithTickets()).thenReturn(Collections.singletonList(shoppingCart)); UserRepository userRepositoryMock = mock(UserRepository.class); when(userRepositoryMock.findById(any(ObjectId.class))).thenReturn(mock(Player.class)); Whitebox.setInternalState(classUnderTest, "lotteryManager", lotteryManagerMock); Whitebox.setInternalState(classUnderTest, "shoppingCartRepository", shoppingCartRepositoryMock); Whitebox.setInternalState(classUnderTest, "userRepository", userRepositoryMock); Whitebox.setInternalState(classUnderTest, "mailController", mailControllerMock); Whitebox.setInternalState(classUnderTest, "activityLogController", activityLogController); classUnderTest.execute(); verify(mailControllerMock, times(1)).sendTicketsDecayReminderMail(any(Player.class)); }