PatternValidator implements Validator { @Override public boolean validate(Object instance, Annotation annotation, Object value) { if (value == null) { return true; } String str = value.toString(); return isExactMatch(str) || isContainsMatch(str) || isRegex(str); }  @Override boolean validate(Object instance, Annotation annotation, Object value); @Override Class<? extends Annotation> getAnnotationClass(); @Override String getMessage(Annotation annotation, String fieldName, Object value);  }
@Test public void testValidate() { PatternValidator patternValidator = new PatternValidator(); Object instance = new Object(); Pattern annotation = new Pattern() { @Override public Class<? extends Annotation> annotationType() { return Pattern.class; } }; assertThat(patternValidator.validate(instance, annotation, pattern), is(result)); }