use of javax.validation.Validator in project podam by devopsfolks.
the class ValidatedPojoTest method podamShouldAllowValidationAnnotationsCustomization.
@Test
@Title("Podam should allow validation annotations customization")
public void podamShouldAllowValidationAnnotationsCustomization() throws Exception {
AttributeStrategy<?> strategy = new PatternStrategy();
PodamFactory podamFactory = podamFactorySteps.givenAPodamFactoryWithCustomStrategy(Pattern.class, strategy);
ValidatedPatternPojo pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(ValidatedPatternPojo.class, podamFactory);
podamValidationSteps.thePojoMustBeOfTheType(pojo, ValidatedPatternPojo.class);
podamValidationSteps.thePojoMustBeOfTheType(pojo.getNumber(), String.class);
podamValidationSteps.thePojoMustBeOfTheType(pojo.getIdentifier(), String.class);
Validator validator = podamFactorySteps.givenAJavaxValidator();
validatorSteps.thePojoShouldNotViolateAnyValidations(validator, pojo);
podamFactorySteps.removeCustomStrategy(podamFactory, Pattern.class);
}
use of javax.validation.Validator in project javaee7-firstcup by ecabrerar.
the class BooksCollectionTest method shouldReturnAValidationError.
@Test
public void shouldReturnAValidationError() {
Book book = new Book("Effective Java", "2234555568", "");
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<Book>> violations = validator.validate(book);
Assert.assertEquals(2, violations.size());
System.out.println(violations.stream().map(error -> error.getMessage()).collect(Collectors.joining(", ")));
}
Aggregations