ProjectEntity { public long countBackers(List<PledgeEntity> pledges) { Optional<Integer> backers = pledges.stream() .collect(groupingBy(PledgeEntity::getUser, reducing(new PledgeEntity(), PledgeEntity::add))) .entrySet().stream() .map(pledgeSumByUser -> (pledgeSumByUser.getValue().getAmount() == 0 ? 0 : 1)).reduce((a, b) -> a + b); return backers.orElse(0); } 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 countBackers() throws Exception { final FinancingRoundEntity activeFinancingRound = new FinancingRoundEntity(); assertThat(projectEntity.countBackers(bunchOfPledgesDone()), is(2L)); }
@Test public void countBackers_isZeroOnEmptyPledges() throws Exception { assertThat(projectEntity.countBackers(new ArrayList<>()), is(0L)); }