@Test public void shouldBuildListOfPersonsFromEveryExpense() throws Exception { final Expense firstExpense = mock(Expense.class); final Expense secondExpense = mock(Expense.class); final Nobt nobt = aNobt() .withExpenses(firstExpense, secondExpense) .build(); nobt.getParticipatingPersons(); verify(firstExpense).getParticipants(); verify(secondExpense).getParticipants(); }
public Set<Person> getParticipatingPersons() { final Set<Person> participantsFromCashFlows = Stream.of(expenses, payments) .flatMap(Collection::stream) .map(CashFlow::getParticipants) .flatMap(Collection::stream) .collect(toSet()); return Stream.of(explicitParticipants, participantsFromCashFlows) .flatMap(Collection::stream) .collect(toCollection(HashSet::new)); }
Nobt { public Set<Person> getParticipatingPersons() { final Set<Person> participantsFromCashFlows = Stream.of(expenses, payments) .flatMap(Collection::stream) .map(CashFlow::getParticipants) .flatMap(Collection::stream) .collect(toSet()); return Stream.of(explicitParticipants, participantsFromCashFlows) .flatMap(Collection::stream) .collect(toCollection(HashSet::new)); } }
Nobt { public Set<Person> getParticipatingPersons() { final Set<Person> participantsFromCashFlows = Stream.of(expenses, payments) .flatMap(Collection::stream) .map(CashFlow::getParticipants) .flatMap(Collection::stream) .collect(toSet()); return Stream.of(explicitParticipants, participantsFromCashFlows) .flatMap(Collection::stream) .collect(toCollection(HashSet::new)); } Nobt(NobtId id, CurrencyKey currencyKey, String name, Set<Person> explicitParticipants, Set<Expense> expenses, Set<DeletedExpense> deletedExpenses, Set<Payment> payments, Instant createdOn, Optimizer optimizer); }
Nobt { public Set<Person> getParticipatingPersons() { final Set<Person> participantsFromCashFlows = Stream.of(expenses, payments) .flatMap(Collection::stream) .map(CashFlow::getParticipants) .flatMap(Collection::stream) .collect(toSet()); return Stream.of(explicitParticipants, participantsFromCashFlows) .flatMap(Collection::stream) .collect(toCollection(HashSet::new)); } Nobt(NobtId id, CurrencyKey currencyKey, String name, Set<Person> explicitParticipants, Set<Expense> expenses, Set<DeletedExpense> deletedExpenses, Set<Payment> payments, Instant createdOn, Optimizer optimizer); NobtId getId(); CurrencyKey getCurrencyKey(); String getName(); Optimizer getOptimizer(); Set<Expense> getExpenses(); Set<DeletedExpense> getDeletedExpenses(); Set<Payment> getPayments(); Set<Person> getParticipatingPersons(); List<Debt> getOptimizedDebts(); Instant getCreatedOn(); void createExpenseFrom(ExpenseDraft expenseDraft); void createPaymentFrom(PaymentDraft paymentDraft); void deleteExpense(long expenseId); }
Nobt { public Set<Person> getParticipatingPersons() { final Set<Person> participantsFromCashFlows = Stream.of(expenses, payments) .flatMap(Collection::stream) .map(CashFlow::getParticipants) .flatMap(Collection::stream) .collect(toSet()); return Stream.of(explicitParticipants, participantsFromCashFlows) .flatMap(Collection::stream) .collect(toCollection(HashSet::new)); } Nobt(NobtId id, CurrencyKey currencyKey, String name, Set<Person> explicitParticipants, Set<Expense> expenses, Set<DeletedExpense> deletedExpenses, Set<Payment> payments, Instant createdOn, Optimizer optimizer); NobtId getId(); CurrencyKey getCurrencyKey(); String getName(); Optimizer getOptimizer(); Set<Expense> getExpenses(); Set<DeletedExpense> getDeletedExpenses(); Set<Payment> getPayments(); Set<Person> getParticipatingPersons(); List<Debt> getOptimizedDebts(); Instant getCreatedOn(); void createExpenseFrom(ExpenseDraft expenseDraft); void createPaymentFrom(PaymentDraft paymentDraft); void deleteExpense(long expenseId);  }