@Test public void shouldRemoveExpenseById() throws Exception { final Nobt nobt = aNobt() .withExpenses(anExpense().withId(1L)) .build(); nobt.deleteExpense(1L); assertThat(nobt, allOf( hasExpenses(iterableWithSize(0)), hasDeletedExpenses(iterableWithSize(1)) )); }
public void deleteExpense(long expenseId) { Expense expenseToDelete = expenses.stream() .filter(e -> e.getId() == expenseId) .findFirst() .orElseThrow(UnknownExpenseException::new); expenses.remove(expenseToDelete); deletedExpenses.add(new DeletedExpense(expenseToDelete)); }
Nobt { public void deleteExpense(long expenseId) { Expense expenseToDelete = expenses.stream() .filter(e -> e.getId() == expenseId) .findFirst() .orElseThrow(UnknownExpenseException::new); expenses.remove(expenseToDelete); deletedExpenses.add(new DeletedExpense(expenseToDelete)); } }
Nobt { public void deleteExpense(long expenseId) { Expense expenseToDelete = expenses.stream() .filter(e -> e.getId() == expenseId) .findFirst() .orElseThrow(UnknownExpenseException::new); expenses.remove(expenseToDelete); deletedExpenses.add(new DeletedExpense(expenseToDelete)); } 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 void deleteExpense(long expenseId) { Expense expenseToDelete = expenses.stream() .filter(e -> e.getId() == expenseId) .findFirst() .orElseThrow(UnknownExpenseException::new); expenses.remove(expenseToDelete); deletedExpenses.add(new DeletedExpense(expenseToDelete)); } 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 void deleteExpense(long expenseId) { Expense expenseToDelete = expenses.stream() .filter(e -> e.getId() == expenseId) .findFirst() .orElseThrow(UnknownExpenseException::new); expenses.remove(expenseToDelete); deletedExpenses.add(new DeletedExpense(expenseToDelete)); } 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);  }