PostsPresenter { public void loadPostsFromAPI() { postsAPI.getPostsObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers .mainThread()) .subscribe(new Subscriber<List<Post>>() { @Override public void onNext(List<Post> newPosts) { EventBus.getDefault().post(new NewPostsEvent(newPosts)); } @Override public void onCompleted() { } @Override public void onError(Throwable e) { EventBus.getDefault().post(new ErrorEvent()); } }); } @Inject  PostsPresenter(PostsAPI postsAPI); void loadPostsFromAPI();  }
@Test public void testShouldSchedulePostsLoadFromAPIOnBackgroundThread() { Observable<List<Post>> postsObservable = (Observable<List<Post>>) mock(Observable.class); when(postsPresenter.postsAPI.getPostsObservable()).thenReturn(postsObservable); when(postsObservable.subscribeOn(Schedulers.io())).thenReturn(postsObservable); when(postsObservable.observeOn(AndroidSchedulers.mainThread())).thenReturn(postsObservable); postsPresenter.loadPostsFromAPI(); verify(postsPresenter.postsAPI).getPostsObservable(); verify(postsObservable).subscribeOn(Schedulers.io()); verify(postsObservable).observeOn(AndroidSchedulers.mainThread()); verify(postsObservable).subscribe(Matchers.<Subscriber<List<Post>>>any()); }