FinancingRoundService implements ApplicationListener<ContextRefreshedEvent> { public List<FinancingRound> allFinancingRounds() { final List<FinancingRoundEntity> all = financingRoundRepository.findAll(); if (all.isEmpty()) { return Collections.emptyList(); } return all.stream() .map(this::financingRound) .collect(Collectors.toList()); } @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 allFinancingRounds() throws Exception { final int pledgedAmountAfterTermination = 10; financingRoundEntities.get(0).setTerminationPostProcessingDone(true); financingRoundEntities.get(1).setTerminationPostProcessingDone(true); when(pledgeRepository.findByFinancingRoundAndCreatedDateGreaterThan(financingRoundEntities.get(1), financingRoundEntities.get(1).getEndDate())) .thenReturn(Collections.singletonList(aPledgeEntity(financingRoundEntities.get(1), pledgedAmountAfterTermination))); final List<FinancingRound> res = financingRoundService.allFinancingRounds(); verify(financingRoundRepository, times(1)).findAll(); verify(pledgeRepository, times(2)).findByFinancingRoundAndCreatedDateGreaterThan(any(FinancingRoundEntity.class), any(DateTime.class)); assertFinancingRoundDto(financingRoundEntities.get(0), res.get(0), POST_ROUND_BUDGET); assertFinancingRoundDto(financingRoundEntities.get(1), res.get(1), POST_ROUND_BUDGET - pledgedAmountAfterTermination); }