CheckoutPresenter extends BasePresenter<Checkout.View> implements Checkout.Actions { void startFlow(final PaymentMethodSearch paymentMethodSearch) { new DefaultPaymentMethodDriver(paymentMethodSearch, paymentSettingRepository.getCheckoutPreference().getPaymentPreference()) .drive(new DefaultPaymentMethodDriver.PaymentMethodDriverCallback() { @Override public void driveToCardVault(@NonNull final Card card) { userSelectionRepository.select(card, null); getView().showSavedCardFlow(card); } @Override public void driveToNewCardFlow(final String defaultPaymentTypeId) { userSelectionRepository.select(defaultPaymentTypeId); getView().showNewCardFlow(); } @Override public void doNothing() { noDefaultPaymentMethods(paymentMethodSearch); } }); } 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 whenDefaultCardIdValidSelectedThenShowSecurityCode() { final InitResponse search = mockPaymentMethodSearchForDriver(true); presenter.startFlow(search); verify(checkoutView).showSavedCardFlow(any(Card.class)); }
@Test public void whenDefaultCardIdInvalidSelectedThenShowPaymentVault() { final InitResponse search = mockPaymentMethodSearchForDriver(false); presenter.startFlow(search); verify(checkoutView).showPaymentMethodSelection(); }
@Test public void whenDefaultCardIdIsNullAndDefaultPaymentTypeIsValidThenShowNewCardFlow() { final InitResponse search = mockPaymentMethodSearchForNewCardDriver(); presenter.startFlow(search); verify(checkoutView).showNewCardFlow(); }