FinancingRoundService implements ApplicationListener<ContextRefreshedEvent> { void reschedulePostProcessingOfFinancingRounds() { log.info("Going to (re-) schedule post processing of still active or not already processed inactive financing rounds."); financingRoundRepository.findAll().stream() .filter(fr -> !fr.getTerminationPostProcessingDone()) .forEach(this::schedulePostProcessing); } @Autowired  FinancingRoundService(UserRepository userRepository,
                                 FinancingRoundRepository financingRoundRepository,
                                 ProjectRepository projectRepository,
                                 FinancingRoundPostProcessor financingRoundPostProcessor,
                                 TaskScheduler crowdScheduler,
                                 PledgeRepository pledgeRepository); @Override void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent); List<FinancingRound> allFinancingRounds(); FinancingRound currentlyActiveRound(); FinancingRound mostRecentRound(); FinancingRoundEntity mostRecentRoundEntity(); FinancingRound startNewFinancingRound(FinancingRound creationCommand); FinancingRound stopFinancingRound(String financingRoundId);  }
@Test public void reschedulePostProcessingOfFinancingRounds() throws Exception { ArgumentCaptor<Date> scheduleDateCaptor = ArgumentCaptor.forClass(Date.class); financingRoundService.reschedulePostProcessingOfFinancingRounds(); verify(crowdScheduler, times(financingRoundEntities.size())).schedule(any(Runnable.class), scheduleDateCaptor.capture()); final List<Date> capturedScheduleDates = scheduleDateCaptor.getAllValues(); assertThat(capturedScheduleDates.size(), is(financingRoundEntities.size())); for (int i = 0; i < capturedScheduleDates.size(); i++) { assertTrue("Should have captured actual end dates as scheduler dates", capturedScheduleDates.contains(financingRoundEntities.get(i).getEndDate().toDate())); } }