CheckoutPresenter extends BasePresenter<Checkout.View> implements Checkout.Actions { @Override public void initialize() { getView().showProgress(); if (isViewAttached()) { initRepository.init().enqueue(new Callback<InitResponse>() { @Override public void success(final InitResponse initResponse) { if (isViewAttached()) { startFlow(initResponse); } } @Override public void failure(final ApiException apiException) { if (isViewAttached()) { getView().showError( new MercadoPagoError(apiException, ApiUtil.RequestOrigin.POST_INIT)); } } }); } } 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 whenCheckoutInitializedAndPaymentMethodSearchFailsThenShowError() { final ApiException apiException = mock(ApiException.class); when(initRepository.init()).thenReturn(new StubFailMpCall<>(apiException)); presenter.initialize(); verify(checkoutView).showProgress(); verify(checkoutView).showError(any(MercadoPagoError.class)); verifyNoMoreInteractions(checkoutView); }
@Test public void whenChoHasCompletePrefSetDoNotCallRepositoryToGetPreference() { final CheckoutPreference preference = stubPreferenceOneItem(); when(paymentSettingRepository.getCheckoutPreference()).thenReturn(preference); when(initRepository.init()).thenReturn(new StubSuccessMpCall<>(InitResponseStub.FULL.get())); presenter.initialize(); verifyInitializeWithPreference(); verifyNoMoreInteractions(checkoutView); }
@Test public void whenChoHasPreferenceAndPaymentMethodRetrievedShowPaymentMethodSelection() { final CheckoutPreference preference = stubPreferenceOneItemAndPayer(); when(paymentSettingRepository.getCheckoutPreference()).thenReturn(preference); when(initRepository.init()).thenReturn(new StubSuccessMpCall<>(InitResponseStub.FULL.get())); presenter.initialize(); verify(initRepository).init(); verifyInitializeWithPreference(); verifyNoMoreInteractions(checkoutView); verifyNoMoreInteractions(initRepository); }