@Test
public void testAddItem() throws Exception {

    final String todoItemText = "Walk the dog";
    final ArgumentCaptor<TodoItem> itemCaptor = ArgumentCaptor.forClass(TodoItem.class);
    final ArgumentCaptor<Realm.Transaction> txCaptor = ArgumentCaptor.forClass(Realm.Transaction.class);
    controller.addItem(todoItemText);
    // Verify executeTransactionAsync is called, then artificially execute it
    // with the mock realmRealm implementation.
    verify(mockRealm, times(1)).executeTransactionAsync(txCaptor.capture());
    txCaptor.getValue().execute(mockRealm);
    // Verify that Realm#createObject was called only once
    // Verify that a TodoItem was in fact created.
    verify(mockRealm, times(1)).insertOrUpdate(itemCaptor.capture());
    // With the value we expect.
    assertEquals(todoItemText, itemCaptor.getValue().getText());
}