diff --git a/javaxval/src/main/java/sample/model/User.java b/javaxval/src/main/java/sample/model/User.java index 889ddd89c4..49d03d27ee 100644 --- a/javaxval/src/main/java/sample/model/User.java +++ b/javaxval/src/main/java/sample/model/User.java @@ -14,7 +14,7 @@ public class User { @AssertTrue private boolean working; - @Size(min = 10, max = 200, message = "About me should not exceed more than 10 characters") + @Size(min = 10, max = 200, message = "Number of characters should be in between 10 and 200 inclusive") private String aboutMe; @Min(value = 18, message = "Age should not be less than 18") diff --git a/javaxval/src/test/java/sample/ValidationTest.java b/javaxval/src/test/java/sample/ValidationTest.java index 0e0ab70216..73a14c1ce3 100644 --- a/javaxval/src/test/java/sample/ValidationTest.java +++ b/javaxval/src/test/java/sample/ValidationTest.java @@ -1,6 +1,5 @@ package sample; -import java.util.Iterator; import java.util.Set; import javax.validation.ConstraintViolation; @@ -21,54 +20,49 @@ public class ValidationTest { user.setWorking(true); user.setAboutMe("Its all about me!!"); user.setAge(50); - - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + Validator validator = factory.getValidator(); + Set> violations = validator.validate(user); + Assert.assertEquals(violations.isEmpty(), false); + } + + @Test + public void ifSizeNotInRange_aboutMeValidationFails() { + User user = new User(); + user.setName("MyName"); + user.setAboutMe("Its all about me!!"); + user.setAge(50); + + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set> violations = validator.validate(user); - Iterator> iter = violations.iterator(); - - while (iter.hasNext()) { - ConstraintViolation cv = iter.next(); - } - Assert.assertEquals(violations.isEmpty(), false); } @Test public void ifWorkingIsFalse_workingValidationFails() { User user = new User(); - user.setName("MyName"); + user.setName("MyName"); user.setAboutMe("Its all about me!!"); user.setAge(50); - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set> violations = validator.validate(user); - Iterator> iter = violations.iterator(); - - while (iter.hasNext()) { - ConstraintViolation cv = iter.next(); - } - Assert.assertEquals(violations.isEmpty(), false); } @Test public void ifAgeNotRange_ageValidationFails() { User user = new User(); - user.setName("MyName"); + user.setName("MyName"); user.setAboutMe("Its all about me!!"); user.setAge(8); - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set> violations = validator.validate(user); - Iterator> iter = violations.iterator(); - - while (iter.hasNext()) { - ConstraintViolation cv = iter.next(); - } - Assert.assertEquals(violations.isEmpty(), false); } }