Search in sources :

Example 21 with Task

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

Example 22 with Task

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

Example 23 with Task

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

Example 24 with Task

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

Example 25 with Task

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));
}
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