Search in sources :

Example 31 with Task

use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.

the class TaskDetailPresenterTest method activateTask.

@Test
public void activateTask() {
    // Given an initialized presenter with a completed task
    Task task = new Task(TITLE_TEST, DESCRIPTION_TEST, true);
    mTaskDetailPresenter = new TaskDetailPresenter(task.getId(), mTasksRepository, mTaskDetailView, mSchedulerProvider);
    setTaskAvailable(task);
    mTaskDetailPresenter.subscribe();
    // When the presenter is asked to activate the task
    mTaskDetailPresenter.activateTask();
    // Then a request is sent to the task repository and the UI is updated
    verify(mTasksRepository).activateTask(task.getId());
    verify(mTaskDetailView).showTaskMarkedActive();
}
Also used : Task(com.example.android.architecture.blueprints.todoapp.data.Task) Test(org.junit.Test)

Example 32 with Task

use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.

the class TasksPresenterTest method clickOnTask_ShowsDetailUi.

@Test
public void clickOnTask_ShowsDetailUi() {
    // Given a stubbed active task
    Task requestedTask = new Task("Details Requested", "For this task");
    // When open task details is requested
    mTasksPresenter.openTaskDetails(requestedTask);
    // Then task detail UI is shown
    verify(mTasksView).showTaskDetailsUi(any(String.class));
}
Also used : Task(com.example.android.architecture.blueprints.todoapp.data.Task) Test(org.junit.Test)

Example 33 with Task

use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.

the class TasksPresenterTest method completeTask_ShowsTaskMarkedComplete.

@Test
public void completeTask_ShowsTaskMarkedComplete() {
    // Given a stubbed task
    Task task = new Task("Details Requested", "For this task");
    // And no tasks available in the repository
    when(mTasksRepository.getTasks()).thenReturn(Flowable.empty());
    // When task is marked as complete
    mTasksPresenter.completeTask(task);
    // Then repository is called and task marked complete UI is shown
    verify(mTasksRepository).completeTask(task);
    verify(mTasksView).showTaskMarkedComplete();
}
Also used : Task(com.example.android.architecture.blueprints.todoapp.data.Task) Test(org.junit.Test)

Example 34 with Task

use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.

the class TasksPresenterTest method setupTasksPresenter.

@Before
public void setupTasksPresenter() {
    // 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
    mTasksPresenter = new TasksPresenter(mTasksRepository, mTasksView, mSchedulerProvider);
    // The presenter won't update the view unless it's active.
    when(mTasksView.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));
}
Also used : Task(com.example.android.architecture.blueprints.todoapp.data.Task) ImmediateSchedulerProvider(com.example.android.architecture.blueprints.todoapp.util.schedulers.ImmediateSchedulerProvider) Before(org.junit.Before)

Example 35 with Task

use of com.example.android.architecture.blueprints.todoapp.data.Task in project todo-mvp-rxjava by albertizzy.

the class TasksPresenterTest method activateTask_ShowsTaskMarkedActive.

@Test
public void activateTask_ShowsTaskMarkedActive() {
    // Given a stubbed completed task
    Task task = new Task("Details Requested", "For this task", true);
    // And no tasks available in the repository
    when(mTasksRepository.getTasks()).thenReturn(Flowable.empty());
    mTasksPresenter.loadTasks(true);
    // When task is marked as activated
    mTasksPresenter.activateTask(task);
    // Then repository is called and task marked active UI is shown
    verify(mTasksRepository).activateTask(task);
    verify(mTasksView).showTaskMarkedActive();
}
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