updated code
This commit is contained in:
parent
7c9070a3a2
commit
c745cf2e9b
|
@ -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")
|
||||
|
|
|
@ -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<ConstraintViolation<User>> 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<ConstraintViolation<User>> violations = validator.validate(user);
|
||||
Iterator<ConstraintViolation<User>> iter = violations.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ConstraintViolation<User> 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<ConstraintViolation<User>> violations = validator.validate(user);
|
||||
Iterator<ConstraintViolation<User>> iter = violations.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ConstraintViolation<User> 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<ConstraintViolation<User>> violations = validator.validate(user);
|
||||
Iterator<ConstraintViolation<User>> iter = violations.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ConstraintViolation<User> cv = iter.next();
|
||||
}
|
||||
|
||||
Assert.assertEquals(violations.isEmpty(), false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue