FinancingRoundService implements ApplicationListener<ContextRefreshedEvent> { public FinancingRound mostRecentRound() { return financingRound(mostRecentRoundEntity()); } @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 mostRecentRound() throws Exception { final FinancingRoundEntity expFinancingRound = financingRoundEntity("test_roundId", DateTime.now().minusDays(2), DateTime.now().minusDays(1)); ArgumentCaptor<PageRequest> pageRequestCaptor = ArgumentCaptor.forClass(PageRequest.class); Page mockedPageAnswer = mock(Page.class); when(financingRoundRepository.financingRounds(pageRequestCaptor.capture())).thenReturn(mockedPageAnswer); when(mockedPageAnswer.getNumberOfElements()).thenReturn(1); when(mockedPageAnswer.getContent()).thenReturn(Collections.singletonList(expFinancingRound)); final FinancingRound res = financingRoundService.mostRecentRound(); assertThat(res, is(new FinancingRound(expFinancingRound, null))); assertThat(pageRequestCaptor.getValue().getSort().getOrderFor("createdDate"), is(new Sort.Order(Sort.Direction.DESC, "createdDate"))); assertThat(pageRequestCaptor.getValue().getPageSize(), is(1)); assertThat(pageRequestCaptor.getValue().getPageNumber(), is(0)); }
@Test(expected = ResourceNotFoundException.class) public void mostRecentRound_throwsExceptionIfNoFinancingRoundsExist() throws Exception { ArgumentCaptor<PageRequest> pageRequestCaptor = ArgumentCaptor.forClass(PageRequest.class); Page mockedPageAnswer = mock(Page.class); when(financingRoundRepository.financingRounds(pageRequestCaptor.capture())).thenReturn(mockedPageAnswer); when(mockedPageAnswer.getNumberOfElements()).thenReturn(0); financingRoundService.mostRecentRound(); }