@Test public void getArticle_returnsRequestedArticleFromTheServer() throws Exception { final String articleId = "bnl-vkn-20161117-7352758"; final HttpUrl baseUrl = prepareAndStartServerToReturnJsonFromFile(mServer, "article(ws.blendle.com_item_" + articleId + ").json"); final DatabaseManager databaseManager = mock(DatabaseManager.class); when(databaseManager.requestArticle(anyString())) .thenReturn(Single.error(new NullPointerException())); final RequestArticlesCommand command = new RequestArticlesCommand( new ArticlesServer(baseUrl, RxJava2CallAdapterFactory. createWithScheduler(Schedulers.trampoline())), databaseManager); final Single<Article> articleObservable = command.getArticle(articleId); final TestObserver<Article> testObserver = new TestObserver<>(); articleObservable.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 Article article = (Article) events.get(0); assertEquals(articleId, article.id()); }
public Single<Article> getArticle(@NonNull final String id) { final Observable<ArticleResource> remoteArticleObservable = getArticleFromRemoteAPI(id).toObservable(); final Observable<ArticleResource> localDBArticleObservable = getArticleFromLocalDB(id); final Single<ArticleResource> articleObservable = Observable .concat(localDBArticleObservable, remoteArticleObservable).firstOrError(); return articleObservable.map(ArticlesDataMapper::convertArticleToDomain); }
RequestArticlesCommand { public Single<Article> getArticle(@NonNull final String id) { final Observable<ArticleResource> remoteArticleObservable = getArticleFromRemoteAPI(id).toObservable(); final Observable<ArticleResource> localDBArticleObservable = getArticleFromLocalDB(id); final Single<ArticleResource> articleObservable = Observable .concat(localDBArticleObservable, remoteArticleObservable).firstOrError(); return articleObservable.map(ArticlesDataMapper::convertArticleToDomain); } }
RequestArticlesCommand { public Single<Article> getArticle(@NonNull final String id) { final Observable<ArticleResource> remoteArticleObservable = getArticleFromRemoteAPI(id).toObservable(); final Observable<ArticleResource> localDBArticleObservable = getArticleFromLocalDB(id); final Single<ArticleResource> articleObservable = Observable .concat(localDBArticleObservable, remoteArticleObservable).firstOrError(); return articleObservable.map(ArticlesDataMapper::convertArticleToDomain); } RequestArticlesCommand();  RequestArticlesCommand(final ArticlesServer articlesServer, final DatabaseManager databaseManager); }
RequestArticlesCommand { public Single<Article> getArticle(@NonNull final String id) { final Observable<ArticleResource> remoteArticleObservable = getArticleFromRemoteAPI(id).toObservable(); final Observable<ArticleResource> localDBArticleObservable = getArticleFromLocalDB(id); final Single<ArticleResource> articleObservable = Observable .concat(localDBArticleObservable, remoteArticleObservable).firstOrError(); return articleObservable.map(ArticlesDataMapper::convertArticleToDomain); } 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 Single<Article> getArticle(@NonNull final String id) { final Observable<ArticleResource> remoteArticleObservable = getArticleFromRemoteAPI(id).toObservable(); final Observable<ArticleResource> localDBArticleObservable = getArticleFromLocalDB(id); final Single<ArticleResource> articleObservable = Observable .concat(localDBArticleObservable, remoteArticleObservable).firstOrError(); return articleObservable.map(ArticlesDataMapper::convertArticleToDomain); } 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);  }