Exemplo n.º 1
0
  @Provides
  protected ValidatorFactory getValidationFactory(
      Provider<MessageInterpolator> interpolatorProvider) {
    HibernateValidatorConfiguration configure =
        Validation.byProvider(HibernateValidator.class).configure();

    configure.messageInterpolator(interpolatorProvider.get());
    return configure.buildValidatorFactory();
  }
 @Test
 public void withConfiguration() {
   HibernateValidatorConfiguration configuration =
       Validation.byProvider(HibernateValidator.class)
           .providerResolver(
               new ValidationProviderResolver() {
                 @Override
                 public List<ValidationProvider<?>> getValidationProviders() {
                   ValidationProvider<HibernateValidatorConfiguration> prov =
                       new HibernateValidator();
                   List<ValidationProvider<?>> provs = new ArrayList<>();
                   provs.add(prov);
                   return provs;
                 }
               })
           .configure();
   configuration.externalClassLoader(Thread.currentThread().getContextClassLoader());
   Validator validator = configuration.buildValidatorFactory().getValidator();
   Thread.currentThread().setContextClassLoader(null);
   Set<ConstraintViolation<ValidateMe>> violations = validator.validate(new ValidateMe(0));
   Assert.assertEquals(1, violations.size());
 }