MetadataValidator implements Validator { @Override public boolean validate(Object instance, Annotation annotation, Object value) { if (value == null) { return true; } if (value instanceof Map) { Map<?, ?> valuesMap = (Map) value; for (Object k : valuesMap.keySet()) { if (!ALL_METADATA_KEYS.contains(k.toString())) { return false; } } return true; } return false; }  @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 MetadataValidator(); Object instance = new Object(); Metadata annotation = new Metadata() { @Override public Class<? extends Annotation> annotationType() { return Metadata.class; } }; assertThat(validator.validate(instance, annotation, null), is(true)); assertThat(validator.validate(instance, annotation, "something"), is(false)); assertThat(validator.validate(instance, annotation, getCorrectMetadataMap()), is(true)); assertThat(validator.validate(instance, annotation, getIncorrectMetadataMap()), is(false)); }