@Test public void testGetTopStoriesSuccess() { when(TestRestServiceFactory.hnRestService.topStoriesRx()) .thenReturn(Observable.just(new int[]{1, 2})); client.getStories(ItemManager.TOP_FETCH_MODE, ItemManager.MODE_DEFAULT, storiesListener); verify(TestRestServiceFactory.hnRestService).topStoriesRx(); verify(storiesListener).onResponse(getStoriesResponse.capture()); assertThat(getStoriesResponse.getValue()).hasSize(2); }
@Override public void getStories(@FetchMode String filter, @CacheMode int cacheMode, final ResponseListener<Item[]> listener) { if (listener == null) { return; } Observable.defer(() -> getStoriesObservable(filter, cacheMode)) .subscribeOn(mIoScheduler) .observeOn(mMainThreadScheduler) .subscribe(listener::onResponse, t -> listener.onError(t != null ? t.getMessage() : "")); }
HackerNewsClient implements ItemManager, UserManager { @Override public void getStories(@FetchMode String filter, @CacheMode int cacheMode, final ResponseListener<Item[]> listener) { if (listener == null) { return; } Observable.defer(() -> getStoriesObservable(filter, cacheMode)) .subscribeOn(mIoScheduler) .observeOn(mMainThreadScheduler) .subscribe(listener::onResponse, t -> listener.onError(t != null ? t.getMessage() : "")); } }
HackerNewsClient implements ItemManager, UserManager { @Override public void getStories(@FetchMode String filter, @CacheMode int cacheMode, final ResponseListener<Item[]> listener) { if (listener == null) { return; } Observable.defer(() -> getStoriesObservable(filter, cacheMode)) .subscribeOn(mIoScheduler) .observeOn(mMainThreadScheduler) .subscribe(listener::onResponse, t -> listener.onError(t != null ? t.getMessage() : "")); } @Inject  HackerNewsClient(RestServiceFactory factory,
                            SessionManager sessionManager,
                            FavoriteManager favoriteManager); }
HackerNewsClient implements ItemManager, UserManager { @Override public void getStories(@FetchMode String filter, @CacheMode int cacheMode, final ResponseListener<Item[]> listener) { if (listener == null) { return; } Observable.defer(() -> getStoriesObservable(filter, cacheMode)) .subscribeOn(mIoScheduler) .observeOn(mMainThreadScheduler) .subscribe(listener::onResponse, t -> listener.onError(t != null ? t.getMessage() : "")); } @Inject  HackerNewsClient(RestServiceFactory factory,
                            SessionManager sessionManager,
                            FavoriteManager favoriteManager); @Override void getStories(@FetchMode String filter, @CacheMode int cacheMode,
                           final ResponseListener<Item[]> listener); @Override void getItem(final String itemId, @CacheMode int cacheMode, ResponseListener<Item> listener); @Override Item[] getStories(String filter, @CacheMode int cacheMode); @Override Item getItem(String itemId, @CacheMode int cacheMode); @Override void getUser(String username, final ResponseListener<User> listener); }
HackerNewsClient implements ItemManager, UserManager { @Override public void getStories(@FetchMode String filter, @CacheMode int cacheMode, final ResponseListener<Item[]> listener) { if (listener == null) { return; } Observable.defer(() -> getStoriesObservable(filter, cacheMode)) .subscribeOn(mIoScheduler) .observeOn(mMainThreadScheduler) .subscribe(listener::onResponse, t -> listener.onError(t != null ? t.getMessage() : "")); } @Inject  HackerNewsClient(RestServiceFactory factory,
                            SessionManager sessionManager,
                            FavoriteManager favoriteManager); @Override void getStories(@FetchMode String filter, @CacheMode int cacheMode,
                           final ResponseListener<Item[]> listener); @Override void getItem(final String itemId, @CacheMode int cacheMode, ResponseListener<Item> listener); @Override Item[] getStories(String filter, @CacheMode int cacheMode); @Override Item getItem(String itemId, @CacheMode int cacheMode); @Override void getUser(String username, final ResponseListener<User> listener); static final String HOST; static final String BASE_WEB_URL; static final String WEB_ITEM_PATH; }