diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java index 650078d10591..1b1bc2b0f98e 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java @@ -516,6 +516,20 @@ void getMergedAnnotationWithImplicitAliasesInMetaAnnotationOnComposedAnnotation( assertThat(isAnnotated(element, name)).isTrue(); } + @Test + void getMergedAnnotationWithImplicitAliasesWithDefaultsInMetaAnnotationOnComposedAnnotation() { + Class element = ImplicitAliasesWithDefaultsClass.class; + String name = AliasesWithDefaults.class.getName(); + AliasesWithDefaults annotation = getMergedAnnotation(element, AliasesWithDefaults.class); + + assertThat(annotation).as("Should find @AliasesWithDefaults on " + element.getSimpleName()).isNotNull(); + assertThat(annotation.a1()).as("a1").isEqualTo("ImplicitAliasesWithDefaults"); + assertThat(annotation.a2()).as("a2").isEqualTo("ImplicitAliasesWithDefaults"); + + // Verify contracts between utility methods: + assertThat(isAnnotated(element, name)).isTrue(); + } + @Test void getMergedAnnotationAttributesWithInvalidConventionBasedComposedAnnotation() { Class element = InvalidConventionBasedComposedContextConfigClass.class; @@ -1064,7 +1078,6 @@ static class MetaCycleAnnotatedClass { String[] xmlConfigFiles() default {}; } - @ContextConfig @Retention(RetentionPolicy.RUNTIME) @interface AliasedComposedContextConfig { @@ -1105,6 +1118,27 @@ static class MetaCycleAnnotatedClass { @interface ComposedImplicitAliasesContextConfig { } + @Retention(RetentionPolicy.RUNTIME) + @interface AliasesWithDefaults { + + @AliasFor("a2") + String a1() default "AliasesWithDefaults"; + + @AliasFor("a1") + String a2() default "AliasesWithDefaults"; + } + + @Retention(RetentionPolicy.RUNTIME) + @AliasesWithDefaults + @interface ImplicitAliasesWithDefaults { + + @AliasFor(annotation = AliasesWithDefaults.class, attribute = "a1") + String b1() default "ImplicitAliasesWithDefaults"; + + @AliasFor(annotation = AliasesWithDefaults.class, attribute = "a2") + String b2() default "ImplicitAliasesWithDefaults"; + } + @ImplicitAliasesContextConfig @Retention(RetentionPolicy.RUNTIME) @interface TransitiveImplicitAliasesContextConfig { @@ -1410,6 +1444,10 @@ static class ImplicitAliasesContextConfigClass2 { static class ImplicitAliasesContextConfigClass3 { } + @ImplicitAliasesWithDefaults + static class ImplicitAliasesWithDefaultsClass { + } + @TransitiveImplicitAliasesContextConfig(groovy = "test.groovy") static class TransitiveImplicitAliasesContextConfigClass { }