FinancingRoundEntity { public Integer postRoundPledgableBudgetRemaining(List<PledgeEntity> postRoundPledges) { if (!terminationPostProcessingDone) { return 0; } if (postRoundPledges == null || postRoundPledges.isEmpty()) { return this.postRoundBudget; } Collections.sort(postRoundPledges, new PledgeEntity.CreationTimeComparator() ); Assert.isTrue(postRoundPledges.get(0).getCreatedDate().getMillis() > this.endDate.getMillis(), "Method must not be called with pledgeEntities from active financing round! One entry was: " + postRoundPledges.get(0)); int postRoundPledgeAmount = postRoundPledges.stream().mapToInt(PledgeEntity::getAmount).sum(); return this.postRoundBudget - postRoundPledgeAmount; } FinancingRoundEntity(); static FinancingRoundEntity newFinancingRound(FinancingRound creationCmd, int userCount); boolean projectEligibleForRound(ProjectEntity project); void stopFinancingRound(); boolean active(); boolean terminated(); boolean terminationPostProcessingRequiredNow(); Integer postRoundPledgableBudgetRemaining(List<PledgeEntity> postRoundPledges); void initPostRoundBudget(int pledgeAmountByUsers); String getId(); DateTime getStartDate(); DateTime getEndDate(); Integer getBudget(); Integer getBudgetPerUser(); Integer getUserCount(); DateTime getCreatedDate(); DateTime getLastModifiedDate(); Boolean getTerminationPostProcessingDone(); Integer getPostRoundBudget(); void setId(String id); void setStartDate(DateTime startDate); void setEndDate(DateTime endDate); void setBudget(Integer budget); void setBudgetPerUser(Integer budgetPerUser); void setUserCount(Integer userCount); void setCreatedDate(DateTime createdDate); void setLastModifiedDate(DateTime lastModifiedDate); void setTerminationPostProcessingDone(Boolean terminationPostProcessingDone); void setPostRoundBudget(Integer postRoundBudget); @Override boolean equals(Object o); boolean idenitityEquals(FinancingRoundEntity other); @Override int hashCode(); @Override String toString();  }
@Test public void postRoundPledgableBudgetRemaining() throws Exception { FinancingRoundEntity round = newFinancingRound(1000, 12, new DateTime().minusDays(2)); round.setPostRoundBudget(400); round.setTerminationPostProcessingDone(true); assertThat(round.postRoundPledgableBudgetRemaining(preparePostRoundPledges(round)), is(400 - (1 + 2 + 3 + 4 + 5))); }