FinancingRoundPostProcessor { public FinancingRoundEntity postProcess(FinancingRoundEntity financingRound) { Assert.notNull(financingRound); if (!financingRound.terminationPostProcessingRequiredNow()) { log.info("Skipping post processing of FinancingRound due to not required right now: {}", financingRound); return financingRound; } log.info("Starting post processing of FinancingRound {}", financingRound); assignUnpledgedBudgetToFinancingRound(financingRound); notifyProjectsOfTerminatedFinancingRound(financingRound); financingRound.setTerminationPostProcessingDone(true); FinancingRoundEntity res = financingRoundRepository.save(financingRound); log.info("Finished post processing of FinancingRound {}", res); return res; } @Autowired  FinancingRoundPostProcessor(
            FinancingRoundRepository financingRoundRepository,
            ProjectRepository projectRepository,
            PledgeRepository pledgeRepository); FinancingRoundEntity postProcess(FinancingRoundEntity financingRound);  }
@Test public void postProcess_succeeds() throws Exception { final FinancingRoundEntity terminatedRound = prepareInactiveFinancingRound(); project_0.setFinancingRound(terminatedRound); project_1.setFinancingRound(terminatedRound); project_2.setFinancingRound(null); final FinancingRoundEntity res = financingRoundPostProcessor.postProcess(terminatedRound); verify(projectRepository, atLeastOnce()).findByFinancingRound(any(FinancingRoundEntity.class)); verify(financingRoundRepository).save(res); verify(projectRepository, times(1)).save(any(ProjectEntity.class)); assertThat(project_0.getStatus(), is(ProjectStatus.PUBLISHED)); assertThat(project_1.getStatus(), is(ProjectStatus.FULLY_PLEDGED)); assertThat(project_2.getStatus(), is(ProjectStatus.DEFERRED)); assertThat(project_3.getStatus(), is(ProjectStatus.PUBLISHED)); assertThat(res.getPostRoundBudget(), is(EXPECTED_REMAINING_BUDGET_AFTER_ROUND)); assertThat(terminatedRound.getTerminationPostProcessingDone(), is(true)); }
@Test public void postProcess_doesNothingOnActiveRound() throws Exception { final FinancingRoundEntity activeRound = prepareActiveFinanzingRound(); project_0.setFinancingRound(activeRound); final FinancingRoundEntity res = financingRoundPostProcessor.postProcess(activeRound); verify(projectRepository, never()).findByFinancingRound(activeRound); verify(projectRepository, never()).save(any(ProjectEntity.class)); verify(financingRoundRepository, never()).save(any(FinancingRoundEntity.class)); assertThat(res, is(activeRound)); assertThat(res.getTerminationPostProcessingDone(), is(false)); }