use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class TasksRepositoryTest method deleteCompletedTasks_deleteCompletedTasksToServiceAPIUpdatesCache.
@Test
public void deleteCompletedTasks_deleteCompletedTasksToServiceAPIUpdatesCache() {
// 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 a completed tasks are cleared to the tasks repository
mTasksRepository.clearCompletedTasks();
// Then the service API and persistent repository are called and the cache is updated
verify(mTasksRemoteDataSource).clearCompletedTasks();
verify(mTasksLocalDataSource).clearCompletedTasks();
assertThat(mTasksRepository.mCachedTasks.size(), is(1));
assertTrue(mTasksRepository.mCachedTasks.get(newTask2.getId()).isActive());
assertThat(mTasksRepository.mCachedTasks.get(newTask2.getId()).getTitle(), is(TASK_TITLE2));
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class TasksRepositoryTest method getTask_requestsSingleTaskFromLocalDataSource.
@Test
public void getTask_requestsSingleTaskFromLocalDataSource() {
// Given a stub completed task with title and description in the local repository
Task task = new Task(TASK_TITLE, "Some Task Description", true);
Optional<Task> taskOptional = Optional.of(task);
setTaskAvailable(mTasksLocalDataSource, taskOptional);
// And the task not available in the remote repository
setTaskNotAvailable(mTasksRemoteDataSource, taskOptional.get().getId());
// When a task is requested from the tasks repository
TestSubscriber<Optional<Task>> testSubscriber = new TestSubscriber<>();
mTasksRepository.getTask(task.getId()).subscribe(testSubscriber);
// Then the task is loaded from the database
verify(mTasksLocalDataSource).getTask(eq(task.getId()));
testSubscriber.assertValue(taskOptional);
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class StatisticsPresenterTest method setupStatisticsPresenter.
@Before
public void setupStatisticsPresenter() {
// Mockito has a very convenient way to inject mocks by using the @Mock annotation. To
// inject the mocks in the test the initMocks method needs to be called.
MockitoAnnotations.initMocks(this);
// Make the sure that all schedulers are immediate.
mSchedulerProvider = new ImmediateSchedulerProvider();
// Get a reference to the class under test
mStatisticsPresenter = new StatisticsPresenter(mTasksRepository, mStatisticsView, mSchedulerProvider);
// The presenter won't update the view unless it's active.
when(mStatisticsView.isActive()).thenReturn(true);
// We subscribe the tasks to 3, with one active and two completed
TASKS = Lists.newArrayList(new Task("Title1", "Description1"), new Task("Title2", "Description2", true), new Task("Title3", "Description3", true));
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class AddEditTaskScreenTest method toolbarTitle_editTask_persistsRotation.
@Test
public void toolbarTitle_editTask_persistsRotation() {
// Put a task in the repository and start the activity to edit it
TasksRepository.destroyInstance();
FakeTasksRemoteDataSource.getInstance().addTasks(new Task("Title1", "", TASK_ID, false));
launchNewTaskActivity(TASK_ID);
// Check that the toolbar shows the correct title
onView(withId(toolbar)).check(matches(withToolbarTitle(R.string.edit_task)));
// Rotate activity
TestUtils.rotateOrientation(mActivityTestRule.getActivity());
// check that the toolbar title is persisted
onView(withId(toolbar)).check(matches(withToolbarTitle(R.string.edit_task)));
}
use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.
the class StatisticsScreenTest method intentWithStubbedTaskId.
/**
* Setup your test fixture with a fake task id. The {@link TaskDetailActivity} is started with
* a particular task id, which is then loaded from the service API.
*
* <p>
* Note that this test runs hermetically and is fully isolated using a fake implementation of
* the service API. This is a great way to make your tests more reliable and faster at the same
* time, since they are isolated from any outside dependencies.
*/
@Before
public void intentWithStubbedTaskId() {
// Given some tasks
TasksRepository.destroyInstance();
TasksRepository repository = Injection.provideTasksRepository(InstrumentationRegistry.getContext());
repository.saveTask(new Task("Title1", "", false));
repository.saveTask(new Task("Title2", "", true));
// Lazily start the Activity from the ActivityTestRule
Intent startIntent = new Intent();
mStatisticsActivityTestRule.launchActivity(startIntent);
}
Aggregations