Introduce getAnnotation() in AnnotatedElementUtils

This commit introduces a "synthesized annotation" alternative to
getAnnotationAttributes() in AnnotatedElementUtils, analogous to the
recently introduced findAnnotation() methods.

Issue: SPR-13082
This commit is contained in:
Sam Brannen
2015-05-29 22:04:10 +02:00
parent 9afcd17c71
commit 9f717871e6
3 changed files with 45 additions and 4 deletions

View File

@@ -322,6 +322,19 @@ public class AnnotatedElementUtilsTests {
assertTrue(isAnnotated(element, name));
}
@Test
public void getAnnotationWithAliasedValueComposedAnnotation() {
Class<?> element = AliasedValueComposedContextConfigClass.class;
ContextConfig contextConfig = getAnnotation(element, ContextConfig.class);
assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), contextConfig);
assertArrayEquals("locations", new String[] { "test.xml" }, contextConfig.locations());
assertArrayEquals("value", new String[] { "test.xml" }, contextConfig.value());
// Verify contracts between utility methods:
assertTrue(isAnnotated(element, ContextConfig.class.getName()));
}
@Test
public void getAnnotationAttributesWithInvalidConventionBasedComposedAnnotation() {
Class<?> element = InvalidConventionBasedComposedContextConfigClass.class;