TodoListManager { public final void deleteAllCompleteTodos() { backupTodoItems.clear(); backupTodoItems.putAll((HashMap<Long, TodoItem>) todoItems.clone()); for (TodoItem item : ((HashMap<Long, TodoItem>)todoItems.clone()).values()) { if (item.isComplete()) { todoItems.remove(item.getId()); } } } @Inject  TodoListManager(ActionBus actionBus, DataBus dataBus); void onPause(); @Subscribe void reactToTodoAction(TodoAction action); @Produce RawTodoList produceTodoList(); final void addTodo(String description); final void toggleTodoComplete(long id); final void toggleAllTodosComplete(); final void editTodo(long id, String description); final void deleteTodo(long id); final void deleteAllCompleteTodos(); final void undoDeleteCompleteAllTodos();  }
@Test(timeout = 100) public void deleteAllCompleteTodosTest() throws InterruptedException { final AtomicBoolean testDone = new AtomicBoolean(false); final AtomicBoolean checkedTodo1 = new AtomicBoolean(false); final AtomicBoolean checkedTodo3 = new AtomicBoolean(false); final AtomicBoolean deleted = new AtomicBoolean(false); final ArrayList<TodoItem> todoItems = new ArrayList<TodoItem>(); createTodos(4); dataBus.register(new Object() { @Subscribe public void onListUpdated(RawTodoList rawTodoList) { todoItems.clear(); todoItems.addAll(rawTodoList.list); if (!checkedTodo1.get()) { checkedTodo1.set(true); DataBundle<TodoAction.DataKeys> bundle = new DataBundle<>(); bundle.put(TodoAction.DataKeys.ID, todoItems.get(1).getId()); actionBus.post(new TodoAction(TodoAction.ActionTypes.TOGGLE, bundle)); return; } if (!checkedTodo3.get()) { checkedTodo3.set(true); DataBundle<TodoAction.DataKeys> bundle = new DataBundle<>(); bundle.put(TodoAction.DataKeys.ID, todoItems.get(3).getId()); actionBus.post(new TodoAction(TodoAction.ActionTypes.TOGGLE, bundle)); return; } if (!deleted.get() && checkedTodo1.get() && checkedTodo3.get()) { deleted.set(true); actionBus.post(new TodoAction(TodoAction.ActionTypes.DELETE_ALL)); return; } if (deleted.get()) { assertThat(todoItems.size()).isEqualTo(2); testDone.set(true); } } }); while (!testDone.get()) ; }