Uploaded image for project: 'Hibernate Validator'
  1. HV-906

org.hibernate.validator.constraints.CreditCardNumber does not fail on a non-numbers string

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 4.3.2.Final
    • Fix Version/s: 5.1.2.Final, 5.2.0.Alpha1
    • Component/s: validators
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      The test invalidTextTest fails.

      import static org.junit.Assert.assertEquals;
       
      import javax.validation.Validation;
      import javax.validation.Validator;
      import javax.validation.ValidatorFactory;
       
      import org.hibernate.validator.constraints.CreditCardNumber;
      import org.junit.BeforeClass;
      import org.junit.Test;
       
      public class CreditCardNumberValidatorTest {
          private static Validator validator;
       
          @BeforeClass
          public static void setUp() {
              ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
              validator = factory.getValidator();
          }
       
          // Ok
          @Test
          public void validCardTest() {
              User user = new User();
              user.setCardNumber("4111111111111111");
              assertEquals(0, validator.validate(user).size());
          }
       
          public void invalidNumberTest() {
              User user = new User();
              user.setCardNumber("400");
              assertEquals(1, validator.validate(user).size());
          }
       
          @Test
          public void invalidTextTest() {
              User user = new User();
              user.setCardNumber("text not numbers");
              assertEquals(1, validator.validate(user).size());
          }
      }
       
      class User {
          @CreditCardNumber
          public String cardNumber;
       
          public String getCardNumber() {
              return cardNumber;
          }
       
          public void setCardNumber(String cardNumber) {
              this.cardNumber = cardNumber;
          }
      }
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: