TaskService { public Observable<Void> active(String taskId) { return Observable.create(subscriber -> { try { mLocalAdapter.activeTask(taskId); SubscriptionUtils.onNextAndComplete(subscriber); } catch (Exception e) { SubscriptionUtils.onError(subscriber, e); } }); } TaskService(LocalAdapter localAdapter); Observable<Void> active(String taskId); Observable<Void> complete(String taskId); Observable<Task> create(String title, String description); Observable<Task> find(String taskId); Observable<List<Task>> getAll(); Observable<Task> observeTaskCreate(); Observable<Task> observeTaskRemove(); Observable<Task> observeTaskUpdate(); Observable<Void> remove(String taskId); Observable<Void> update(String taskId, String title, String description);  }
@Test public void testActiveError() throws Exception { TestSubscriber<Void> testSubscriber = new TestSubscriber<>(); DataNotFoundException exception = new DataNotFoundException(); doThrow(exception).when(mLocalAdapter).activeTask(any()); mTaskService.active("unknown").subscribe(testSubscriber); testSubscriber.assertError(exception); verify(mLocalAdapter).activeTask("unknown"); }
@Test public void testActiveSuccess() throws Exception { TestSubscriber<Void> testSubscriber = new TestSubscriber<>(); mTaskService.active("taskId").subscribe(testSubscriber); testSubscriber.assertNoErrors(); verify(mLocalAdapter).activeTask("taskId"); }