InstallmentsPresenter extends BasePresenter<InstallmentsView> implements
    AmountView.OnClick, InstallmentsAdapter.ItemListener, AmountRowController.AmountRowVisibilityBehaviour { public void initialize() { showSiteRelatedInformation(); resolvePayerCosts(); } InstallmentsPresenter(@NonNull final AmountRepository amountRepository,
        @NonNull final PaymentSettingRepository configuration,
        @NonNull final UserSelectionRepository userSelectionRepository,
        @NonNull final DiscountRepository discountRepository,
        @NonNull final SummaryAmountRepository summaryAmountRepository,
        @NonNull final AmountConfigurationRepository amountConfigurationRepository); void initialize(); @Override void showAmountRow(); @Override void hideAmountRow(); @Nullable CardInfo getCardInfo(); void setCardInfo(@Nullable final CardInfo cardInfo); int getCardNumberLength(); FailureRecovery getFailureRecovery(); void setFailureRecovery(final FailureRecovery failureRecovery); @Nullable PaymentMethod getPaymentMethod(); String getBin(); void recoverFromFailure(); @Override void onDetailClicked(@NonNull final DiscountConfigurationModel discountModel); @Override void onClick(final PayerCost payerCostSelected); void removeUserSelection();  }
@Test public void whenIsGuessingFlowThenCallSummaryAmount() { when(userSelectionRepository.hasCardSelected()).thenReturn(false); presetApiError(); presenter.initialize(); verify(view).showLoadingView(); verify(summaryAmountRepository).getSummaryAmount(anyString()); }
@Test public void whenIsGuessingFlowAndApiCallFailedThenShowErrorScreen() { when(userSelectionRepository.hasCardSelected()).thenReturn(false); final ApiException apiException = presetApiError(); presenter.initialize(); verify(view).showLoadingView(); verify(view).hideLoadingView(); verify(view).showApiErrorScreen(apiException, ApiUtil.RequestOrigin.POST_SUMMARY_AMOUNT); verifyNoMoreInteractions(view); }
@Test public void whenMCOThenShowBankInterestsNotCoveredWarning() { when(paymentSettingRepository.getSite()).thenReturn(Sites.COLOMBIA); when(userSelectionRepository.hasCardSelected()).thenReturn(false); final SummaryAmount response = StubSummaryAmount.getSummaryAmountTwoPayerCosts(); when(summaryAmountRepository.getSummaryAmount(anyString())).thenReturn(new StubSuccessMpCall<>(response)); presenter.initialize(); verify(view).warnAboutBankInterests(); }
@Test public void whenCardSelectedThenResolvePayerCosts() { final List<PayerCost> payerCosts = Collections.emptyList(); when(userSelectionRepository.hasCardSelected()).thenReturn(true); when(amountConfiguration.getPayerCosts()).thenReturn(payerCosts); presenter.initialize(); verify(view).hideLoadingView(); }
@Test public void whenCardSelectedAndNoPayerCostsThenShowError() { final List<PayerCost> payerCosts = Collections.emptyList(); when(userSelectionRepository.hasCardSelected()).thenReturn(true); when(amountConfiguration.getPayerCosts()).thenReturn(payerCosts); presenter.initialize(); verify(view).hideLoadingView(); verify(view).showAmount(discountConfigurationModel, BigDecimal.TEN, paymentSettingRepository.getCurrency()); verify(view).showErrorNoPayerCost(); verifyNoMoreInteractions(view); }
@Test public void whenCardSelectedAndOnlyOnePayerCostThenSelectAndFinish() { final PayerCost selectedPayerCost = mock(PayerCost.class); final List<PayerCost> payerCosts = Collections.singletonList(selectedPayerCost); when(userSelectionRepository.hasCardSelected()).thenReturn(true); when(amountConfiguration.getPayerCosts()).thenReturn(payerCosts); presenter.initialize(); verify(userSelectionRepository).select(selectedPayerCost); verify(view).hideLoadingView(); verify(view).showAmount(discountConfigurationModel, amountRepository.getItemsPlusCharges(anyString()), paymentSettingRepository.getCurrency()); verify(view).finishWithResult(); verifyNoMoreInteractions(view); }
@Test public void whenCardSelectedAndMultiplePayerCostThenDisplayThem() { final List<PayerCost> payerCosts = Arrays.asList(mock(PayerCost.class), mock(PayerCost.class)); final List<InstallmentRowHolder.Model> models = new InstallmentViewModelMapper(paymentSettingRepository.getCurrency(), null).map(payerCosts); when(userSelectionRepository.hasCardSelected()).thenReturn(true); when(amountConfiguration.getPayerCosts()).thenReturn(payerCosts); presenter.initialize(); verify(view).hideLoadingView(); verify(view).showAmount(discountConfigurationModel, amountRepository.getItemsPlusCharges(anyString()), paymentSettingRepository.getCurrency()); verify(view).showInstallments(ReflectionArgumentMatchers.reflectionEquals(models)); verifyNoMoreInteractions(view); }
@Test public void whenAmountRowIsEnabledItShouldBeSetted() { when(userSelectionRepository.hasCardSelected()).thenReturn(true); when(advancedConfiguration.isAmountRowEnabled()).thenReturn(true); presenter.initialize(); verify(view).showAmount(discountConfigurationModel, amountRepository.getItemsPlusCharges(anyString()), paymentSettingRepository.getCurrency()); }
@Test public void whenAmountRowIsEnabledItShouldBeSettedWithGuessedCards() { when(userSelectionRepository.hasCardSelected()).thenReturn(false); final SummaryAmount response = StubSummaryAmount.getSummaryAmountTwoPayerCosts(); when(summaryAmountRepository.getSummaryAmount(anyString())).thenReturn(new StubSuccessMpCall<>(response)); when(advancedConfiguration.isAmountRowEnabled()).thenReturn(true); presenter.initialize(); verify(view).showAmount(discountConfigurationModel, amountRepository.getItemsPlusCharges(anyString()), paymentSettingRepository.getCurrency()); verify(view).hideLoadingView(); }