NumberRelationValidator implements Validator { @Override public boolean validate(Object instance, Annotation annotation, Object value) { if (value == null) { return true; } RelativeToNumber ann = RelativeToNumber.class.cast(annotation); double number = ann.number(); double doubleValue = Double.valueOf(value.toString()); return relationChecker.checkDoubleRelation(doubleValue, number, ann.relation()); }  @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 { Object instance = new Object(); RelativeToNumber annotation = new RelativeToNumber() { @Override public BooleanRelation relation() { return BooleanRelation.GREATER_THAN; } @Override public double number() { return 0; } @Override public Class<? extends Annotation> annotationType() { return RelativeToNumber.class; } }; assertThat(validator.validate(instance, annotation, null), is(true)); assertThat(validator.validate(instance, annotation, 1), is(true)); assertThat(validator.validate(instance, annotation, -1), is(false)); }