SearchPresenter extends BasePresenter { public void loadPostIdListBySearch(String keyword, String dateRange, int page, boolean isSortByDate) { mCompositeSubscription.add( mDataManager.getSearchResult(keyword, "created_at_i>" + dateRange.substring(0, 10) + "," + "created_at_i<" + dateRange.substring(10), page, isSortByDate) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<HNItem.SearchResult>() { @Override public void call(HNItem.SearchResult searchResult) { if (searchResult.getHits().length == 0) { mSearchView.hideSwipeRefresh(); mSearchView.updatePrompt(R.string.no_search_result_prompt); updateLoadingState(Constants.LOADING_PROMPT_NO_CONTENT); return; } List<Long> list = new ArrayList<>(); mSearchResultTotalPages = searchResult.getNbPages(); for (int i = 0; i < searchResult.getHits().length; i++) { list.add(searchResult.getHits()[i].getObjectID()); } mPostIdList.clear(); mPostIdList.addAll(list); loadPosts(list, true); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { mSearchView.hideSwipeRefresh(); mSearchView.showErrorLog("loadPostIdListBySearch", throwable.toString()); } })); } SearchPresenter(@NonNull SearchView searchView);  SearchPresenter(@NonNull SearchView searchView, @NonNull DataManager dataManager,
                           @NonNull SharedPrefsContract prefsManager, @NonNull UtilsContract utils); void setView(SearchView searchView); void setDataManager(DataManager dataManager); void setPrefsManager(SharedPrefsContract sharedPrefsContract); void setUtils(UtilsContract utils); @Override void setup(); @Override void restoreState(Bundle savedInstanceState); @Override void saveState(Bundle outState); @Override void destroy(); @Override void unsubscribe(); void refresh(); void refresh(String dateRange); void refresh(boolean isSortByDate); void refresh(String keyword, String dateRange, boolean isSortByDate); void loadPostIdListBySearch(String keyword, String dateRange, int page, boolean isSortByDate); String getKeyword(); void setKeyword(String keyword); String getDateRange(); void setDateRange(String dateRange); boolean isSortByDate(); void setSortByDate(boolean isSortByDate); void updateCachedPostList(); List<Post> getCachedPosts(); void loadMore(); void setShowPostSummaryPref(); static final String TAG; }
@Test public void getSearchResultsEmpty() { HNItem.SearchResult result = new HNItem.SearchResult(); result.setHits(new HNItem.SearchHit[]{}); when(mDataManager.getSearchResult("1", "created_at_i>" + "0123456789" + "," + "created_at_i<" + "0", 1, true)) .thenReturn(Observable.just(result)); mPresenter.loadPostIdListBySearch("1", "01234567890", 1, true); verify(mSearchView).hideSwipeRefresh(); verify(mSearchView).updatePrompt(R.string.no_search_result_prompt); }