MoreBundlePresenter implements Presenter { @VisibleForTesting public void onCreateLoadBundles() { view.getLifecycleEvent() .filter(lifecycleEvent -> lifecycleEvent.equals(View.LifecycleEvent.CREATE)) .observeOn(viewScheduler) .doOnNext(created -> view.showLoading()) .flatMapSingle(created -> loadBundles()) .compose(view.bindUntilEvent(View.LifecycleEvent.DESTROY)) .subscribe(__ -> { }, crashReporter::log); } MoreBundlePresenter(MoreBundleView view, MoreBundleManager moreBundleManager,
      Scheduler viewScheduler, CrashReport crashReporter, HomeNavigator homeNavigator,
      AdMapper adMapper, BundleEvent bundleEvent, HomeAnalytics homeAnalytics,
      ChipManager chipManager); @Override void present(); @VisibleForTesting void onCreateSetupToolbar(); @VisibleForTesting void onCreateLoadBundles(); @VisibleForTesting void handleAppClick(); @VisibleForTesting void handleAdClick(); @VisibleForTesting void handleMoreClick(); @VisibleForTesting void handleBundleScrolledRight(); @VisibleForTesting void handleBottomReached(); @VisibleForTesting void handlePullToRefresh(); @VisibleForTesting void handleRetryClick();  }
@Test public void loadAllBundlesFromRepositoryAndLoadIntoView() { presenter.onCreateLoadBundles(); when(moreBundleManager.loadBundle(bundleEvent.getTitle(), bundleEvent.getAction())).thenReturn( Single.just(bundlesModel)); lifecycleEvent.onNext(View.LifecycleEvent.CREATE); verify(view).showLoading(); verify(view).showBundles(bundlesModel.getList()); verify(view).hideLoading(); }
@Test public void errorLoadingBundles_ShowsError() { presenter.onCreateLoadBundles(); when(moreBundleManager.loadBundle(bundleEvent.getTitle(), bundleEvent.getAction())).thenReturn( Single.just(new HomeBundlesModel(HomeBundlesModel.Error.GENERIC))); lifecycleEvent.onNext(View.LifecycleEvent.CREATE); verify(view).showGenericError(); }
@Test public void errorLoadingBundles_ShowsNetworkError() { presenter.onCreateLoadBundles(); when(moreBundleManager.loadBundle(bundleEvent.getTitle(), bundleEvent.getAction())).thenReturn( Single.just(new HomeBundlesModel(HomeBundlesModel.Error.NETWORK))); lifecycleEvent.onNext(View.LifecycleEvent.CREATE); verify(view).showNetworkError(); }