CheckoutPresenter extends BasePresenter<Checkout.View> implements Checkout.Actions { @Override public void onPaymentResultResponse(@Nullable final Integer customResultCode) { new PostCongratsDriver.Builder(paymentSettingRepository, paymentRepository) .customResponseCode(customResultCode) .action(new PostCongratsDriver.Action() { @Override public void goToLink(@NonNull final String link) { getView().goToLink(link); } @Override public void openInWebView(@NonNull final String link) { getView().openInWebView(link); } @Override public void exitWith(@Nullable final Integer customResponseCode, @Nullable final Payment payment) { getView().finishWithPaymentResult(customResultCode, payment); } }).build().execute(); } CheckoutPresenter(@NonNull final CheckoutStateModel persistentData,
        @NonNull final PaymentSettingRepository paymentSettingRepository,
        @NonNull final UserSelectionRepository userSelectionRepository,
        @NonNull final InitRepository initRepository,
        @NonNull final PluginRepository pluginRepository,
        @NonNull final PaymentRepository paymentRepository,
        @NonNull final CongratsRepository congratsRepository,
        @NonNull final InternalConfiguration internalConfiguration); @NonNull CheckoutStateModel getState(); @Override void initialize(); @Override void onErrorCancel(@Nullable final MercadoPagoError mercadoPagoError); @Override void onPaymentMethodSelectionError(final MercadoPagoError mercadoPagoError); @Override void onPaymentMethodSelectionCancel(); @Override void onReviewAndConfirmCancel(); @Override void onReviewAndConfirmError(final MercadoPagoError mercadoPagoError); @Override void onCardFlowResponse(); @Override void onTerminalError(@NonNull final MercadoPagoError mercadoPagoError); @Override void onCardFlowCancel(); @Override void onCustomReviewAndConfirmResponse(final Integer customResultCode); @Override void recoverFromFailure(); @Override void setFailureRecovery(final FailureRecovery failureRecovery); @Override void onPaymentResultResponse(@Nullable final Integer customResultCode); @Override void cancelCheckout(); @Override boolean isUniquePaymentMethod(); @Override void onChangePaymentMethod(); @Override void onCardAdded(@NonNull final String cardId, @NonNull final LifecycleListener.Callback callback);  }
@Test public void whenPaymentResultWithCreatedPaymentThenFinishCheckoutWithPaymentResult() { final Payment payment = mock(Payment.class); when(paymentRepository.getPayment()).thenReturn(payment); presenter.onPaymentResultResponse(null); verify(checkoutView).finishWithPaymentResult(null, payment); }
@Test public void whenPaymentResultWithoutCreatedPaymentThenFinishCheckoutWithoutPaymentResult() { presenter.onPaymentResultResponse(null); verify(checkoutView).finishWithPaymentResult(null, null); }
@Test public void whenCustomPaymentResultResponseHasPaymentThenFinishWithPaymentResult() { final Payment payment = mock(Payment.class); when(paymentRepository.getPayment()).thenReturn(payment); presenter.onPaymentResultResponse(CUSTOM_RESULT_CODE); verify(checkoutView).finishWithPaymentResult(CUSTOM_RESULT_CODE, payment); verifyNoMoreInteractions(checkoutView); }
@Test public void whenCustomPaymentResultResponseHasNotPaymentThenFinishWithPaymentResult() { presenter.onPaymentResultResponse(CUSTOM_RESULT_CODE); verify(checkoutView).finishWithPaymentResult(CUSTOM_RESULT_CODE, null); verifyNoMoreInteractions(checkoutView); }
@Test public void whenCustomPaymentResultResponseHasBusinessPaymentThenFinishWithPaymentResult() { final BusinessPayment payment = mock(BusinessPayment.class); when(paymentRepository.getPayment()).thenReturn(payment); presenter.onPaymentResultResponse(CUSTOM_RESULT_CODE); verify(checkoutView).finishWithPaymentResult(CUSTOM_RESULT_CODE, null); verifyNoMoreInteractions(checkoutView); }