### Question:
PatternValidator implements ConstraintValidator<Pattern, String> { public void initialize(Pattern parameters) { Pattern.Flag flags[] = parameters.flags(); int intFlag = 0; for ( Pattern.Flag flag : flags ) { intFlag = intFlag | mapFlagToInt( flag ); } try { pattern = java.util.regex.Pattern.compile( parameters.regexp(), intFlag ); } catch ( PatternSyntaxException e ) { throw new ValidationException( "Invalid regular expression.", e ); } }  void initialize(Pattern parameters); boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext);  }### Answer:
@Test(expectedExceptions = ValidationException.class) public void testInvalidRegularExpression() { AnnotationDescriptor<Pattern> descriptor = new AnnotationDescriptor<Pattern>( Pattern.class ); descriptor.setValue( "regexp", "(unbalanced parentheses" ); descriptor.setValue( "message", "{validator.pattern}" ); Pattern p = AnnotationFactory.create( descriptor ); PatternValidator constraint = new PatternValidator(); constraint.initialize( p ); }