EditorialListPresenter implements Presenter { @VisibleForTesting public void handleUserReaction() { view.getLifecycleEvent() .filter(lifecycleEvent -> lifecycleEvent.equals(View.LifecycleEvent.CREATE)) .flatMap(created -> view.reactionClicked()) .doOnNext(__ -> userFeedbackAnalytics.sendReactionEvent()) .flatMap( reactionsHomeEvent -> editorialListManager.setReaction(reactionsHomeEvent.getCardId(), reactionsHomeEvent.getGroupId(), reactionsHomeEvent.getReaction()) .toObservable() .filter(ReactionsResponse::differentReaction) .observeOn(viewScheduler) .doOnNext(reactionsResponse -> handleReactionsResponse(reactionsResponse, false)) .filter(ReactionsResponse::wasSuccess) .flatMapSingle(__ -> loadReactionModel(reactionsHomeEvent.getCardId(), reactionsHomeEvent.getGroupId()))) .compose(view.bindUntilEvent(View.LifecycleEvent.DESTROY)) .subscribe(lifecycleEvent -> { }, crashReporter::log); } EditorialListPresenter(EditorialListView editorialListView,
      EditorialListManager editorialListManager, AptoideAccountManager accountManager,
      EditorialListNavigator editorialListNavigator, EditorialListAnalytics editorialListAnalytics,
      CrashReport crashReporter, Scheduler viewScheduler,
      UserFeedbackAnalytics userFeedbackAnalytics); @Override void present(); @VisibleForTesting void onCreateLoadViewModel(); @VisibleForTesting void loadUserImage(); @VisibleForTesting void handleEditorialCardClick(); @VisibleForTesting void handlePullToRefresh(); @VisibleForTesting void handleRetryClick(); @VisibleForTesting void handleImpressions(); @VisibleForTesting void handleBottomReached(); @VisibleForTesting void handleUserImageClick(); @VisibleForTesting void handleReactionButtonClick(); @VisibleForTesting void handleUserReaction(); @VisibleForTesting void handleSnackLogInClick();  }
@Test public void handleUserReactionTest() { CurationCard curationCard = new CurationCard("1", "sub", "icon", "title", "1000", GROUP_ID, "2018-11-29 17:14:56", ""); presenter.handleUserReaction(); lifecycleEvent.onNext(View.LifecycleEvent.CREATE); when(editorialListManager.setReaction("1", GROUP_ID, "laugh")).thenReturn( Single.just(new ReactionsResponse(ReactionsResponse.ReactionResponseMessage.SUCCESS))); when(editorialListManager.loadReactionModel("1", GROUP_ID)).thenReturn( Single.just(curationCard)); reactionClickEvent.onNext( new ReactionsHomeEvent("1", GROUP_ID, null, 1, HomeEvent.Type.REACT_LONG_PRESS, "laugh")); verify(editorialListAnalytics).sendReactedEvent(); verify(editorialListManager).loadReactionModel("1", GROUP_ID); verify(view).updateEditorialCard(curationCard); }
@Test public void handleReactionsExceeded() { presenter.handleUserReaction(); lifecycleEvent.onNext(View.LifecycleEvent.CREATE); when(editorialListManager.setReaction("1", GROUP_ID, "laugh")).thenReturn(Single.just( new ReactionsResponse(ReactionsResponse.ReactionResponseMessage.REACTIONS_EXCEEDED))); reactionClickEvent.onNext( new ReactionsHomeEvent("1", GROUP_ID, null, 1, HomeEvent.Type.REACT_LONG_PRESS, "laugh")); verify(view).showLogInDialog(); }
@Test public void handleNetworkError() { presenter.handleUserReaction(); lifecycleEvent.onNext(View.LifecycleEvent.CREATE); when(editorialListManager.setReaction("1", GROUP_ID, "laugh")).thenReturn(Single.just( new ReactionsResponse(ReactionsResponse.ReactionResponseMessage.NETWORK_ERROR))); reactionClickEvent.onNext( new ReactionsHomeEvent("1", GROUP_ID, null, 1, HomeEvent.Type.REACT_LONG_PRESS, "laugh")); verify(view).showNetworkErrorToast(); }
@Test public void handleGeneralError() { presenter.handleUserReaction(); lifecycleEvent.onNext(View.LifecycleEvent.CREATE); when(editorialListManager.setReaction("1", GROUP_ID, "laugh")).thenReturn(Single.just( new ReactionsResponse(ReactionsResponse.ReactionResponseMessage.GENERAL_ERROR))); reactionClickEvent.onNext( new ReactionsHomeEvent("1", GROUP_ID, null, 1, HomeEvent.Type.REACT_LONG_PRESS, "laugh")); verify(view).showGenericErrorToast(); }