Nobt { public void createExpenseFrom(ExpenseDraft expenseDraft) { final Expense expense = Expense.fromDraft(getNextIdentifier(), currencyKey, expenseDraft); expenses.add(expense); } 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);  }
@Test public void shouldThrowExceptionIfConversionInformationIsNotConsistent() throws Exception { final Nobt nobt = aNobt() .withCurrency(new CurrencyKey("EUR")) .build(); final ExpenseDraft expenseDraft = anExpenseDraft() .withConversionInformation(new ConversionInformation(new CurrencyKey("EUR"), BigDecimal.TEN)) .build(); expectedException.expect(ConversionInformationInconsistentException.class); nobt.createExpenseFrom(expenseDraft); }
@Test public void shouldAddExpenseIfConversionInformationIsConsistent() throws Exception { final Nobt nobt = aNobt() .withCurrency(new CurrencyKey("EUR")) .build(); final ExpenseDraft expenseDraft = anExpenseDraft() .withConversionInformation(new ConversionInformation(new CurrencyKey("USD"), BigDecimal.TEN)) .build(); nobt.createExpenseFrom(expenseDraft); }
@Test public void shouldAssignIdToExpense() throws Exception { final Nobt nobt = aNobt().build(); nobt.createExpenseFrom(anExpenseDraft().build()); assertThat(nobt, hasExpenses( allOf( iterableWithSize(greaterThan(0)), everyItem( hasId(notNullValue(Long.class)) ) ) )); }
@Test public void shouldAssignOneAsTheFirstId() throws Exception { final Nobt nobt = aNobt().build(); nobt.createExpenseFrom(anExpenseDraft().build()); assertThat(nobt, hasExpenses(hasItem(hasId(equalTo(1L))))); }