use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class TasksRepositoryTest method getTask_whenDataNotLocal_fails.
@Test
public void getTask_whenDataNotLocal_fails() {
// Given a stub completed task with title and description in the remote repository
Task task = new Task(TASK_TITLE, "Some Task Description", true);
Optional<Task> taskOptional = Optional.of(task);
setTaskAvailable(mTasksRemoteDataSource, taskOptional);
// And the task not available in the local repository
setTaskNotAvailable(mTasksLocalDataSource, task.getId());
// When a task is requested from the tasks repository
TestSubscriber<Optional<Task>> testSubscriber = new TestSubscriber<>();
mTasksRepository.getTask(task.getId()).subscribe(testSubscriber);
// then empty Optional is returned
testSubscriber.assertValue(Optional.absent());
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class TasksRepositoryTest method activateTaskId_activatesTaskToServiceAPIUpdatesCache.
@Test
public void activateTaskId_activatesTaskToServiceAPIUpdatesCache() {
// Given a stub completed task with title and description in the repository
Task newTask = new Task(TASK_TITLE, "Some Task Description", true);
mTasksRepository.saveTask(newTask);
// When a completed task is activated with its id to the tasks repository
mTasksRepository.activateTask(newTask.getId());
// Then the service API and persistent repository are called and the cache is updated
verify(mTasksRemoteDataSource).activateTask(newTask);
verify(mTasksLocalDataSource).activateTask(newTask);
assertThat(mTasksRepository.mCachedTasks.size(), is(1));
assertThat(mTasksRepository.mCachedTasks.get(newTask.getId()).isActive(), is(true));
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class TasksRepositoryTest method activateTask_activatesTaskToServiceAPIUpdatesCache.
@Test
public void activateTask_activatesTaskToServiceAPIUpdatesCache() {
// Given a stub completed task with title and description in the repository
Task newTask = new Task(TASK_TITLE, "Some Task Description", true);
mTasksRepository.saveTask(newTask);
// When a completed task is activated to the tasks repository
mTasksRepository.activateTask(newTask);
// Then the service API and persistent repository are called and the cache is updated
verify(mTasksRemoteDataSource).activateTask(newTask);
verify(mTasksLocalDataSource).activateTask(newTask);
assertThat(mTasksRepository.mCachedTasks.size(), is(1));
assertThat(mTasksRepository.mCachedTasks.get(newTask.getId()).isActive(), is(true));
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class TaskDetailPresenterTest method deleteTask.
@Test
public void deleteTask() {
// Given an initialized TaskDetailPresenter with stubbed task
Task task = new Task(TITLE_TEST, DESCRIPTION_TEST);
// When the deletion of a task is requested
mTaskDetailPresenter = new TaskDetailPresenter(task.getId(), mTasksRepository, mTaskDetailView, mSchedulerProvider);
mTaskDetailPresenter.deleteTask();
// Then the repository and the view are notified
verify(mTasksRepository).deleteTask(task.getId());
verify(mTaskDetailView).showTaskDeleted();
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class TaskDetailPresenterTest method completeTask.
@Test
public void completeTask() {
// Given an initialized presenter with an active task
Task task = new Task(TITLE_TEST, DESCRIPTION_TEST);
mTaskDetailPresenter = new TaskDetailPresenter(task.getId(), mTasksRepository, mTaskDetailView, mSchedulerProvider);
setTaskAvailable(task);
mTaskDetailPresenter.subscribe();
// When the presenter is asked to complete the task
mTaskDetailPresenter.completeTask();
// Then a request is sent to the task repository and the UI is updated
verify(mTasksRepository).completeTask(task.getId());
verify(mTaskDetailView).showTaskMarkedComplete();
}
Aggregations