Skip to content

Commit 73d92d6

Browse files
committed
Stop using convention-based annotation attribute overrides in tests
This commit replaces convention-based annotation attribute overrides in tests with explicit use of @AliasFor -- except for tests in spring-core, since we still want to test our support for convention-based annotation attribute overrides. See gh-28760
1 parent 6812de7 commit 73d92d6

File tree

11 files changed

+51
-4
lines changed

11 files changed

+51
-4
lines changed

spring-context/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
2525
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
2626
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
2727
import org.springframework.beans.factory.config.BeanDefinition;
28+
import org.springframework.core.annotation.AliasFor;
2829
import org.springframework.core.type.classreading.MetadataReader;
2930
import org.springframework.core.type.classreading.MetadataReaderFactory;
3031
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
@@ -139,6 +140,7 @@ public void setScopeAnnotationTypeWithNullType() {
139140
@Scope("request")
140141
@interface CustomRequestScopeWithAttributeOverride {
141142

143+
@AliasFor(annotation = Scope.class)
142144
ScopedProxyMode proxyMode();
143145
}
144146

spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,6 +52,7 @@
5252
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
5353
import org.springframework.context.support.GenericApplicationContext;
5454
import org.springframework.context.testfixture.SimpleMapScope;
55+
import org.springframework.core.annotation.AliasFor;
5556
import org.springframework.core.env.ConfigurableEnvironment;
5657
import org.springframework.core.env.Environment;
5758
import org.springframework.core.env.Profiles;
@@ -274,6 +275,7 @@ public void withBasePackagesAndValueAlias() {
274275
@Target(ElementType.TYPE)
275276
public @interface ComposedConfiguration {
276277

278+
@AliasFor(annotation = ComponentScan.class)
277279
String[] basePackages() default {};
278280
}
279281

spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.springframework.context.ConfigurableApplicationContext;
5757
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
5858
import org.springframework.core.ResolvableType;
59+
import org.springframework.core.annotation.AliasFor;
5960
import org.springframework.core.annotation.Order;
6061
import org.springframework.core.env.ConfigurableEnvironment;
6162
import org.springframework.core.env.StandardEnvironment;
@@ -1471,6 +1472,7 @@ public String toString() {
14711472
@Scope(scopeName = "prototype")
14721473
public @interface PrototypeScoped {
14731474

1475+
@AliasFor(annotation = Scope.class)
14741476
ScopedProxyMode proxyMode() default ScopedProxyMode.TARGET_CLASS;
14751477
}
14761478

@@ -1628,8 +1630,10 @@ public static class ComposedConfigurationClass {
16281630
@Target(ElementType.TYPE)
16291631
public @interface ComposedConfigurationWithAttributeOverrides {
16301632

1633+
@AliasFor(annotation = ComponentScan.class)
16311634
String[] basePackages() default {};
16321635

1636+
@AliasFor(annotation = ComponentScan.class)
16331637
ComponentScan.Filter[] excludeFilters() default {};
16341638
}
16351639

@@ -1656,6 +1660,7 @@ public static class ExtendedConfigurationWithAttributeOverrideForExcludeFilter e
16561660
@Target(ElementType.TYPE)
16571661
public @interface ComposedComposedConfigurationWithAttributeOverrides {
16581662

1663+
@AliasFor(annotation = ComposedConfigurationWithAttributeOverrides.class)
16591664
String[] basePackages() default {};
16601665
}
16611666

@@ -1675,6 +1680,7 @@ public static class ComposedComposedConfigurationWithAttributeOverridesClass {
16751680
@Target(ElementType.TYPE)
16761681
public @interface MetaComponentScanConfigurationWithAttributeOverrides {
16771682

1683+
@AliasFor(annotation = ComponentScan.class)
16781684
String[] basePackages() default {};
16791685
}
16801686

spring-context/src/test/java/org/springframework/context/annotation/configuration/BeanMethodQualificationTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.context.annotation.Lazy;
3434
import org.springframework.context.annotation.Scope;
3535
import org.springframework.context.annotation.ScopedProxyMode;
36+
import org.springframework.core.annotation.AliasFor;
3637
import org.springframework.stereotype.Component;
3738

3839
import static org.assertj.core.api.Assertions.assertThat;
@@ -259,6 +260,7 @@ static class CustomPojo {
259260
@Retention(RetentionPolicy.RUNTIME)
260261
@interface InterestingBeanWithName {
261262

263+
@AliasFor(annotation = Bean.class)
262264
String name();
263265
}
264266

@@ -271,6 +273,7 @@ static class CustomPojo {
271273
@Retention(RetentionPolicy.RUNTIME)
272274
@interface InterestingNeedWithRequiredOverride {
273275

276+
@AliasFor(annotation = Autowired.class)
274277
boolean required();
275278
}
276279

spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,13 +1061,17 @@ static class MetaCycleAnnotatedClass {
10611061
@Retention(RetentionPolicy.RUNTIME)
10621062
@interface ConventionBasedComposedContextConfig {
10631063

1064+
// Do NOT use @AliasFor here until Spring 6.1
1065+
// @AliasFor(annotation = ContextConfig.class)
10641066
String[] locations() default {};
10651067
}
10661068

10671069
@ContextConfig(value = "duplicateDeclaration")
10681070
@Retention(RetentionPolicy.RUNTIME)
10691071
@interface InvalidConventionBasedComposedContextConfig {
10701072

1073+
// Do NOT use @AliasFor here until Spring 6.1
1074+
// @AliasFor(annotation = ContextConfig.class)
10711075
String[] locations();
10721076
}
10731077

@@ -1225,9 +1229,13 @@ static class MetaCycleAnnotatedClass {
12251229
@AliasFor(annotation = ContextConfig.class, attribute = "locations")
12261230
String[] locations() default {};
12271231

1232+
// Do NOT use @AliasFor(annotation = ...) here until Spring 6.1
1233+
// @AliasFor(annotation = ContextConfig.class, attribute = "classes")
12281234
@AliasFor("value")
12291235
Class<?>[] classes() default {};
12301236

1237+
// Do NOT use @AliasFor(annotation = ...) here until Spring 6.1
1238+
// @AliasFor(annotation = ContextConfig.class, attribute = "classes")
12311239
@AliasFor("classes")
12321240
Class<?>[] value() default {};
12331241
}
@@ -1266,6 +1274,8 @@ static class MetaCycleAnnotatedClass {
12661274
@Retention(RetentionPolicy.RUNTIME)
12671275
@interface ConventionBasedSinglePackageComponentScan {
12681276

1277+
// Do NOT use @AliasFor here until Spring 6.1
1278+
// @AliasFor(annotation = ComponentScan.class)
12691279
String basePackages();
12701280
}
12711281

spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,8 @@ enum RequestMethod {
13671367
@WebMapping(method = RequestMethod.POST, name = "")
13681368
@interface Post {
13691369

1370+
// Do NOT use @AliasFor here until Spring 6.1
1371+
// @AliasFor(annotation = WebMapping.class)
13701372
String path() default "";
13711373
}
13721374

spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,13 +2425,17 @@ static class MetaMetaAliasedTransactionalClass {
24252425
@Retention(RetentionPolicy.RUNTIME)
24262426
@interface ConventionBasedComposedContextConfiguration {
24272427

2428+
// Do NOT use @AliasFor here until Spring 6.1
2429+
// @AliasFor(annotation = ContextConfiguration.class)
24282430
String[] locations() default {};
24292431
}
24302432

24312433
@ContextConfiguration(value = "duplicateDeclaration")
24322434
@Retention(RetentionPolicy.RUNTIME)
24332435
@interface InvalidConventionBasedComposedContextConfiguration {
24342436

2437+
// Do NOT use @AliasFor here until Spring 6.1
2438+
// @AliasFor(annotation = ContextConfiguration.class)
24352439
String[] locations();
24362440
}
24372441

@@ -2443,6 +2447,8 @@ static class MetaMetaAliasedTransactionalClass {
24432447
@Retention(RetentionPolicy.RUNTIME)
24442448
@interface HalfConventionBasedAndHalfAliasedComposedContextConfiguration {
24452449

2450+
// Do NOT use @AliasFor here until Spring 6.1
2451+
// @AliasFor(annotation = ContextConfiguration.class)
24462452
String[] locations() default {};
24472453

24482454
@AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
@@ -2564,9 +2570,13 @@ static class MetaMetaAliasedTransactionalClass {
25642570
@AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
25652571
String[] locations() default {};
25662572

2573+
// Do NOT use @AliasFor(annotation = ...) here until Spring 6.1
2574+
// @AliasFor(annotation = ContextConfiguration.class, attribute = "classes")
25672575
@AliasFor("value")
25682576
Class<?>[] classes() default {};
25692577

2578+
// Do NOT use @AliasFor(annotation = ...) here until Spring 6.1
2579+
// @AliasFor(annotation = ContextConfiguration.class, attribute = "classes")
25702580
@AliasFor("classes")
25712581
Class<?>[] value() default {};
25722582
}
@@ -2603,6 +2613,8 @@ static class MetaMetaAliasedTransactionalClass {
26032613
@Retention(RetentionPolicy.RUNTIME)
26042614
@interface ConventionBasedSinglePackageComponentScan {
26052615

2616+
// Do NOT use @AliasFor here until Spring 6.1
2617+
// @AliasFor(annotation = ComponentScan.class)
26062618
String basePackages();
26072619
}
26082620

@@ -3193,6 +3205,8 @@ public String toString() {
31933205
@RequestMapping(method = RequestMethod.POST, name = "")
31943206
@interface PostMapping {
31953207

3208+
// Do NOT use @AliasFor here until Spring 6.1
3209+
// @AliasFor(annotation = RequestMapping.class)
31963210
String path() default "";
31973211
}
31983212

spring-core/src/test/java/org/springframework/core/annotation/TypeMappedAnnotationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ private static class WithExplicitAliasToMetaAnnotation {
196196

197197
String value() default "";
198198

199+
// Do NOT use @AliasFor here until Spring 6.1
200+
// @AliasFor(annotation = ConventionAliasMetaAnnotationTarget.class)
199201
String convention() default "";
200202
}
201203

spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ private static class AnnotatedComponentSubClass extends AnnotatedComponent {
549549
@Target(ElementType.TYPE)
550550
public @interface ComposedConfigurationWithAttributeOverrides {
551551

552+
// Do NOT use @AliasFor here until Spring 6.1
553+
// @AliasFor(annotation = TestComponentScan.class)
552554
String[] basePackages() default {};
553555
}
554556

spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
2929

3030
import org.springframework.aop.framework.Advised;
3131
import org.springframework.aop.framework.ProxyFactory;
32+
import org.springframework.core.annotation.AliasFor;
3233
import org.springframework.core.annotation.AnnotationUtils;
3334
import org.springframework.core.testfixture.io.SerializationTestUtils;
3435
import org.springframework.transaction.TransactionManager;
@@ -668,6 +669,7 @@ public int getAge() {
668669
@Transactional(rollbackFor = Exception.class, noRollbackFor = IOException.class)
669670
@interface TxWithAttribute {
670671

672+
@AliasFor(annotation = Transactional.class)
671673
boolean readOnly();
672674
}
673675

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
import org.junit.jupiter.api.Test;
3333

3434
import org.springframework.context.annotation.Bean;
35+
import org.springframework.core.annotation.AliasFor;
3536
import org.springframework.format.annotation.DateTimeFormat;
3637
import org.springframework.format.annotation.DateTimeFormat.ISO;
3738
import org.springframework.http.HttpEntity;
@@ -635,6 +636,7 @@ public void handleInput() {
635636
@Documented
636637
private @interface PostJson {
637638

639+
@AliasFor(annotation = RequestMapping.class)
638640
String[] path() default {};
639641
}
640642

0 commit comments

Comments
 (0)