TasksViewModel extends BaseViewModel<TasksViewModel.State> { protected void onTaskUpdate(Task task) { Task tmp; int n = mTasks.size(); for (int i = 0; i < n; i++) { tmp = mTasks.get(i); if (task.getId().equals(tmp.getId())) { tmp.setTitle(task.getTitle()); tmp.setDescription(task.getDescription()); tmp.setCompleted(task.isCompleted()); setState(State.UPDATED_TASK, Constants.Key.INDEX, i); break; } } } TasksViewModel(); @Override void onCreate(); List<Task> getTasks(); void reloadData();  }
@Test public void testOnTaskUpdate() throws Exception { Task taskA = new Task("title a", "description a"); List<Task> tasks = mTasksViewModel.getTasks(); tasks.add(taskA); Task taskB = new Task(taskA.getId(), "title b", "description b"); mTasksViewModel.onTaskUpdate(taskB); verify(mTasksViewModel, times(1)).setState(eq(TasksViewModel.State.UPDATED_TASK), eq(Constants.Key.INDEX), eq(tasks.size() - 1)); }