use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class AddEditTaskPresenterTest method populateTask_callsRepoAndUpdatesViewOnAbsentTask.
@Test
public void populateTask_callsRepoAndUpdatesViewOnAbsentTask() {
Task testTask = new Task("TITLE", "DESCRIPTION");
when(mTasksRepository.getTask(testTask.getId())).thenReturn(Flowable.just(Optional.absent()));
// Get a reference to the class under test
mAddEditTaskPresenter = new AddEditTaskPresenter(testTask.getId(), mTasksRepository, mAddEditTaskView, true, mSchedulerProvider);
// When the presenter is asked to populate an existing task
mAddEditTaskPresenter.populateTask();
// Then the task repository is queried and the view updated
verify(mTasksRepository).getTask(eq(testTask.getId()));
verify(mAddEditTaskView).showEmptyTaskError();
verify(mAddEditTaskView, never()).setTitle(testTask.getTitle());
verify(mAddEditTaskView, never()).setDescription(testTask.getDescription());
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class AddEditTaskPresenterTest method populateTask_callsRepoAndUpdatesViewOnError.
@Test
public void populateTask_callsRepoAndUpdatesViewOnError() {
Task testTask = new Task("TITLE", "DESCRIPTION");
when(mTasksRepository.getTask(testTask.getId())).thenReturn(Flowable.error(new Throwable("Some error")));
// Get a reference to the class under test
mAddEditTaskPresenter = new AddEditTaskPresenter(testTask.getId(), mTasksRepository, mAddEditTaskView, true, mSchedulerProvider);
// When the presenter is asked to populate an existing task
mAddEditTaskPresenter.populateTask();
// Then the task repository is queried and the view updated
verify(mTasksRepository).getTask(eq(testTask.getId()));
verify(mAddEditTaskView).showEmptyTaskError();
verify(mAddEditTaskView, never()).setTitle(testTask.getTitle());
verify(mAddEditTaskView, never()).setDescription(testTask.getDescription());
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class TasksRepositoryTest method deleteAllTasks_deleteTasksToServiceAPIUpdatesCache.
@Test
public void deleteAllTasks_deleteTasksToServiceAPIUpdatesCache() {
// Given 2 stub completed tasks and 1 stub active tasks in the repository
Task newTask = new Task(TASK_TITLE, "Some Task Description", true);
mTasksRepository.saveTask(newTask);
Task newTask2 = new Task(TASK_TITLE2, "Some Task Description");
mTasksRepository.saveTask(newTask2);
Task newTask3 = new Task(TASK_TITLE3, "Some Task Description", true);
mTasksRepository.saveTask(newTask3);
// When all tasks are deleted to the tasks repository
mTasksRepository.deleteAllTasks();
// Verify the data sources were called
verify(mTasksRemoteDataSource).deleteAllTasks();
verify(mTasksLocalDataSource).deleteAllTasks();
assertThat(mTasksRepository.mCachedTasks.size(), is(0));
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class TasksRepositoryTest method completeTaskId_completesTaskToServiceAPIUpdatesCache.
@Test
public void completeTaskId_completesTaskToServiceAPIUpdatesCache() {
// Given a stub active task with title and description added in the repository
Task newTask = new Task(TASK_TITLE, "Some Task Description");
mTasksRepository.saveTask(newTask);
// When a task is completed using its id to the tasks repository
mTasksRepository.completeTask(newTask.getId());
// Then the service API and persistent repository are called and the cache is updated
verify(mTasksRemoteDataSource).completeTask(newTask);
verify(mTasksLocalDataSource).completeTask(newTask);
assertThat(mTasksRepository.mCachedTasks.size(), is(1));
assertThat(mTasksRepository.mCachedTasks.get(newTask.getId()).isActive(), is(false));
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class TasksRepositoryTest method saveTask_savesTaskToServiceAPI.
@Test
public void saveTask_savesTaskToServiceAPI() {
// Given a stub task with title and description
Task newTask = new Task(TASK_TITLE, "Some Task Description");
// When a task is saved to the tasks repository
mTasksRepository.saveTask(newTask);
// Then the service API and persistent repository are called and the cache is updated
verify(mTasksRemoteDataSource).saveTask(newTask);
verify(mTasksLocalDataSource).saveTask(newTask);
assertThat(mTasksRepository.mCachedTasks.size(), is(1));
}
Aggregations