ExpensePresenter { public boolean addExpense() { String amount = view.getAmount(); if(amount.isEmpty()) { view.displayError(); return false; } Expense expense = new Expense(Long.valueOf(amount), view.getType(), getCurrentDate()); database.addExpense(expense); return true; } ExpensePresenter(ExpenseDatabaseHelper expenseDatabaseHelper, ExpenseView view); boolean addExpense(); void setExpenseTypes();  }
@Test public void shouldAddExpenseAndNotify() throws Exception { DateTimeUtils.setCurrentMillisFixed(new DateTime("2015-09-06").getMillis()); when(view.getAmount()).thenReturn("123"); when(view.getType()).thenReturn("Food"); ArgumentCaptor<Expense> expenseCaptor = ArgumentCaptor.forClass(Expense.class); assertTrue(presenter.addExpense()); verify(database).addExpense(expenseCaptor.capture()); Expense actualExpense = expenseCaptor.getValue(); assertThat(actualExpense.getAmount(), is(123l)); assertThat(actualExpense.getType(), is("Food")); assertThat(actualExpense.getDate(), is("06-09-2015")); DateTimeUtils.setCurrentMillisSystem(); }
@Test public void shouldNotAddExpenseAndNotifyViewWhenAmountIsEmpty() throws Exception { when(view.getAmount()).thenReturn(""); when(view.getType()).thenReturn("Food"); assertFalse(presenter.addExpense()); verify(view).displayError(); verifyNoMoreInteractions(database); }