Annotation for my ConstraintValidator implementation is defined as PARAMETER
@Target({PARAMETER, ANNOTATION_TYPE, TYPE_USE})
During the test, Validator’s validate() method is not being called, but isValid() does. If I change annotation target to FIELD
and add annotation to class variable, then validate() method is starting to get called. How should approach testing annotation with target set as PARAMETER
without also defining it as FIELD
?
This is my test case
public class ExecutionRequestValidatorTest_Local extends BaseValidatorTest {
private static Validator validator;
@BeforeAll
public void init() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
executionRequestInstance = ExecutionRequestInstance.builder().build();
}
@Test
void isValid(){
final Set<ConstraintViolation<Tester>> validate = validator.validate(new Tester(executionRequestInstance));
}
private class Tester {
@ValidateExecutionRequest // validate() method gets called only if this annotation is present
private final ExecutionRequestInstance requestInstance;
public Tester(ExecutionRequestInstance requestInstance){
this.requestInstance = requestInstance;
test(requestInstance);
}
public void test(@ValidateExecutionRequest ExecutionRequestInstance request){
}
}
}