DefaultAnnotationAttributeHandler implements AnnotationAttributeHandler { @Override public Map<String, Object> generateFrom(AnnotatedElement annotatedElement, Annotation annotation) { final AnnotationAttributes annotationAttributes = AnnotationUtils.getAnnotationAttributes(annotatedElement, annotation, false, true); final HashMap<String, Object> map = new HashMap<>(); for(final Entry<String, Object> entry: annotationAttributes.entrySet()) { map.put(entry.getKey(), entry.getValue()); } return map; }  @Override Map<String, Object> generateFrom(AnnotatedElement annotatedElement, Annotation annotation);  }
@Test public void t1_generateFrom_singleAttribute() throws Exception { final Field annotatedElement = this.getClass().getDeclaredField("testVariable"); final Annotation annotation = annotatedElement.getAnnotation(Foo.class); final Map<String, Object> actual = this.testee.generateFrom(annotatedElement, annotation); Assert.assertEquals(1, actual.size()); Assert.assertEquals("FooAnnotation_value", actual.get("value")); }
@Test public void t2_generateFrom_noAttributes() throws Exception { final Field annotatedElement = this.getClass().getDeclaredField("testVariable"); final Annotation annotation = annotatedElement.getAnnotation(Baz.class); final Map<String, Object> actual = this.testee.generateFrom(annotatedElement, annotation); Assert.assertTrue(actual.isEmpty()); }
@Test public void t3_generateFrom_multipleAttributes() throws Exception { final Field annotatedElement = this.getClass().getDeclaredField("testVariable"); final Annotation annotation = annotatedElement.getAnnotation(Bar.class); final Map<String, Object> actual = this.testee.generateFrom(annotatedElement, annotation); Assert.assertEquals(2, actual.size()); Assert.assertEquals("BarAnnotation_value", actual.get("value")); Assert.assertEquals("BarAnnotation_value2", actual.get("value2")); }