@Test public void getPopularArticles_returnsListOfArticles() throws Exception { final HttpUrl baseUrl = prepareAndStartServerToReturnJsonFromFile(mServer, "popular(ws.blendle.com_items_popular).json"); final DatabaseManager databaseManager = mock(DatabaseManager.class); when(databaseManager.requestPopularArticles(anyInt(), anyInt())) .thenReturn(Single.error(new NullPointerException())); final RequestArticlesCommand command = new RequestArticlesCommand( new ArticlesServer(baseUrl, RxJava2CallAdapterFactory. createWithScheduler(Schedulers.trampoline())), databaseManager); final Observable<List<Article>> popularArticlesObservable = command.getPopularArticles(null, null); final TestObserver<List<Article>> testObserver = new TestObserver<>(); popularArticlesObservable.subscribe(testObserver); testObserver.await(2, TimeUnit.SECONDS); final List<Object> events = testObserver.getEvents().get(0); testObserver.assertNoErrors(); assertTrue("There should only one event with the request results", events.size() == 1); final List<Article> popularArticles = (List<Article>) events.get(0); assertThat("No articles loaded", popularArticles.size(), greaterThan(0)); }
public Observable<List<Article>> getPopularArticles(@Nullable final Integer amount, @Nullable final Integer page) { final Single<PopularArticlesResource> remotePopularArticlesObservable = getPopularArticlesFromRemoteAPI(amount, page); final Observable<PopularArticlesResource> localDBPopularArticlesObservable = getPopularArticlesFromLocalDB(amount, page); final Observable<PopularArticlesResource> popularArticlesObservable = getPopularArticlesFromCombinedSources(remotePopularArticlesObservable, localDBPopularArticlesObservable); return popularArticlesObservable .distinct() .map(ArticlesDataMapper::convertPopularArticlesListToDomain); }
RequestArticlesCommand { public Observable<List<Article>> getPopularArticles(@Nullable final Integer amount, @Nullable final Integer page) { final Single<PopularArticlesResource> remotePopularArticlesObservable = getPopularArticlesFromRemoteAPI(amount, page); final Observable<PopularArticlesResource> localDBPopularArticlesObservable = getPopularArticlesFromLocalDB(amount, page); final Observable<PopularArticlesResource> popularArticlesObservable = getPopularArticlesFromCombinedSources(remotePopularArticlesObservable, localDBPopularArticlesObservable); return popularArticlesObservable .distinct() .map(ArticlesDataMapper::convertPopularArticlesListToDomain); } }
RequestArticlesCommand { public Observable<List<Article>> getPopularArticles(@Nullable final Integer amount, @Nullable final Integer page) { final Single<PopularArticlesResource> remotePopularArticlesObservable = getPopularArticlesFromRemoteAPI(amount, page); final Observable<PopularArticlesResource> localDBPopularArticlesObservable = getPopularArticlesFromLocalDB(amount, page); final Observable<PopularArticlesResource> popularArticlesObservable = getPopularArticlesFromCombinedSources(remotePopularArticlesObservable, localDBPopularArticlesObservable); return popularArticlesObservable .distinct() .map(ArticlesDataMapper::convertPopularArticlesListToDomain); } RequestArticlesCommand();  RequestArticlesCommand(final ArticlesServer articlesServer, final DatabaseManager databaseManager); }
RequestArticlesCommand { public Observable<List<Article>> getPopularArticles(@Nullable final Integer amount, @Nullable final Integer page) { final Single<PopularArticlesResource> remotePopularArticlesObservable = getPopularArticlesFromRemoteAPI(amount, page); final Observable<PopularArticlesResource> localDBPopularArticlesObservable = getPopularArticlesFromLocalDB(amount, page); final Observable<PopularArticlesResource> popularArticlesObservable = getPopularArticlesFromCombinedSources(remotePopularArticlesObservable, localDBPopularArticlesObservable); return popularArticlesObservable .distinct() .map(ArticlesDataMapper::convertPopularArticlesListToDomain); } RequestArticlesCommand();  RequestArticlesCommand(final ArticlesServer articlesServer, final DatabaseManager databaseManager); Observable<List<Article>> getPopularArticles(@Nullable final Integer amount,
                                                        @Nullable final Integer page); Single<Article> getArticle(@NonNull final String id); }
RequestArticlesCommand { public Observable<List<Article>> getPopularArticles(@Nullable final Integer amount, @Nullable final Integer page) { final Single<PopularArticlesResource> remotePopularArticlesObservable = getPopularArticlesFromRemoteAPI(amount, page); final Observable<PopularArticlesResource> localDBPopularArticlesObservable = getPopularArticlesFromLocalDB(amount, page); final Observable<PopularArticlesResource> popularArticlesObservable = getPopularArticlesFromCombinedSources(remotePopularArticlesObservable, localDBPopularArticlesObservable); return popularArticlesObservable .distinct() .map(ArticlesDataMapper::convertPopularArticlesListToDomain); } RequestArticlesCommand();  RequestArticlesCommand(final ArticlesServer articlesServer, final DatabaseManager databaseManager); Observable<List<Article>> getPopularArticles(@Nullable final Integer amount,
                                                        @Nullable final Integer page); Single<Article> getArticle(@NonNull final String id);  }