diff --git a/spring-test/src/main/java/org/springframework/test/util/MetaAnnotationUtils.java b/spring-test/src/main/java/org/springframework/test/util/MetaAnnotationUtils.java index 28b7a12b55..c38d53479b 100644 --- a/spring-test/src/main/java/org/springframework/test/util/MetaAnnotationUtils.java +++ b/spring-test/src/main/java/org/springframework/test/util/MetaAnnotationUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -286,8 +286,8 @@ public abstract class MetaAnnotationUtils { this.declaringClass = declaringClass; this.composedAnnotation = composedAnnotation; this.annotation = annotation; - this.annotationAttributes = AnnotatedElementUtils.getAnnotationAttributes( - rootDeclaringClass, annotation.annotationType().getName()); + this.annotationAttributes = AnnotatedElementUtils.getAnnotationAttributes(rootDeclaringClass, + annotation.annotationType().getName(), true, true, false, false); } public Class getRootDeclaringClass() { diff --git a/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java b/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java index 314f5ee2d8..01241fa1c8 100644 --- a/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,8 @@ import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.util.MetaAnnotationUtils.AnnotationDescriptor; +import org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor; import org.springframework.transaction.annotation.Transactional; import static org.junit.Assert.*; @@ -161,6 +163,22 @@ public class MetaAnnotationUtilsTests { assertNull(findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class)); } + @Test + public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndAnnotatedSuperclass() { + AnnotationDescriptor descriptor = findAnnotationDescriptor( + MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class); + + assertNotNull("AnnotationDescriptor should not be null", descriptor); + assertEquals("rootDeclaringClass", MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, descriptor.getRootDeclaringClass()); + assertEquals("declaringClass", MetaConfig.class, descriptor.getDeclaringClass()); + assertEquals("annotationType", ContextConfiguration.class, descriptor.getAnnotationType()); + assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation()); + assertEquals("composedAnnotationType", MetaConfig.class, descriptor.getComposedAnnotationType()); + + assertArrayEquals("configured classes", new Class[] { String.class }, + descriptor.getAnnotationAttributes().getClassArray("classes")); + } + @Test public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { assertAtComponentOnComposedAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", @@ -546,4 +564,12 @@ public class MetaAnnotationUtilsTests { static class SubNonInheritedAnnotationClass extends NonInheritedAnnotationClass { } + @ContextConfiguration(classes = Number.class) + static class AnnotatedContextConfigClass { + } + + @MetaConfig(classes = String.class) + static class MetaAnnotatedAndSuperAnnotatedContextConfigClass extends AnnotatedContextConfigClass { + } + }