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 792dc1f6def8..b0be3a216b57 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 @@ -197,7 +197,7 @@ void typeHierarchyStrategyOnClassWhenHasSuperclassScansSuperclass() { } @Test - void typeHierarchyStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() { + void typeHierarchyStrategyOnClassWhenHasSingleInterfaceScansInterfaces() { Class source = WithSingleInterface.class; assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2"); @@ -353,7 +353,7 @@ void typeHierarchyStrategyOnMethodWhenHasSuperclassScansSuperclass() { } @Test - void typeHierarchyStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() { + void typeHierarchyStrategyOnMethodWhenHasInterfaceScansInterfaces() { Method source = methodFrom(WithSingleInterface.class); assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2"); 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 8ffd0eeb8939..340b0031a210 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 @@ -679,12 +679,9 @@ void getWithTypeHierarchyFromSubSubNonInheritedAnnotationInterface() { } @Test - void getWithTypeHierarchyInheritedFromInterfaceMethod() - throws NoSuchMethodException { - Method method = ConcreteClassWithInheritedAnnotation.class.getMethod( - "handleFromInterface"); - MergedAnnotation annotation = MergedAnnotations.from(method, - SearchStrategy.TYPE_HIERARCHY).get(Order.class); + void getWithTypeHierarchyInheritedFromInterfaceMethod() throws Exception { + Method method = ConcreteClassWithInheritedAnnotation.class.getMethod("handleFromInterface"); + MergedAnnotation annotation = MergedAnnotations.from(method,SearchStrategy.TYPE_HIERARCHY).get(Order.class); assertThat(annotation.isPresent()).isTrue(); assertThat(annotation.getAggregateIndex()).isEqualTo(1); } @@ -1384,7 +1381,7 @@ void getDefaultValueFromAnnotationType() { } @Test - void getRepeatableDeclaredOnMethod() throws Exception { + void streamRepeatableDeclaredOnMethod() throws Exception { Method method = InterfaceWithRepeated.class.getMethod("foo"); Stream> annotations = MergedAnnotations.from( method, SearchStrategy.TYPE_HIERARCHY).stream(MyRepeatable.class); @@ -1395,7 +1392,7 @@ void getRepeatableDeclaredOnMethod() throws Exception { @Test @SuppressWarnings("deprecation") - void getRepeatableDeclaredOnClassWithAttributeAliases() { + void streamRepeatableDeclaredOnClassWithAttributeAliases() { assertThat(MergedAnnotations.from(HierarchyClass.class).stream( TestConfiguration.class)).isEmpty(); RepeatableContainers containers = RepeatableContainers.of(TestConfiguration.class, @@ -1409,7 +1406,7 @@ void getRepeatableDeclaredOnClassWithAttributeAliases() { } @Test - void getRepeatableDeclaredOnClass() { + void streamRepeatableDeclaredOnClass() { Class element = MyRepeatableClass.class; String[] expectedValuesJava = { "A", "B", "C" }; String[] expectedValuesSpring = { "A", "B", "C", "meta1" }; @@ -1417,7 +1414,7 @@ void getRepeatableDeclaredOnClass() { } @Test - void getRepeatableDeclaredOnSuperclass() { + void streamRepeatableDeclaredOnSuperclass() { Class element = SubMyRepeatableClass.class; String[] expectedValuesJava = { "A", "B", "C" }; String[] expectedValuesSpring = { "A", "B", "C", "meta1" }; @@ -1425,7 +1422,7 @@ void getRepeatableDeclaredOnSuperclass() { } @Test - void getRepeatableDeclaredOnClassAndSuperclass() { + void streamRepeatableDeclaredOnClassAndSuperclass() { Class element = SubMyRepeatableWithAdditionalLocalDeclarationsClass.class; String[] expectedValuesJava = { "X", "Y", "Z" }; String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" }; @@ -1433,7 +1430,7 @@ void getRepeatableDeclaredOnClassAndSuperclass() { } @Test - void getRepeatableDeclaredOnMultipleSuperclasses() { + void streamRepeatableDeclaredOnMultipleSuperclasses() { Class element = SubSubMyRepeatableWithAdditionalLocalDeclarationsClass.class; String[] expectedValuesJava = { "X", "Y", "Z" }; String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" }; @@ -1441,7 +1438,7 @@ void getRepeatableDeclaredOnMultipleSuperclasses() { } @Test - void getDirectRepeatablesDeclaredOnClass() { + void streamDirectRepeatablesDeclaredOnClass() { Class element = MyRepeatableClass.class; String[] expectedValuesJava = { "A", "B", "C" }; String[] expectedValuesSpring = { "A", "B", "C", "meta1" }; @@ -1449,7 +1446,7 @@ void getDirectRepeatablesDeclaredOnClass() { } @Test - void getDirectRepeatablesDeclaredOnSuperclass() { + void streamDirectRepeatablesDeclaredOnSuperclass() { Class element = SubMyRepeatableClass.class; String[] expectedValuesJava = {}; String[] expectedValuesSpring = {}; @@ -1476,20 +1473,17 @@ private void testExplicitRepeatables(SearchStrategy searchStrategy, Class ele MergedAnnotations annotations = MergedAnnotations.from(element, searchStrategy, RepeatableContainers.of(MyRepeatable.class, MyRepeatableContainer.class), AnnotationFilter.PLAIN); - assertThat(annotations.stream(MyRepeatable.class).filter( - MergedAnnotationPredicates.firstRunOf( - MergedAnnotation::getAggregateIndex)).map( - annotation -> annotation.getString( - "value"))).containsExactly(expected); + Stream values = annotations.stream(MyRepeatable.class) + .filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex)) + .map(annotation -> annotation.getString("value")); + assertThat(values).containsExactly(expected); } private void testStandardRepeatables(SearchStrategy searchStrategy, Class element, String[] expected) { - MergedAnnotations annotations = MergedAnnotations.from(element, searchStrategy); - assertThat(annotations.stream(MyRepeatable.class).filter( - MergedAnnotationPredicates.firstRunOf( - MergedAnnotation::getAggregateIndex)).map( - annotation -> annotation.getString( - "value"))).containsExactly(expected); + Stream values = MergedAnnotations.from(element, searchStrategy).stream(MyRepeatable.class) + .filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex)) + .map(annotation -> annotation.getString("value")); + assertThat(values).containsExactly(expected); } @Test