CardVaultPresenter extends BasePresenter<CardVault.View> implements CardVault.Actions { @Override public void initialize() { if (tokenRecoveryAvailable()) { startTokenRecoveryFlow(); } else if (getCard() == null) { startNewCardFlow(); } else { startSavedCardFlow(); } } CardVaultPresenter(@NonNull final UserSelectionRepository userSelectionRepository,
        @NonNull final PaymentSettingRepository paymentSettingRepository,
        @NonNull final ESCManagerBehaviour escManagerBehaviour,
        @NonNull final AmountConfigurationRepository amountConfigurationRepository,
        @NonNull final CardTokenRepository cardTokenRepository); @Override void initialize(); @Override void setPaymentRecovery(final PaymentRecovery paymentRecovery); @Override void setCard(@Nullable final Card card); @Override @Nullable Token getToken(); @Override void setToken(final Token mToken); @Override @Nullable PaymentMethod getPaymentMethod(); @Override void setPaymentMethod(final PaymentMethod mPaymentMethod); @Override @Nullable PaymentRecovery getPaymentRecovery(); @Override @Nullable Card getCard(); @Override void setCardInfo(final CardInfo cardInfo); @Override @Nullable CardInfo getCardInfo(); @Override int getCardNumberLength(); @Override void resolveInstallmentsRequest(); @Override void resolveSecurityCodeRequest(); @Override void resolveNewCardRequest(@NonNull final Intent data); @Override void onResultCancel(); @Override void onResultFinishOnError();  }
@Test public void whenSavedCardNotPresentThenStartGuessingFlow() { presenter.initialize(); verify(view).askForCardInformation(); verifyNoMoreInteractions(view); }
@Test public void verifyResolvesEmptyPayerCostList() { configureMockedCard(); presenter.initialize(); verify(view).showEmptyPayerCostScreen(); verifyNoMoreInteractions(view); }
@Test public void whenOnlyOnePayerCostThenSelectsAndAsksForSecCode() { configureMockedCard(); final List<PayerCost> payerCosts = Collections.singletonList(mock(PayerCost.class)); when(amountConfiguration.getPayerCosts()).thenReturn(payerCosts); presenter.initialize(); verify(view).finishWithResult(); verifyNoMoreInteractions(view); }
@Test public void verifyResolvesDisplayInstallments() { configureMockedCard(); final List<PayerCost> payerCosts = Arrays.asList(mock(PayerCost.class), mock(PayerCost.class)); when(amountConfiguration.getPayerCosts()).thenReturn(payerCosts); presenter.initialize(); verify(view).askForInstallments(any(CardInfo.class)); verifyNoMoreInteractions(view); }
@Test public void whenIsOneTapFlowThenDontAskForInstallmentsAndContinueFlow() { configureMockedCard(); when(userSelectionRepository.getPayerCost()).thenReturn(mock(PayerCost.class)); presenter.initialize(); verifyNoMoreInteractions(amountConfigurationRepository); }