@Override public void onTextChanged(String text) { if (isPostalCodeMaximalLength(true, text) && mCardInputListener != null) { mCardInputListener.onPostalCodeComplete(); } mPostalCodeEditText.setShouldShowError(false); } });
/** * This test should change when we allow and validate postal codes outside of the US * in this control. */ @Test public void isPostalCodeMaximalLength_whenNotZip_returnsFalse() { assertFalse(CardMultilineWidget.isPostalCodeMaximalLength(false, "12345")); }
@Test public void isPostalCodeMaximalLength_whenZipEnteredAndIsMaximalLength_returnsTrue() { assertTrue(CardMultilineWidget.isPostalCodeMaximalLength(true, "12345")); }
@Test public void isPostalCodeMaximalLength_whenZipEnteredAndIsEmpty_returnsFalse() { assertFalse(CardMultilineWidget.isPostalCodeMaximalLength(true, "")); }
@Test public void isPostalCodeMaximalLength_whenZipEnteredAndIsNull_returnsFalse() { assertFalse(CardMultilineWidget.isPostalCodeMaximalLength(true, null)); }
@Test public void isPostalCodeMaximalLength_whenZipEnteredAndIsNotMaximalLength_returnsFalse() { assertFalse(CardMultilineWidget.isPostalCodeMaximalLength(true, "123")); }
/** * Validates all fields and shows error messages if appropriate. * * @return {@code true} if all shown fields are valid, {@code false} otherwise */ public boolean validateAllFields() { boolean cardNumberIsValid = CardUtils.isValidCardNumber(mCardNumberEditText.getCardNumber()); boolean expiryIsValid = mExpiryDateEditText.getValidDateFields() != null && mExpiryDateEditText.isDateValid(); boolean cvcIsValid = isCvcLengthValid(); mCardNumberEditText.setShouldShowError(!cardNumberIsValid); mExpiryDateEditText.setShouldShowError(!expiryIsValid); mCvcEditText.setShouldShowError(!cvcIsValid); boolean postalCodeIsValidOrGone; if (mShouldShowPostalCode) { postalCodeIsValidOrGone = isPostalCodeMaximalLength(true, mPostalCodeEditText.getText().toString()); mPostalCodeEditText.setShouldShowError(!postalCodeIsValidOrGone); } else { postalCodeIsValidOrGone = true; } return cardNumberIsValid && expiryIsValid && cvcIsValid && postalCodeIsValidOrGone; }