ProjectEntity { public PledgeEntity pledgeUsingPostRoundBudget(Pledge pledge, UserEntity pledgingUser, List<PledgeEntity> pledgesAlreadyDone, int postRoundPledgableBudgetAvailable) { Assert.isTrue(pledgingUser.getRoles().contains(Roles.ROLE_ADMIN), "pledgeUsingPostRoundBudget(..) called with non admin user: " + pledgingUser); Assert.notNull(this.financingRound, "FinancingRound must not be null; Project was: " + this); Assert.isTrue(this.financingRound.terminated(), "pledgeUsingPostRoundBudget(..) requires its financingRound to be terminated; Project was: " + this); if (!this.financingRound.getTerminationPostProcessingDone()) { throw InvalidRequestException.financingRoundNotPostProcessedYet(); } if (this.status == ProjectStatus.FULLY_PLEDGED) { throw InvalidRequestException.projectAlreadyFullyPledged(); } if (this.status != ProjectStatus.PUBLISHED) { throw InvalidRequestException.projectNotPublished(); } if (pledge.getAmount() == 0) { throw InvalidRequestException.zeroPledgeNotValid(); } if (pledge.getAmount() > postRoundPledgableBudgetAvailable) { throw InvalidRequestException.postRoundBudgetExceeded(); } if (pledgedAmountPostRound(pledgesAlreadyDone) + pledge.getAmount() < 0) { throw InvalidRequestException.reversePledgeExceeded(); } int newPledgedAmount = pledgedAmount(pledgesAlreadyDone) + pledge.getAmount(); if (newPledgedAmount > this.pledgeGoal) { throw InvalidRequestException.pledgeGoalExceeded(); } if (newPledgedAmount == this.pledgeGoal) { setStatus(ProjectStatus.FULLY_PLEDGED); } return new PledgeEntity(this, pledgingUser, pledge, financingRound); } ProjectEntity(UserEntity creator, Project project, FinancingRoundEntity financingRound); @Deprecated /** * @deprecated DO NOT use this one, due to this causes problems in ATs, violating this model's constraints! */  ProjectEntity(); PledgeEntity pledge(Pledge pledge, UserEntity pledgingUser, List<PledgeEntity> pledgesAlreadyDone); PledgeEntity pledgeUsingPostRoundBudget(Pledge pledge, UserEntity pledgingUser, List<PledgeEntity> pledgesAlreadyDone, int postRoundPledgableBudgetAvailable); boolean modifyStatus(ProjectStatus newStatus); boolean modifyMasterdata(Project updatedProject, UserEntity requestingUser); void addAttachmentAllowed(UserEntity attachmentCreator); void deleteAttachmentAllowed(UserEntity attachmentCreator); void addAttachment(AttachmentValue attachment); void deleteAttachment(AttachmentValue attachment2Delete); AttachmentValue findAttachmentByReference(Attachment attachment); boolean onFinancingRoundTerminated(FinancingRoundEntity financingRound); boolean pledgeGoalAchieved(); int pledgedAmount(List<PledgeEntity> pledges); long countBackers(List<PledgeEntity> pledges); int pledgedAmountOfUser(List<PledgeEntity> pledges, UserEntity requestingUser); int pledgedAmountPostRound(List<PledgeEntity> pledges); String getId(); UserEntity getCreator(); FinancingRoundEntity getFinancingRound(); String getTitle(); String getShortDescription(); String getDescription(); ProjectStatus getStatus(); int getPledgeGoal(); DateTime getCreatedDate(); DateTime getLastModifiedDate(); List<AttachmentValue> getAttachments(); void setId(String id); void setCreator(UserEntity creator); void setFinancingRound(FinancingRoundEntity financingRound); void setTitle(String title); void setShortDescription(String shortDescription); void setDescription(String description); void setStatus(ProjectStatus status); void setPledgeGoal(int pledgeGoal); void setCreatedDate(DateTime createdDate); void setLastModifiedDate(DateTime lastModifiedDate); void setAttachments(List<AttachmentValue> attachments); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void pledgeUsingPostroundBudget() { projectEntity.setStatus(ProjectStatus.PUBLISHED); projectEntity.setFinancingRound(aTerminatedFinancingRound()); final List<PledgeEntity> pledgesDoneBefore = bunchOfWithPostRoundPledgesDone(); final Pledge pledge = new Pledge(projectEntity.getPledgeGoal() - projectEntity.pledgedAmount(pledgesDoneBefore)); int userBudgetBefore = adminUser.getBudget(); final PledgeEntity pledgeRes = projectEntity.pledgeUsingPostRoundBudget(pledge, adminUser, pledgesDoneBefore, 400); assertThat(pledgeRes, is(new PledgeEntity(projectEntity, adminUser, pledge, projectEntity.getFinancingRound()))); assertThat(adminUser.getBudget(), is(userBudgetBefore)); assertThat(projectEntity.pledgeGoalAchieved(), is(true)); }