/** * Checks whether or not the {@link #cvc} field is valid. * * @return {@code true} if valid, {@code false} otherwise */ public boolean validateCVC() { if (StripeTextUtils.isBlank(cvc)) { return false; } String cvcValue = cvc.trim(); String updatedType = getBrand(); boolean validLength = (updatedType == null && cvcValue.length() >= 3 && cvcValue.length() <= 4) || (AMERICAN_EXPRESS.equals(updatedType) && cvcValue.length() == 4) || cvcValue.length() == 3; return ModelUtils.isWholePositiveNumber(cvcValue) && validLength; }
@Test public void wholePositiveNumberShouldFailIfNegative() { assertFalse(ModelUtils.isWholePositiveNumber("-1")); }
@Test public void wholePositiveNumberShouldPassWithLeadingZero() { assertTrue(ModelUtils.isWholePositiveNumber("000")); }
@Test public void wholePositiveNumberShouldPass() { assertTrue(ModelUtils.isWholePositiveNumber("123")); }
@Test public void wholePositiveNumberShouldFailIfLetters() { assertFalse(ModelUtils.isWholePositiveNumber("1a")); }
@Test public void wholePositiveNumberShouldFailNull() { assertFalse(ModelUtils.isWholePositiveNumber(null)); }
@Test public void wholePositiveNumberShouldPassIfEmpty() { assertTrue(ModelUtils.isWholePositiveNumber("")); }