SupportedSymbolsValidator implements Validator { @Override public boolean validate(Object instance, Annotation annotation, Object value) { return value == null || value.toString().matches(String.format("[%s]+", getAllowedSymbols(annotation))); }  @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() throws Exception { Validator validator = new SupportedSymbolsValidator(); SupportedSymbols annotation = new SupportedSymbols() { @Override public Class<? extends Annotation> annotationType() { return SupportedSymbols.class; } @Override public String value() { return "a-zA-Z0-9-_$."; } }; Object instance = new Object(); assertThat(validator.validate(instance, annotation, "Cor_rect-$Name."), is(true)); assertThat(validator.validate(instance, annotation, null), is(true)); assertThat(validator.validate(instance, annotation, "%incorrect#name"), is(false)); }