I have this validation:
public void initialize(Telephone constraintAnnotation) {
setTelephoneCountryCodeField(constraintAnnotation.telephoneCountryCodeField());
setTelephoneField(constraintAnnotation.telephoneField());
}
public boolean isValid(Object value, **ConstraintValidatorContext context**) {
String telephone = BeanUtils.getProperty(value, telephoneField);
String countryCode = BeanUtils.getProperty(value, telephoneCountryCodeField);
return validateTelephone(...);
}
While a test using MockitoJUnitRunner, I need to call separately to ‘initialize()’ and ‘isValid()’, but I don’t know how to retrieve the current ConstraintValidatorContext to pass it to the method isValid() (i’m building that object from nothing which I don’t think is a good practice)
telephoneValidator.initialize(validationData.getTelephone());
telephoneValidator.isValid(validationData.getUserEntitySpainKo(), ValidatorContext.getValidatorContext());
How can i retrieve current ConstraintValidatorContext to pass it to the method isValid, after call initialize?