FinancingRoundService implements ApplicationListener<ContextRefreshedEvent> { FinancingRound financingRound(FinancingRoundEntity financingRoundEntity) { List<PledgeEntity> postRoundPledges = null; if (financingRoundEntity.getTerminationPostProcessingDone()) { postRoundPledges = pledgeRepository.findByFinancingRoundAndCreatedDateGreaterThan(financingRoundEntity, financingRoundEntity.getEndDate()); } return new FinancingRound(financingRoundEntity, postRoundPledges); } @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 financingRound_ShouldCallRepositoryOnTerminatedPostProcessedRound() throws Exception { final FinancingRoundEntity financingRoundEntity = financingRoundEntity("test_roundId", DateTime.now().minusDays(3), DateTime.now().minusDays(2)); financingRoundEntity.setTerminationPostProcessingDone(true); when(pledgeRepository.findByFinancingRoundAndCreatedDateGreaterThan(any(FinancingRoundEntity.class), any(DateTime.class))) .thenReturn(Collections.singletonList(aPledgeEntity(financingRoundEntity, 100))); final FinancingRound res = financingRoundService.financingRound(financingRoundEntity); assertFinancingRoundDto(financingRoundEntity, res, 300); }
@Test public void financingRound_ShouldNotCallRepositoryOnNonTerminatedNonPostProcessedRound() throws Exception { final FinancingRoundEntity financingRoundEntity = financingRoundEntity("test_roundId", DateTime.now().minusDays(2), DateTime.now().plusDays(1)); final FinancingRound res = financingRoundService.financingRound(financingRoundEntity); assertFinancingRoundDto(financingRoundEntity, res, 0); verify(pledgeRepository, never()).findByFinancingRoundAndCreatedDateGreaterThan(any(FinancingRoundEntity.class), any(DateTime.class)); }