FinancingRoundService implements ApplicationListener<ContextRefreshedEvent> { public FinancingRound currentlyActiveRound() { final FinancingRoundEntity financingRoundEntity = financingRoundRepository.findActive(DateTime.now()); if (financingRoundEntity == null) { throw new ResourceNotFoundException(); } return financingRound(financingRoundEntity); } @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 currentlyActiveRound() throws Exception { final FinancingRoundEntity financingRoundEntity = financingRoundEntity("test_roundId", fixedDate.minusDays(100), fixedDate.minusDays(50)); when(financingRoundRepository.findActive(any())) .thenReturn(financingRoundEntity); final FinancingRound res = financingRoundService.currentlyActiveRound(); assertFinancingRoundDto(financingRoundEntity, res, 0); verify(financingRoundRepository, times(1)).findActive(any()); }
@Test(expected = ResourceNotFoundException.class) public void currentlyActiveRound_ThrowsResournceNotFoundExceptionIfNotFonud() throws Exception { when(financingRoundRepository.findActive(any(DateTime.class))).thenReturn(null); financingRoundService.currentlyActiveRound(); }