CheckoutPresenter extends BasePresenter<Checkout.View> implements Checkout.Actions { @Override public void onChangePaymentMethod() { state.paymentMethodEdited = true; userSelectionRepository.reset(); getView().transitionOut(); new OnChangePaymentMethodDriver(internalConfiguration, state, paymentRepository) .drive(new OnChangePaymentMethodDriver.ChangePaymentMethodDriverCallback() { @Override public void driveToFinishWithPaymentResult(final Integer resultCode, final Payment payment) { getView().finishWithPaymentResult(resultCode, payment); } @Override public void driveToFinishWithoutPaymentResult(final Integer resultCode) { getView().finishWithPaymentResult(resultCode, null); } @Override public void driveToShowPaymentMethodSelection() { getView().showPaymentMethodSelection(); } }); } 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 whenPaymentIsCanceledBecauseUserWantsToSelectOtherPaymentMethodThenShowPaymentMethodSelection() { presenter.onChangePaymentMethod(); verify(checkoutView).transitionOut(); verify(checkoutView).showPaymentMethodSelection(); verifyNoMoreInteractions(checkoutView); }
@Test public void whenUserSelectChangePaymentMethodFromPaymentResultAndExitOnIsTrueThenNotShowPaymentMethodSelection() { when(paymentRepository.getPayment()).thenReturn(mock(Payment.class)); when(internalConfiguration.shouldExitOnPaymentMethodChange()).thenReturn(true); presenter.onChangePaymentMethod(); verify(checkoutView).transitionOut(); verify(checkoutView) .finishWithPaymentResult(Constants.RESULT_CHANGE_PAYMENT_METHOD, (Payment) paymentRepository.getPayment()); }
@Test public void whenUserSelectChangePaymentMethodWithoutPaymentAndExitOnIsTrueThenFinishWithPaymentResultChangePaymentMethodCode() { when(internalConfiguration.shouldExitOnPaymentMethodChange()).thenReturn(true); presenter.onChangePaymentMethod(); verify(checkoutView).transitionOut(); verify(checkoutView).finishWithPaymentResult(Constants.RESULT_CHANGE_PAYMENT_METHOD, null); }