CategoryPresenter { public boolean addCategory() { String newCategory = view.getCategory(); if(newCategory.isEmpty()){ view.displayError(); return false; } database.addExpenseType(new ExpenseType(newCategory)); return true; } CategoryPresenter(AddCategoryView view, ExpenseDatabaseHelper database); boolean addCategory();  }
@Test public void shouldAddCategoryToTheDatabaseAndNotify() throws Exception { when(view.getCategory()).thenReturn("Movie"); ArgumentCaptor<ExpenseType> expenseTypeCaptor = ArgumentCaptor.forClass(ExpenseType.class); assertTrue(presenter.addCategory()); verify(database).addExpenseType(expenseTypeCaptor.capture()); ExpenseType expenseType = expenseTypeCaptor.getValue(); assertThat(expenseType.getType(), is("Movie")); }
@Test public void shouldNotAddCategoryAndNotifyViewWhenCategoryInputIsEmpty() throws Exception { when(view.getCategory()).thenReturn(""); assertFalse(presenter.addCategory()); verifyNoMoreInteractions(database); verify(view).displayError(); }