NumericRangeValidator implements Validator { @Override public boolean validate(Object instance, Annotation annotation, Object value) { return value == null || isRange(value.toString()); }  @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 NumericRangeValidator(); Object instance = new Object(); NumericRange annotation = new NumericRange() { @Override public Class<? extends Annotation> annotationType() { return NumericRange.class; } }; assertThat(validator.validate(instance, annotation, null), is(true)); assertThat(validator.validate(instance, annotation, "1,3-5,10,100"), is(true)); assertThat(validator.validate(instance, annotation, "1"), is(true)); assertThat(validator.validate(instance, annotation, "#$-3"), is(false)); }