From a6021cc96890e6f909fcf9f20d8ff6dabf596359 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 31 Jul 2019 13:46:25 +0100 Subject: [PATCH] Rename SearchStrategy.EXHAUSTIVE to TYPE_HIERARCHY Rename `SearchStrategy.EXHAUSTIVE` from `MergedAnnotations` to `SearchStrategy.TYPE_HIERARCHY` See gh-23378 --- .../support/DefaultListableBeanFactory.java | 6 +- .../AnnotationJmxAttributeSource.java | 10 +- .../annotation/AnnotatedElementUtils.java | 4 +- .../AnnotationAwareOrderComparator.java | 2 +- .../core/annotation/AnnotationUtils.java | 4 +- .../core/annotation/AnnotationsScanner.java | 4 + .../core/annotation/MergedAnnotations.java | 14 +- .../core/annotation/OrderUtils.java | 4 +- .../annotation/AnnotationsScannerTests.java | 78 ++++----- ...ComposedOnSingleAnnotatedElementTests.java | 44 ++--- ...dAnnotationsRepeatableAnnotationTests.java | 44 ++--- .../annotation/MergedAnnotationsTests.java | 162 +++++++++--------- .../support/TestPropertySourceUtils.java | 2 +- 13 files changed, 196 insertions(+), 182 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index ca598a3d57..aaf8b8f806 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -684,7 +684,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto Class beanType = getType(beanName); if (beanType != null) { MergedAnnotation annotation = - MergedAnnotations.from(beanType, SearchStrategy.EXHAUSTIVE).get(annotationType); + MergedAnnotations.from(beanType, SearchStrategy.TYPE_HIERARCHY).get(annotationType); if (annotation.isPresent()) { return annotation; } @@ -696,7 +696,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto Class beanClass = bd.getBeanClass(); if (beanClass != beanType) { MergedAnnotation annotation = - MergedAnnotations.from(beanClass, SearchStrategy.EXHAUSTIVE).get(annotationType); + MergedAnnotations.from(beanClass, SearchStrategy.TYPE_HIERARCHY).get(annotationType); if (annotation.isPresent()) { return annotation; } @@ -706,7 +706,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto Method factoryMethod = bd.getResolvedFactoryMethod(); if (factoryMethod != null) { MergedAnnotation annotation = - MergedAnnotations.from(factoryMethod, SearchStrategy.EXHAUSTIVE).get(annotationType); + MergedAnnotations.from(factoryMethod, SearchStrategy.TYPE_HIERARCHY).get(annotationType); if (annotation.isPresent()) { return annotation; } diff --git a/spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java b/spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java index 30f6446bf1..a1f0284795 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java @@ -76,7 +76,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac @Override @Nullable public org.springframework.jmx.export.metadata.ManagedResource getManagedResource(Class beanClass) throws InvalidMetadataException { - MergedAnnotation ann = MergedAnnotations.from(beanClass, SearchStrategy.EXHAUSTIVE) + MergedAnnotation ann = MergedAnnotations.from(beanClass, SearchStrategy.TYPE_HIERARCHY) .get(ManagedResource.class).withNonMergedAttributes(); if (!ann.isPresent()) { return null; @@ -106,7 +106,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac @Override @Nullable public org.springframework.jmx.export.metadata.ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException { - MergedAnnotation ann = MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE) + MergedAnnotation ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY) .get(ManagedAttribute.class).withNonMergedAttributes(); if (!ann.isPresent()) { return null; @@ -127,7 +127,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac @Override @Nullable public org.springframework.jmx.export.metadata.ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException { - MergedAnnotation ann = MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE) + MergedAnnotation ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY) .get(ManagedMetric.class).withNonMergedAttributes(); return copyPropertiesToBean(ann, org.springframework.jmx.export.metadata.ManagedMetric.class); @@ -136,7 +136,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac @Override @Nullable public org.springframework.jmx.export.metadata.ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException { - MergedAnnotation ann = MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE) + MergedAnnotation ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY) .get(ManagedOperation.class).withNonMergedAttributes(); return copyPropertiesToBean(ann, org.springframework.jmx.export.metadata.ManagedOperation.class); @@ -167,7 +167,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac AnnotatedElement annotatedElement, Class annotationType, Class containerAnnotationType) { - return MergedAnnotations.from(annotatedElement, SearchStrategy.EXHAUSTIVE, + return MergedAnnotations.from(annotatedElement, SearchStrategy.TYPE_HIERARCHY, RepeatableContainers.of(annotationType, containerAnnotationType), AnnotationFilter.PLAIN) .stream(annotationType) .filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex)) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java index 58ea983a1a..6a27cafed1 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java @@ -763,7 +763,7 @@ public abstract class AnnotatedElementUtils { } private static MergedAnnotations findAnnotations(AnnotatedElement element) { - return MergedAnnotations.from(element, SearchStrategy.EXHAUSTIVE, + return MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY, RepeatableContainers.none(), AnnotationFilter.PLAIN); } @@ -771,7 +771,7 @@ public abstract class AnnotatedElementUtils { @Nullable Class containerType, Class annotationType) { RepeatableContainers repeatableContainers = RepeatableContainers.of(annotationType, containerType); - return MergedAnnotations.from(element, SearchStrategy.EXHAUSTIVE, + return MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY, repeatableContainers, AnnotationFilter.PLAIN); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java index 18b91de935..e0f107bcaf 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java @@ -71,7 +71,7 @@ public class AnnotationAwareOrderComparator extends OrderComparator { @Nullable private Integer findOrderFromAnnotation(Object obj) { AnnotatedElement element = (obj instanceof AnnotatedElement ? (AnnotatedElement) obj : obj.getClass()); - MergedAnnotations annotations = MergedAnnotations.from(element, SearchStrategy.EXHAUSTIVE); + MergedAnnotations annotations = MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY); Integer order = OrderUtils.getOrderFromAnnotations(element, annotations); if (order == null && obj instanceof DecoratingProxy) { return findOrderFromAnnotation(((DecoratingProxy) obj).getDecoratedClass()); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 1d89dd69e7..1381f19a78 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -524,7 +524,7 @@ public abstract class AnnotationUtils { return method.getDeclaredAnnotation(annotationType); } // Exhaustive retrieval of merged annotations... - return MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE, + return MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY, RepeatableContainers.none(), AnnotationFilter.PLAIN) .get(annotationType).withNonMergedAttributes() .synthesize(MergedAnnotation::isPresent).orElse(null); @@ -563,7 +563,7 @@ public abstract class AnnotationUtils { return clazz.getDeclaredAnnotation(annotationType); } // Exhaustive retrieval of merged annotations... - return MergedAnnotations.from(clazz, SearchStrategy.EXHAUSTIVE, + return MergedAnnotations.from(clazz, SearchStrategy.TYPE_HIERARCHY, RepeatableContainers.none(), AnnotationFilter.PLAIN) .get(annotationType).withNonMergedAttributes() .synthesize(MergedAnnotation::isPresent).orElse(null); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java index 5d444a1a57..4a041a9ab5 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java @@ -112,6 +112,7 @@ abstract class AnnotationsScanner { } @Nullable + @SuppressWarnings("deprecation") private static R processClass(C context, Class source, SearchStrategy searchStrategy, AnnotationsProcessor processor, @Nullable BiPredicate> classFilter) { @@ -124,6 +125,7 @@ abstract class AnnotationsScanner { case SUPERCLASS: return processClassHierarchy(context, new int[] {0}, source, processor, classFilter, false); case EXHAUSTIVE: + case TYPE_HIERARCHY: return processClassHierarchy(context, new int[] {0}, source, processor, classFilter, true); } throw new IllegalStateException("Unsupported search strategy " + searchStrategy); @@ -221,6 +223,7 @@ abstract class AnnotationsScanner { } @Nullable + @SuppressWarnings("deprecation") private static R processMethod(C context, Method source, SearchStrategy searchStrategy, AnnotationsProcessor processor, @Nullable BiPredicate> classFilter) { @@ -233,6 +236,7 @@ abstract class AnnotationsScanner { return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(), processor, classFilter, source, false); case EXHAUSTIVE: + case TYPE_HIERARCHY: return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(), processor, classFilter, source, true); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java index 4a2d41268b..e2a96cb7c9 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java @@ -91,7 +91,7 @@ import org.springframework.lang.Nullable; * *

Different {@linkplain SearchStrategy search strategies} can be used to locate * related source elements that contain the annotations to be aggregated. For - * example, {@link SearchStrategy#EXHAUSTIVE} will search both superclasses and + * example, {@link SearchStrategy#TYPE_HIERARCHY} will search both superclasses and * implemented interfaces. * *

From a {@link MergedAnnotations} instance you can either @@ -428,8 +428,18 @@ public interface MergedAnnotations extends Iterable * Perform a full search of all related elements, including those on any * superclasses or implemented interfaces. Superclass annotations do * not need to be meta-annotated with {@link Inherited @Inherited}. + * @deprecated since 5.2.0.RC1 in favor of {@link #TYPE_HIERARCHY}. */ - EXHAUSTIVE + @Deprecated + EXHAUSTIVE, + + /** + * Perform a full search of the entire type hierarchy , including + * superclasses and implemented interfaces. Superclass annotations do + * not need to be meta-annotated with {@link Inherited @Inherited}. + */ + TYPE_HIERARCHY + } } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java index 2e8c216b96..494f4c886e 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java @@ -81,7 +81,7 @@ public abstract class OrderUtils { */ @Nullable public static Integer getOrder(Class type) { - return getOrderFromAnnotations(type, MergedAnnotations.from(type, SearchStrategy.EXHAUSTIVE)); + return getOrderFromAnnotations(type, MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY)); } /** @@ -127,7 +127,7 @@ public abstract class OrderUtils { */ @Nullable public static Integer getPriority(Class type) { - return MergedAnnotations.from(type, SearchStrategy.EXHAUSTIVE).get(JAVAX_PRIORITY_ANNOTATION) + return MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY).get(JAVAX_PRIORITY_ANNOTATION) .getValue(MergedAnnotation.VALUE, Integer.class).orElse(null); } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java index 2e86c69546..e57341e4a0 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java @@ -179,43 +179,43 @@ public class AnnotationsScannerTests { } @Test - public void exhaustiveStrategyOnClassWhenNotAnnoatedScansNone() { + public void typeHierarchyStrategyOnClassWhenNotAnnoatedScansNone() { Class source = WithNoAnnotations.class; - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).isEmpty(); + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).isEmpty(); } @Test - public void exhaustiveStrategyOnClassScansAnnotations() { + public void typeHierarchyStrategyOnClassScansAnnotations() { Class source = WithSingleAnnotation.class; - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1"); } @Test - public void exhaustiveStrategyOnClassWhenMultipleAnnotationsScansAnnotations() { + public void typeHierarchyStrategyOnClassWhenMultipleAnnotationsScansAnnotations() { Class source = WithMultipleAnnotations.class; - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "0:TestAnnotation2"); } @Test - public void exhaustiveStrategyOnClassWhenHasSuperclassScansSuperclass() { + public void typeHierarchyStrategyOnClassWhenHasSuperclassScansSuperclass() { Class source = WithSingleSuperclass.class; - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2"); } @Test - public void exhaustiveStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() { + public void typeHierarchyStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() { Class source = WithSingleInterface.class; - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2"); } @Test - public void exhaustiveStrategyOnClassHierarchyScansInCorrectOrder() { + public void typeHierarchyStrategyOnClassHierarchyScansInCorrectOrder() { Class source = WithHierarchy.class; - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation5", "1:TestInheritedAnnotation5", "2:TestAnnotation6", "3:TestAnnotation2", "3:TestInheritedAnnotation2", "4:TestAnnotation3", "5:TestAnnotation4"); @@ -346,61 +346,61 @@ public class AnnotationsScannerTests { } @Test - public void exhaustiveStrategyOnMethodWhenNotAnnoatedScansNone() { + public void typeHierarchyStrategyOnMethodWhenNotAnnoatedScansNone() { Method source = methodFrom(WithNoAnnotations.class); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).isEmpty(); + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).isEmpty(); } @Test - public void exhaustiveStrategyOnMethodScansAnnotations() { + public void typeHierarchyStrategyOnMethodScansAnnotations() { Method source = methodFrom(WithSingleAnnotation.class); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1"); } @Test - public void exhaustiveStrategyOnMethodWhenMultipleAnnotationsScansAnnotations() { + public void typeHierarchyStrategyOnMethodWhenMultipleAnnotationsScansAnnotations() { Method source = methodFrom(WithMultipleAnnotations.class); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "0:TestAnnotation2"); } @Test - public void exhaustiveStrategyOnMethodWhenHasSuperclassScansSuperclass() { + public void typeHierarchyStrategyOnMethodWhenHasSuperclassScansSuperclass() { Method source = methodFrom(WithSingleSuperclass.class); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2"); } @Test - public void exhaustiveStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() { + public void typeHierarchyStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() { Method source = methodFrom(WithSingleInterface.class); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2"); } @Test - public void exhaustiveStrategyOnMethodHierarchyScansInCorrectOrder() { + public void typeHierarchyStrategyOnMethodHierarchyScansInCorrectOrder() { Method source = methodFrom(WithHierarchy.class); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation5", "1:TestInheritedAnnotation5", "2:TestAnnotation6", "3:TestAnnotation2", "3:TestInheritedAnnotation2", "4:TestAnnotation3", "5:TestAnnotation4"); } @Test - public void exhaustiveStrategyOnBridgeMethodScansAnnotations() throws Exception { + public void typeHierarchyStrategyOnBridgeMethodScansAnnotations() throws Exception { Method source = BridgedMethod.class.getDeclaredMethod("method", Object.class); assertThat(source.isBridge()).isTrue(); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2"); } @Test - public void exhaustiveStrategyOnBridgedMethodScansAnnotations() throws Exception { + public void typeHierarchyStrategyOnBridgedMethodScansAnnotations() throws Exception { Method source = BridgedMethod.class.getDeclaredMethod("method", String.class); assertThat(source.isBridge()).isFalse(); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2"); } @@ -421,43 +421,43 @@ public class AnnotationsScannerTests { } @Test - public void exhaustiveStrategyOnMethodWithIgnorablesScansAnnotations() + public void typeHierarchyStrategyOnMethodWithIgnorablesScansAnnotations() throws Exception { Method source = methodFrom(Ignoreable.class); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1"); } @Test - public void exhaustiveStrategyOnMethodWithMultipleCandidatesScansAnnotations() + public void typeHierarchyStrategyOnMethodWithMultipleCandidatesScansAnnotations() throws Exception { Method source = methodFrom(MultipleMethods.class); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1"); } @Test - public void exhaustiveStrategyOnMethodWithGenericParameterOverrideScansAnnotations() + public void typeHierarchyStrategyOnMethodWithGenericParameterOverrideScansAnnotations() throws Exception { Method source = ReflectionUtils.findMethod(GenericOverride.class, "method", String.class); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2"); } @Test - public void exhaustiveStrategyOnMethodWithGenericParameterNonOverrideScansAnnotations() + public void typeHierarchyStrategyOnMethodWithGenericParameterNonOverrideScansAnnotations() throws Exception { Method source = ReflectionUtils.findMethod(GenericNonOverride.class, "method", StringBuilder.class); - assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly( + assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1"); } @Test public void scanWhenProcessorReturnsFromDoWithAggregateExitsEarly() { String result = AnnotationsScanner.scan(this, WithSingleSuperclass.class, - SearchStrategy.EXHAUSTIVE, new AnnotationsProcessor() { + SearchStrategy.TYPE_HIERARCHY, new AnnotationsProcessor() { @Override @Nullable @@ -480,7 +480,7 @@ public class AnnotationsScannerTests { public void scanWhenProcessorReturnsFromDoWithAnnotationsExitsEarly() { List indexes = new ArrayList<>(); String result = AnnotationsScanner.scan(this, WithSingleSuperclass.class, - SearchStrategy.EXHAUSTIVE, + SearchStrategy.TYPE_HIERARCHY, (context, aggregateIndex, source, annotations) -> { indexes.add(aggregateIndex); return ""; @@ -492,7 +492,7 @@ public class AnnotationsScannerTests { @Test public void scanWhenProcessorHasFinishMethodUsesFinishResult() { String result = AnnotationsScanner.scan(this, WithSingleSuperclass.class, - SearchStrategy.EXHAUSTIVE, new AnnotationsProcessor() { + SearchStrategy.TYPE_HIERARCHY, new AnnotationsProcessor() { @Override @Nullable diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsComposedOnSingleAnnotatedElementTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsComposedOnSingleAnnotatedElementTests.java index 42ea78709e..28d375f317 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsComposedOnSingleAnnotatedElementTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsComposedOnSingleAnnotatedElementTests.java @@ -105,70 +105,70 @@ public class MergedAnnotationsComposedOnSingleAnnotatedElementTests { } @Test - public void exhaustiveStrategyMultipleComposedAnnotationsOnClass() { - assertExhaustiveStrategyBehavior(MultipleComposedCachesClass.class); + public void typeHierarchyStrategyMultipleComposedAnnotationsOnClass() { + assertTypeHierarchyStrategyBehavior(MultipleComposedCachesClass.class); } @Test - public void exhaustiveStrategyMultipleInheritedComposedAnnotationsOnSuperclass() { - assertExhaustiveStrategyBehavior(SubMultipleComposedCachesClass.class); + public void typeHierarchyStrategyMultipleInheritedComposedAnnotationsOnSuperclass() { + assertTypeHierarchyStrategyBehavior(SubMultipleComposedCachesClass.class); } @Test - public void exhaustiveStrategyMultipleNoninheritedComposedAnnotationsOnClass() { + public void typeHierarchyStrategyMultipleNoninheritedComposedAnnotationsOnClass() { MergedAnnotations annotations = MergedAnnotations.from( - MultipleNoninheritedComposedCachesClass.class, SearchStrategy.EXHAUSTIVE); + MultipleNoninheritedComposedCachesClass.class, SearchStrategy.TYPE_HIERARCHY); assertThat(stream(annotations, "value")).containsExactly("noninheritedCache1", "noninheritedCache2"); } @Test - public void exhaustiveStrategyMultipleNoninheritedComposedAnnotationsOnSuperclass() { + public void typeHierarchyStrategyMultipleNoninheritedComposedAnnotationsOnSuperclass() { MergedAnnotations annotations = MergedAnnotations.from( SubMultipleNoninheritedComposedCachesClass.class, - SearchStrategy.EXHAUSTIVE); + SearchStrategy.TYPE_HIERARCHY); assertThat(stream(annotations, "value")).containsExactly("noninheritedCache1", "noninheritedCache2"); } @Test - public void exhaustiveStrategyComposedPlusLocalAnnotationsOnClass() { - assertExhaustiveStrategyBehavior(ComposedPlusLocalCachesClass.class); + public void typeHierarchyStrategyComposedPlusLocalAnnotationsOnClass() { + assertTypeHierarchyStrategyBehavior(ComposedPlusLocalCachesClass.class); } @Test - public void exhaustiveStrategyMultipleComposedAnnotationsOnInterface() { - assertExhaustiveStrategyBehavior(MultipleComposedCachesOnInterfaceClass.class); + public void typeHierarchyStrategyMultipleComposedAnnotationsOnInterface() { + assertTypeHierarchyStrategyBehavior(MultipleComposedCachesOnInterfaceClass.class); } @Test - public void exhaustiveStrategyComposedCacheOnInterfaceAndLocalCacheOnClass() { - assertExhaustiveStrategyBehavior( + public void typeHierarchyStrategyComposedCacheOnInterfaceAndLocalCacheOnClass() { + assertTypeHierarchyStrategyBehavior( ComposedCacheOnInterfaceAndLocalCacheClass.class); } @Test - public void exhaustiveStrategyMultipleComposedAnnotationsOnMethod() throws Exception { - assertExhaustiveStrategyBehavior( + public void typeHierarchyStrategyMultipleComposedAnnotationsOnMethod() throws Exception { + assertTypeHierarchyStrategyBehavior( getClass().getDeclaredMethod("multipleComposedCachesMethod")); } @Test - public void exhaustiveStrategyComposedPlusLocalAnnotationsOnMethod() + public void typeHierarchyStrategyComposedPlusLocalAnnotationsOnMethod() throws Exception { - assertExhaustiveStrategyBehavior( + assertTypeHierarchyStrategyBehavior( getClass().getDeclaredMethod("composedPlusLocalCachesMethod")); } @Test - public void exhaustiveStrategyMultipleComposedAnnotationsOnBridgeMethod() + public void typeHierarchyStrategyMultipleComposedAnnotationsOnBridgeMethod() throws Exception { - assertExhaustiveStrategyBehavior(getBridgeMethod()); + assertTypeHierarchyStrategyBehavior(getBridgeMethod()); } - private void assertExhaustiveStrategyBehavior(AnnotatedElement element) { + private void assertTypeHierarchyStrategyBehavior(AnnotatedElement element) { MergedAnnotations annotations = MergedAnnotations.from(element, - SearchStrategy.EXHAUSTIVE); + SearchStrategy.TYPE_HIERARCHY); assertThat(stream(annotations, "key")).containsExactly("fooKey", "barKey"); assertThat(stream(annotations, "value")).containsExactly("fooCache", "barCache"); } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsRepeatableAnnotationTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsRepeatableAnnotationTests.java index dffd1b46bd..1970206a9e 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsRepeatableAnnotationTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsRepeatableAnnotationTests.java @@ -135,89 +135,89 @@ public class MergedAnnotationsRepeatableAnnotationTests { } @Test - public void exhaustiveWhenNonRepeatableThrowsException() { + public void typeHierarchyWhenNonRepeatableThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> - getAnnotations(null, NonRepeatable.class, SearchStrategy.EXHAUSTIVE, getClass())) + getAnnotations(null, NonRepeatable.class, SearchStrategy.TYPE_HIERARCHY, getClass())) .satisfies(this::nonRepeatableRequirements); } @Test - public void exhaustiveWhenContainerMissingValueAttributeThrowsException() { + public void typeHierarchyWhenContainerMissingValueAttributeThrowsException() { assertThatAnnotationConfigurationException().isThrownBy(() -> getAnnotations(ContainerMissingValueAttribute.class, InvalidRepeatable.class, - SearchStrategy.EXHAUSTIVE, getClass())) + SearchStrategy.TYPE_HIERARCHY, getClass())) .satisfies(this::missingValueAttributeRequirements); } @Test - public void exhaustiveWhenWhenNonArrayValueAttributeThrowsException() { + public void typeHierarchyWhenWhenNonArrayValueAttributeThrowsException() { assertThatAnnotationConfigurationException().isThrownBy(() -> getAnnotations(ContainerWithNonArrayValueAttribute.class, InvalidRepeatable.class, - SearchStrategy.EXHAUSTIVE, getClass())) + SearchStrategy.TYPE_HIERARCHY, getClass())) .satisfies(this::nonArrayValueAttributeRequirements); } @Test - public void exhaustiveWhenWrongComponentTypeThrowsException() { + public void typeHierarchyWhenWrongComponentTypeThrowsException() { assertThatAnnotationConfigurationException().isThrownBy(() -> getAnnotations(ContainerWithArrayValueAttributeButWrongComponentType.class, - InvalidRepeatable.class, SearchStrategy.EXHAUSTIVE, getClass())) + InvalidRepeatable.class, SearchStrategy.TYPE_HIERARCHY, getClass())) .satisfies(this::wrongComponentTypeRequirements); } @Test - public void exhaustiveWhenOnClassReturnsAnnotations() { + public void typeHierarchyWhenOnClassReturnsAnnotations() { Set annotations = getAnnotations(null, PeteRepeat.class, - SearchStrategy.EXHAUSTIVE, RepeatableClass.class); + SearchStrategy.TYPE_HIERARCHY, RepeatableClass.class); assertThat(annotations.stream().map(PeteRepeat::value)).containsExactly("A", "B", "C"); } @Test - public void exhaustiveWhenWhenOnSuperclassReturnsAnnotations() { + public void typeHierarchyWhenWhenOnSuperclassReturnsAnnotations() { Set annotations = getAnnotations(null, PeteRepeat.class, - SearchStrategy.EXHAUSTIVE, SubRepeatableClass.class); + SearchStrategy.TYPE_HIERARCHY, SubRepeatableClass.class); assertThat(annotations.stream().map(PeteRepeat::value)).containsExactly("A", "B", "C"); } @Test - public void exhaustiveWhenComposedOnClassReturnsAnnotations() { + public void typeHierarchyWhenComposedOnClassReturnsAnnotations() { Set annotations = getAnnotations(null, PeteRepeat.class, - SearchStrategy.EXHAUSTIVE, ComposedRepeatableClass.class); + SearchStrategy.TYPE_HIERARCHY, ComposedRepeatableClass.class); assertThat(annotations.stream().map(PeteRepeat::value)).containsExactly("A", "B", "C"); } @Test - public void exhaustiveWhenComposedMixedWithContainerOnClassReturnsAnnotations() { + public void typeHierarchyWhenComposedMixedWithContainerOnClassReturnsAnnotations() { Set annotations = getAnnotations(null, PeteRepeat.class, - SearchStrategy.EXHAUSTIVE, + SearchStrategy.TYPE_HIERARCHY, ComposedRepeatableMixedWithContainerClass.class); assertThat(annotations.stream().map(PeteRepeat::value)).containsExactly("A", "B", "C"); } @Test - public void exhaustiveWhenComposedContainerForRepeatableOnClassReturnsAnnotations() { + public void typeHierarchyWhenComposedContainerForRepeatableOnClassReturnsAnnotations() { Set annotations = getAnnotations(null, PeteRepeat.class, - SearchStrategy.EXHAUSTIVE, ComposedContainerClass.class); + SearchStrategy.TYPE_HIERARCHY, ComposedContainerClass.class); assertThat(annotations.stream().map(PeteRepeat::value)).containsExactly("A", "B", "C"); } @Test - public void exhaustiveAnnotationsWhenNoninheritedComposedRepeatableOnClassReturnsAnnotations() { + public void typeHierarchyAnnotationsWhenNoninheritedComposedRepeatableOnClassReturnsAnnotations() { Set annotations = getAnnotations(null, Noninherited.class, - SearchStrategy.EXHAUSTIVE, NoninheritedRepeatableClass.class); + SearchStrategy.TYPE_HIERARCHY, NoninheritedRepeatableClass.class); assertThat(annotations.stream().map(Noninherited::value)).containsExactly("A", "B", "C"); } @Test - public void exhaustiveAnnotationsWhenNoninheritedComposedRepeatableOnSuperclassReturnsAnnotations() { + public void typeHierarchyAnnotationsWhenNoninheritedComposedRepeatableOnSuperclassReturnsAnnotations() { Set annotations = getAnnotations(null, Noninherited.class, - SearchStrategy.EXHAUSTIVE, SubNoninheritedRepeatableClass.class); + SearchStrategy.TYPE_HIERARCHY, SubNoninheritedRepeatableClass.class); assertThat(annotations.stream().map(Noninherited::value)).containsExactly("A", "B", "C"); } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java index a73939fe00..7469349bf9 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java @@ -459,93 +459,93 @@ public class MergedAnnotationsTests { } @Test - public void getWithExhaustiveFromInheritedAnnotationInterface() { + public void getWithTypeHierarchyFromInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( - InheritedAnnotationInterface.class, SearchStrategy.EXHAUSTIVE).get( + InheritedAnnotationInterface.class, SearchStrategy.TYPE_HIERARCHY).get( Transactional.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(0); } @Test - public void getWithExhaustiveFromSubInheritedAnnotationInterface() { + public void getWithTypeHierarchyFromSubInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( - SubInheritedAnnotationInterface.class, SearchStrategy.EXHAUSTIVE).get( + SubInheritedAnnotationInterface.class, SearchStrategy.TYPE_HIERARCHY).get( Transactional.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(1); } @Test - public void getWithExhaustiveFromSubSubInheritedAnnotationInterface() { + public void getWithTypeHierarchyFromSubSubInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( - SubSubInheritedAnnotationInterface.class, SearchStrategy.EXHAUSTIVE).get( + SubSubInheritedAnnotationInterface.class, SearchStrategy.TYPE_HIERARCHY).get( Transactional.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(2); } @Test - public void getWithExhaustiveFromNonInheritedAnnotationInterface() { + public void getWithTypeHierarchyFromNonInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( - NonInheritedAnnotationInterface.class, SearchStrategy.EXHAUSTIVE).get( + NonInheritedAnnotationInterface.class, SearchStrategy.TYPE_HIERARCHY).get( Order.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(0); } @Test - public void getWithExhaustiveFromSubNonInheritedAnnotationInterface() { + public void getWithTypeHierarchyFromSubNonInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( - SubNonInheritedAnnotationInterface.class, SearchStrategy.EXHAUSTIVE).get( + SubNonInheritedAnnotationInterface.class, SearchStrategy.TYPE_HIERARCHY).get( Order.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(1); } @Test - public void getWithExhaustiveFromSubSubNonInheritedAnnotationInterface() { + public void getWithTypeHierarchyFromSubSubNonInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( SubSubNonInheritedAnnotationInterface.class, - SearchStrategy.EXHAUSTIVE).get(Order.class); + SearchStrategy.TYPE_HIERARCHY).get(Order.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(2); } @Test - public void getWithExhaustiveInheritedFromInterfaceMethod() + public void getWithTypeHierarchyInheritedFromInterfaceMethod() throws NoSuchMethodException { Method method = ConcreteClassWithInheritedAnnotation.class.getMethod( "handleFromInterface"); MergedAnnotation annotation = MergedAnnotations.from(method, - SearchStrategy.EXHAUSTIVE).get(Order.class); + SearchStrategy.TYPE_HIERARCHY).get(Order.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(1); } @Test - public void getWithExhaustiveInheritedFromAbstractMethod() + public void getWithTypeHierarchyInheritedFromAbstractMethod() throws NoSuchMethodException { Method method = ConcreteClassWithInheritedAnnotation.class.getMethod("handle"); MergedAnnotation annotation = MergedAnnotations.from(method, - SearchStrategy.EXHAUSTIVE).get(Transactional.class); + SearchStrategy.TYPE_HIERARCHY).get(Transactional.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(1); } @Test - public void getWithExhaustiveInheritedFromBridgedMethod() + public void getWithTypeHierarchyInheritedFromBridgedMethod() throws NoSuchMethodException { Method method = ConcreteClassWithInheritedAnnotation.class.getMethod( "handleParameterized", String.class); MergedAnnotation annotation = MergedAnnotations.from(method, - SearchStrategy.EXHAUSTIVE).get(Transactional.class); + SearchStrategy.TYPE_HIERARCHY).get(Transactional.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(1); } @Test - public void getWithExhaustiveFromBridgeMethod() { + public void getWithTypeHierarchyFromBridgeMethod() { List methods = new ArrayList<>(); ReflectionUtils.doWithLocalMethods(StringGenericParameter.class, method -> { if ("getFor".equals(method.getName())) { @@ -561,23 +561,23 @@ public class MergedAnnotationsTests { assertThat(bridgeMethod.isBridge()).isTrue(); assertThat(bridgedMethod.isBridge()).isFalse(); MergedAnnotation annotation = MergedAnnotations.from(bridgeMethod, - SearchStrategy.EXHAUSTIVE).get(Order.class); + SearchStrategy.TYPE_HIERARCHY).get(Order.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(0); } @Test - public void getWithExhaustiveFromClassWithMetaAndLocalTxConfig() { + public void getWithTypeHierarchyFromClassWithMetaAndLocalTxConfig() { MergedAnnotation annotation = MergedAnnotations.from( - MetaAndLocalTxConfigClass.class, SearchStrategy.EXHAUSTIVE).get( + MetaAndLocalTxConfigClass.class, SearchStrategy.TYPE_HIERARCHY).get( Transactional.class); assertThat(annotation.getString("qualifier")).isEqualTo("localTxMgr"); } @Test - public void getWithExhaustiveFromClassWithAttributeAliasesInTargetAnnotation() { + public void getWithTypeHierarchyFromClassWithAttributeAliasesInTargetAnnotation() { MergedAnnotation mergedAnnotation = MergedAnnotations.from( - AliasedTransactionalComponentClass.class, SearchStrategy.EXHAUSTIVE).get( + AliasedTransactionalComponentClass.class, SearchStrategy.TYPE_HIERARCHY).get( AliasedTransactional.class); AliasedTransactional synthesizedAnnotation = mergedAnnotation.synthesize(); String qualifier = "aliasForQualifier"; @@ -588,8 +588,8 @@ public class MergedAnnotationsTests { } @Test - public void getWithExhaustiveFromClassWithAttributeAliasInComposedAnnotationAndNestedAnnotationsInTargetAnnotation() { - MergedAnnotation annotation = testGetWithExhaustive( + public void getWithTypeHierarchyFromClassWithAttributeAliasInComposedAnnotationAndNestedAnnotationsInTargetAnnotation() { + MergedAnnotation annotation = testGetWithTypeHierarchy( TestComponentScanClass.class, "com.example.app.test"); MergedAnnotation[] excludeFilters = annotation.getAnnotationArray( "excludeFilters", Filter.class); @@ -599,37 +599,37 @@ public class MergedAnnotationsTests { } @Test - public void getWithExhaustiveFromClassWithBothAttributesOfAnAliasPairDeclared() { - testGetWithExhaustive(ComponentScanWithBasePackagesAndValueAliasClass.class, + public void getWithTypeHierarchyFromClassWithBothAttributesOfAnAliasPairDeclared() { + testGetWithTypeHierarchy(ComponentScanWithBasePackagesAndValueAliasClass.class, "com.example.app.test"); } @Test - public void getWithExhaustiveWithSingleElementOverridingAnArrayViaConvention() { - testGetWithExhaustive(ConventionBasedSinglePackageComponentScanClass.class, + public void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaConvention() { + testGetWithTypeHierarchy(ConventionBasedSinglePackageComponentScanClass.class, "com.example.app.test"); } @Test - public void getWithExhaustiveWithSingleElementOverridingAnArrayViaAliasFor() { - testGetWithExhaustive(AliasForBasedSinglePackageComponentScanClass.class, + public void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaAliasFor() { + testGetWithTypeHierarchy(AliasForBasedSinglePackageComponentScanClass.class, "com.example.app.test"); } - private MergedAnnotation testGetWithExhaustive(Class element, + private MergedAnnotation testGetWithTypeHierarchy(Class element, String... expected) { MergedAnnotation annotation = MergedAnnotations.from(element, - SearchStrategy.EXHAUSTIVE).get(ComponentScan.class); + SearchStrategy.TYPE_HIERARCHY).get(ComponentScan.class); assertThat(annotation.getStringArray("value")).containsExactly(expected); assertThat(annotation.getStringArray("basePackages")).containsExactly(expected); return annotation; } @Test - public void getWithExhaustiveWhenMultipleMetaAnnotationsHaveClashingAttributeNames() { + public void getWithTypeHierarchyWhenMultipleMetaAnnotationsHaveClashingAttributeNames() { MergedAnnotations annotations = MergedAnnotations.from( AliasedComposedContextConfigurationAndTestPropertySourceClass.class, - SearchStrategy.EXHAUSTIVE); + SearchStrategy.TYPE_HIERARCHY); MergedAnnotation contextConfig = annotations.get(ContextConfiguration.class); assertThat(contextConfig.getStringArray("locations")).containsExactly("test.xml"); assertThat(contextConfig.getStringArray("value")).containsExactly("test.xml"); @@ -641,9 +641,9 @@ public class MergedAnnotationsTests { } @Test - public void getWithExhaustiveWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() { + public void getWithTypeHierarchyWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() { MergedAnnotation annotation = MergedAnnotations.from( - SpringApplicationConfigurationClass.class, SearchStrategy.EXHAUSTIVE).get( + SpringApplicationConfigurationClass.class, SearchStrategy.TYPE_HIERARCHY).get( ContextConfiguration.class); assertThat(annotation.getStringArray("locations")).isEmpty(); assertThat(annotation.getStringArray("value")).isEmpty(); @@ -651,22 +651,22 @@ public class MergedAnnotationsTests { } @Test - public void getWithExhaustiveOnMethodWithSingleElementOverridingAnArrayViaConvention() throws Exception { - testGetWithExhaustiveWebMapping( + public void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaConvention() throws Exception { + testGetWithTypeHierarchyWebMapping( WebController.class.getMethod("postMappedWithPathAttribute")); } @Test - public void getWithExhaustiveOnMethodWithSingleElementOverridingAnArrayViaAliasFor() throws Exception { - testGetWithExhaustiveWebMapping( + public void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaAliasFor() throws Exception { + testGetWithTypeHierarchyWebMapping( WebController.class.getMethod("getMappedWithValueAttribute")); - testGetWithExhaustiveWebMapping( + testGetWithTypeHierarchyWebMapping( WebController.class.getMethod("getMappedWithPathAttribute")); } - private void testGetWithExhaustiveWebMapping(AnnotatedElement element) throws ArrayComparisonFailure { + private void testGetWithTypeHierarchyWebMapping(AnnotatedElement element) throws ArrayComparisonFailure { MergedAnnotation annotation = MergedAnnotations.from(element, - SearchStrategy.EXHAUSTIVE).get(RequestMapping.class); + SearchStrategy.TYPE_HIERARCHY).get(RequestMapping.class); assertThat(annotation.getStringArray("value")).containsExactly("/test"); assertThat(annotation.getStringArray("path")).containsExactly("/test"); } @@ -686,9 +686,9 @@ public class MergedAnnotationsTests { } @Test - public void streamExhaustiveFromClassWithInterface() throws Exception { + public void streamTypeHierarchyFromClassWithInterface() throws Exception { Method method = TransactionalServiceImpl.class.getMethod("doIt"); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).stream( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).stream( Transactional.class)).hasSize(1); } @@ -698,7 +698,7 @@ public class MergedAnnotationsTests { assertThat(method.getAnnotation(Order.class)).isNotNull(); assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo( 0); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); } @@ -708,7 +708,7 @@ public class MergedAnnotationsTests { assertThat(method.getAnnotation(Order.class)).isNull(); assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo( -1); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); } @@ -718,7 +718,7 @@ public class MergedAnnotationsTests { assertThat(method.getAnnotation(Order.class)).isNull(); assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo( 1); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(1); } @@ -729,7 +729,7 @@ public class MergedAnnotationsTests { assertThat( MergedAnnotations.from(method).get(Component.class).getDistance()).isEqualTo( 2); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Component.class).getDistance()).isEqualTo(2); } @@ -739,7 +739,7 @@ public class MergedAnnotationsTests { assertThat(method.getAnnotation(Order.class)).isNotNull(); assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo( 0); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); } @@ -749,7 +749,7 @@ public class MergedAnnotationsTests { assertThat(method.getAnnotation(Order.class)).isNull(); assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo( 1); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(1); } @@ -759,7 +759,7 @@ public class MergedAnnotationsTests { assertThat(method.getAnnotation(Order.class)).isNull(); assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo( -1); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); } @@ -769,7 +769,7 @@ public class MergedAnnotationsTests { assertThat(method.getAnnotation(Order.class)).isNull(); assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo( -1); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(-1); } @@ -781,7 +781,7 @@ public class MergedAnnotationsTests { assertThat(method.getAnnotation(Order.class)).isNull(); assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo( -1); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); boolean runningInEclipse = Arrays.stream( new Exception().getStackTrace()).anyMatch( @@ -800,7 +800,7 @@ public class MergedAnnotationsTests { } assertThat(MergedAnnotations.from(method).get( Transactional.class).getDistance()).isEqualTo(0); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Transactional.class).getDistance()).isEqualTo(0); } @@ -812,19 +812,19 @@ public class MergedAnnotationsTests { assertThat(method.getAnnotation(Order.class)).isNull(); assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo( -1); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); assertThat(method.getAnnotation(Transactional.class)).isNotNull(); assertThat(MergedAnnotations.from(method).get( Transactional.class).getDistance()).isEqualTo(0); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Transactional.class).getDistance()).isEqualTo(0); } @Test public void getFromMethodWithInterface() throws Exception { Method method = ImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo"); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); } @@ -832,7 +832,7 @@ public class MergedAnnotationsTests { public void getFromMethodWithGenericInterface() throws Exception { Method method = ImplementsInterfaceWithGenericAnnotatedMethod.class.getMethod( "foo", String.class); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); } @@ -840,7 +840,7 @@ public class MergedAnnotationsTests { public void getFromMethodWithGenericSuperclass() throws Exception { Method method = ExtendsBaseClassWithGenericAnnotatedMethod.class.getMethod("foo", String.class); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); } @@ -848,7 +848,7 @@ public class MergedAnnotationsTests { public void getFromMethodWithInterfaceOnSuper() throws Exception { Method method = SubOfImplementsInterfaceWithAnnotatedMethod.class.getMethod( "foo"); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); } @@ -857,7 +857,7 @@ public class MergedAnnotationsTests { throws Exception { Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod.class.getMethod( "foo"); - assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get( + assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get( Order.class).getDistance()).isEqualTo(0); } @@ -865,14 +865,14 @@ public class MergedAnnotationsTests { public void getDirectFromClassFavorsMoreLocallyDeclaredComposedAnnotationsOverAnnotationsOnInterfaces() { MergedAnnotation annotation = MergedAnnotations.from( ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, - SearchStrategy.EXHAUSTIVE).get(Component.class); + SearchStrategy.TYPE_HIERARCHY).get(Component.class); assertThat(annotation.getString("value")).isEqualTo("meta2"); } @Test public void getDirectFromClassFavorsMoreLocallyDeclaredComposedAnnotationsOverInheritedAnnotations() { MergedAnnotation annotation = MergedAnnotations.from( - SubSubClassWithInheritedAnnotation.class, SearchStrategy.EXHAUSTIVE).get( + SubSubClassWithInheritedAnnotation.class, SearchStrategy.TYPE_HIERARCHY).get( Transactional.class); assertThat(annotation.getBoolean("readOnly")).isTrue(); } @@ -881,14 +881,14 @@ public class MergedAnnotationsTests { public void getDirectFromClassFavorsMoreLocallyDeclaredComposedAnnotationsOverInheritedComposedAnnotations() { MergedAnnotation annotation = MergedAnnotations.from( SubSubClassWithInheritedMetaAnnotation.class, - SearchStrategy.EXHAUSTIVE).get(Component.class); + SearchStrategy.TYPE_HIERARCHY).get(Component.class); assertThat(annotation.getString("value")).isEqualTo("meta2"); } @Test public void getDirectFromClassgetDirectFromClassMetaMetaAnnotatedClass() { MergedAnnotation annotation = MergedAnnotations.from( - MetaMetaAnnotatedClass.class, SearchStrategy.EXHAUSTIVE).get( + MetaMetaAnnotatedClass.class, SearchStrategy.TYPE_HIERARCHY).get( Component.class); assertThat(annotation.getString("value")).isEqualTo("meta2"); } @@ -896,7 +896,7 @@ public class MergedAnnotationsTests { @Test public void getDirectFromClassWithMetaMetaMetaAnnotatedClass() { MergedAnnotation annotation = MergedAnnotations.from( - MetaMetaMetaAnnotatedClass.class, SearchStrategy.EXHAUSTIVE).get( + MetaMetaMetaAnnotatedClass.class, SearchStrategy.TYPE_HIERARCHY).get( Component.class); assertThat(annotation.getString("value")).isEqualTo("meta2"); } @@ -905,14 +905,14 @@ public class MergedAnnotationsTests { public void getDirectFromClassWithAnnotatedClassWithMissingTargetMetaAnnotation() { // TransactionalClass is NOT annotated or meta-annotated with @Component MergedAnnotation annotation = MergedAnnotations.from(TransactionalClass.class, - SearchStrategy.EXHAUSTIVE).get(Component.class); + SearchStrategy.TYPE_HIERARCHY).get(Component.class); assertThat(annotation.isPresent()).isFalse(); } @Test public void getDirectFromClassWithMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { MergedAnnotation annotation = MergedAnnotations.from( - MetaCycleAnnotatedClass.class, SearchStrategy.EXHAUSTIVE).get( + MetaCycleAnnotatedClass.class, SearchStrategy.TYPE_HIERARCHY).get( Component.class); assertThat(annotation.isPresent()).isFalse(); } @@ -920,7 +920,7 @@ public class MergedAnnotationsTests { @Test public void getDirectFromClassWithInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( - InheritedAnnotationInterface.class, SearchStrategy.EXHAUSTIVE).get( + InheritedAnnotationInterface.class, SearchStrategy.TYPE_HIERARCHY).get( Transactional.class); assertThat(annotation.getAggregateIndex()).isEqualTo(0); } @@ -928,7 +928,7 @@ public class MergedAnnotationsTests { @Test public void getDirectFromClassWithSubInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( - SubInheritedAnnotationInterface.class, SearchStrategy.EXHAUSTIVE).get( + SubInheritedAnnotationInterface.class, SearchStrategy.TYPE_HIERARCHY).get( Transactional.class); assertThat(annotation.getAggregateIndex()).isEqualTo(1); } @@ -936,7 +936,7 @@ public class MergedAnnotationsTests { @Test public void getDirectFromClassWithSubSubInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( - SubSubInheritedAnnotationInterface.class, SearchStrategy.EXHAUSTIVE).get( + SubSubInheritedAnnotationInterface.class, SearchStrategy.TYPE_HIERARCHY).get( Transactional.class); assertThat(annotation.getAggregateIndex()).isEqualTo(2); } @@ -944,7 +944,7 @@ public class MergedAnnotationsTests { @Test public void getDirectFromClassWithNonInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( - NonInheritedAnnotationInterface.class, SearchStrategy.EXHAUSTIVE).get( + NonInheritedAnnotationInterface.class, SearchStrategy.TYPE_HIERARCHY).get( Order.class); assertThat(annotation.getAggregateIndex()).isEqualTo(0); } @@ -952,7 +952,7 @@ public class MergedAnnotationsTests { @Test public void getDirectFromClassWithSubNonInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( - SubNonInheritedAnnotationInterface.class, SearchStrategy.EXHAUSTIVE).get( + SubNonInheritedAnnotationInterface.class, SearchStrategy.TYPE_HIERARCHY).get( Order.class); assertThat(annotation.getAggregateIndex()).isEqualTo(1); } @@ -961,7 +961,7 @@ public class MergedAnnotationsTests { public void getDirectFromClassWithSubSubNonInheritedAnnotationInterface() { MergedAnnotation annotation = MergedAnnotations.from( SubSubNonInheritedAnnotationInterface.class, - SearchStrategy.EXHAUSTIVE).get(Order.class); + SearchStrategy.TYPE_HIERARCHY).get(Order.class); assertThat(annotation.getAggregateIndex()).isEqualTo(2); } @@ -1225,7 +1225,7 @@ public class MergedAnnotationsTests { @Test public void getValueFromAnnotation() throws Exception { Method method = TransactionalStringGeneric.class.getMethod("something", Object.class); - MergedAnnotation annotation = MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE) + MergedAnnotation annotation = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY) .get(Order.class); assertThat(annotation.getInt("value")).isEqualTo(1); } @@ -1244,7 +1244,7 @@ public class MergedAnnotationsTests { @Test public void getDefaultValueFromAnnotation() throws Exception { Method method = TransactionalStringGeneric.class.getMethod("something", Object.class); - MergedAnnotation annotation = MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE) + MergedAnnotation annotation = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY) .get(Order.class); assertThat(annotation.getDefaultValue("value")).contains(Ordered.LOWEST_PRECEDENCE); } @@ -1271,7 +1271,7 @@ public class MergedAnnotationsTests { public void getRepeatableDeclaredOnMethod() throws Exception { Method method = InterfaceWithRepeated.class.getMethod("foo"); Stream> annotations = MergedAnnotations.from( - method, SearchStrategy.EXHAUSTIVE).stream(MyRepeatable.class); + method, SearchStrategy.TYPE_HIERARCHY).stream(MyRepeatable.class); Stream values = annotations.map( annotation -> annotation.getString("value")); assertThat(values).containsExactly("A", "B", "C", "meta1"); @@ -1282,7 +1282,7 @@ public class MergedAnnotationsTests { RepeatableContainers containers = RepeatableContainers.of( BrokenContextConfiguration.class, BrokenHierarchy.class); assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> - MergedAnnotations.from(BrokenHierarchyClass.class, SearchStrategy.EXHAUSTIVE, containers, + MergedAnnotations.from(BrokenHierarchyClass.class, SearchStrategy.TYPE_HIERARCHY, containers, AnnotationFilter.PLAIN).get(BrokenHierarchy.class)) .withMessageStartingWith("Attribute 'value' in") .withMessageContaining(BrokenContextConfiguration.class.getName()) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java index 022df72c22..442946450c 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java @@ -71,7 +71,7 @@ public abstract class TestPropertySourceUtils { static MergedTestPropertySources buildMergedTestPropertySources(Class testClass) { - MergedAnnotations mergedAnnotations = MergedAnnotations.from(testClass, SearchStrategy.EXHAUSTIVE); + MergedAnnotations mergedAnnotations = MergedAnnotations.from(testClass, SearchStrategy.TYPE_HIERARCHY); return (mergedAnnotations.isPresent(TestPropertySource.class) ? mergeTestPropertySources(mergedAnnotations) : MergedTestPropertySources.empty()); }