RequiredValidator implements Validator { @Override public boolean validate(Object instance, Annotation annotation, Object value) { return value != null; }  @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 RequiredValidator(); Object instance = new Object(); Required annotation = new Required() { @Override public Class<? extends Annotation> annotationType() { return Required.class; } }; assertThat(validator.validate(instance, annotation, null), is(false)); assertThat(validator.validate(instance, annotation, "something"), is(true)); }