PayerInformationPresenter extends BasePresenter<PayerInformation.View> implements PayerInformation.Actions { @Override public void attachView(final PayerInformation.View view) { super.attachView(view); if (state.hasIdentificationTypes()) { view.hideProgressBar(); } else { view.showProgressBar(); getIdentificationTypesAsync(); } if (state.hasFilledInfo()) { view.initializeIdentificationTypes(state.getIdentificationTypeList(), state.getIdentificationType()); view.setName(state.getIdentificationName()); view.setLastName(state.getIdentificationLastName()); view.setNumber(state.getIdentificationNumber()); view.identificationDraw(); restoreViewFocus(); } } PayerInformationPresenter(@NonNull final PayerInformationStateModel state,
        @NonNull final PaymentSettingRepository paymentSettings,
        @NonNull final IdentificationRepository identificationRepository,
        @Nullable final PaymentMethod paymentMethod); @Override void attachView(final PayerInformation.View view); void saveIdentificationNumber(final String identificationNumber); void saveIdentificationName(final String identificationName); void saveIdentificationLastName(final String identificationLastName); void saveIdentificationBusinessName(final String identificationBusinessName); int getIdentificationNumberMaxLength(); void saveIdentificationType(final IdentificationType identificationType); @Override void createPayer(); @VisibleForTesting void recoverFromFailure(); @Override void validateName(); @Override void validateLastName(); @Override void validateBusinessName(); @Override void validateIdentification(); @Override void trackAbort(); @Override void setCurrentFocus(@PayerInformationFocus final String currentFocusType); @Override void configureIdentificationTypeFlow(@NonNull final IdentificationType identificationType); @Override void validateCurrentEditText(); @Override void onSaveInstance(@NonNull final Bundle bundle); @Override void onBackPressed();  }
@Test public void whenInitializePresenterAndHasFilledInfoThenSetIt() { when(stateModel.hasFilledInfo()).thenReturn(true); when(stateModel.hasIdentificationTypes()).thenReturn(true); when(stateModel.getCurrentFocusType()).thenReturn(PayerInformationFocus.NAME_INPUT); presenter.attachView(view); verify(view).hideProgressBar(); verify(view) .initializeIdentificationTypes(stateModel.getIdentificationTypeList(), stateModel.getIdentificationType()); verify(view).setName(stateModel.getIdentificationName()); verify(view).setLastName(stateModel.getIdentificationLastName()); verify(view).setNumber(stateModel.getIdentificationNumber()); verify(view).identificationDraw(); verify(view).showIdentificationNameFocus(); verifyNoMoreInteractions(view); }
@Test public void whenInitializePresenterThenInitializeIdentificationTypes() { final List<IdentificationType> stubIdentificationTypes = IdentificationTypes.getEnabledMLBIdentificationTypes(); when(stateModel.hasIdentificationTypes()).thenReturn(false); when(identificationRepository.getIdentificationTypes()) .thenReturn(new StubSuccessMpCall<>(stubIdentificationTypes)); presenter.attachView(view); verify(view).showProgressBar(); verify(view).initializeIdentificationTypes(stubIdentificationTypes, stateModel.getIdentificationType()); verify(view).hideProgressBar(); verify(view).showIdentificationNumberFocus(); verifyNoMoreInteractions(view); }
@Test public void whenInitializePresenterAndIdentificationTypesAreEmptyThenShowMissingIdentificationTypesError() { final List<IdentificationType> stubIdentificationTypes = new ArrayList<>(); when(stateModel.hasIdentificationTypes()).thenReturn(false); when(identificationRepository.getIdentificationTypes()) .thenReturn(new StubSuccessMpCall<>(stubIdentificationTypes)); presenter.attachView(view); verify(view).showProgressBar(); verify(view).showMissingIdentificationTypesError(); verify(view).hideProgressBar(); verify(view).showIdentificationNumberFocus(); verifyNoMoreInteractions(view); }
@Test public void whenGetIdentificationTypesFailThenShowError() { final ApiException apiException = mock(ApiException.class); when(stateModel.hasIdentificationTypes()).thenReturn(false); when(identificationRepository.getIdentificationTypes()) .thenReturn(new StubFailMpCall<>(apiException)); presenter.attachView(view); verify(view).showProgressBar(); verify(view).showError(any(MercadoPagoError.class), anyString()); verifyNoMoreInteractions(view); }