Search in sources :

Example 26 with Task

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());
}
Also used : Task(com.example.android.architecture.blueprints.todoapp.data.Task) Optional(com.google.common.base.Optional) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 27 with Task

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));
}
Also used : Task(com.example.android.architecture.blueprints.todoapp.data.Task) Test(org.junit.Test)

Example 28 with Task

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));
}
Also used : Task(com.example.android.architecture.blueprints.todoapp.data.Task) Test(org.junit.Test)

Example 29 with Task

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();
}
Also used : Task(com.example.android.architecture.blueprints.todoapp.data.Task) Test(org.junit.Test)

Example 30 with Task

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();
}
Also used : Task(com.example.android.architecture.blueprints.todoapp.data.Task) Test(org.junit.Test)

Aggregations

Task (com.example.android.architecture.blueprints.todoapp.data.Task)35 Test (org.junit.Test)20 Optional (com.google.common.base.Optional)3 Before (org.junit.Before)3 TasksRepository (com.example.android.architecture.blueprints.todoapp.data.source.TasksRepository)2 ImmediateSchedulerProvider (com.example.android.architecture.blueprints.todoapp.util.schedulers.ImmediateSchedulerProvider)2 Flowable (io.reactivex.Flowable)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Disposable (io.reactivex.disposables.Disposable)2 TestSubscriber (io.reactivex.subscribers.TestSubscriber)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 LargeTest (android.support.test.filters.LargeTest)1 AddEditTaskActivity (com.example.android.architecture.blueprints.todoapp.addedittask.AddEditTaskActivity)1 TasksDataSource (com.example.android.architecture.blueprints.todoapp.data.source.TasksDataSource)1 EspressoIdlingResource (com.example.android.architecture.blueprints.todoapp.util.EspressoIdlingResource)1 BaseSchedulerProvider (com.example.android.architecture.blueprints.todoapp.util.schedulers.BaseSchedulerProvider)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 List (java.util.List)1