I have a model object like the one below with custom constraint validator. The custom validator checks if either fileName or hours is populated.
@ValidCriteria
class Criteria{
@NotEmpty String id;
@NotEmpty String name;
String fileName;
String hours;
}
There is a method which takes takes this as input and it validates all the following conditions
- criteria is not null (by Default validator)
- criteria.id is not empty (by Default validator)
- criteria.name is not empty (by Default validator)
criteria fileName or hours is not empty (by custom validator)
void evaluate(@NotNull @Valid Criteria criteria){}
Now when I'm writing unit test for this model class. I'm invoking
Validation.buildDefaultValidatorFactory().getValidator().validate(criteria)
when I do this, the first 3 validations by default validator is not being invoked. Is there a way to invoke the default validator from my unit test or from my custom validator?