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
This commit is contained in:
Sam Brannen
2022-07-08 18:59:06 +02:00
parent 6812de7b82
commit 73d92d66b9
11 changed files with 51 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
@@ -139,6 +140,7 @@ public class AnnotationScopeMetadataResolverTests {
@Scope("request")
@interface CustomRequestScopeWithAttributeOverride {
@AliasFor(annotation = Scope.class)
ScopedProxyMode proxyMode();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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.
@@ -52,6 +52,7 @@ import org.springframework.context.annotation.componentscan.simple.ClassWithNest
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.testfixture.SimpleMapScope;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
@@ -274,6 +275,7 @@ public class ComponentScanAnnotationIntegrationTests {
@Target(ElementType.TYPE)
public @interface ComposedConfiguration {
@AliasFor(annotation = ComponentScan.class)
String[] basePackages() default {};
}

View File

@@ -56,6 +56,7 @@ import org.springframework.beans.testfixture.beans.TestBean;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.StandardEnvironment;
@@ -1471,6 +1472,7 @@ class ConfigurationClassPostProcessorTests {
@Scope(scopeName = "prototype")
public @interface PrototypeScoped {
@AliasFor(annotation = Scope.class)
ScopedProxyMode proxyMode() default ScopedProxyMode.TARGET_CLASS;
}
@@ -1628,8 +1630,10 @@ class ConfigurationClassPostProcessorTests {
@Target(ElementType.TYPE)
public @interface ComposedConfigurationWithAttributeOverrides {
@AliasFor(annotation = ComponentScan.class)
String[] basePackages() default {};
@AliasFor(annotation = ComponentScan.class)
ComponentScan.Filter[] excludeFilters() default {};
}
@@ -1656,6 +1660,7 @@ class ConfigurationClassPostProcessorTests {
@Target(ElementType.TYPE)
public @interface ComposedComposedConfigurationWithAttributeOverrides {
@AliasFor(annotation = ComposedConfigurationWithAttributeOverrides.class)
String[] basePackages() default {};
}
@@ -1675,6 +1680,7 @@ class ConfigurationClassPostProcessorTests {
@Target(ElementType.TYPE)
public @interface MetaComponentScanConfigurationWithAttributeOverrides {
@AliasFor(annotation = ComponentScan.class)
String[] basePackages() default {};
}

View File

@@ -33,6 +33,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Component;
import static org.assertj.core.api.Assertions.assertThat;
@@ -259,6 +260,7 @@ class BeanMethodQualificationTests {
@Retention(RetentionPolicy.RUNTIME)
@interface InterestingBeanWithName {
@AliasFor(annotation = Bean.class)
String name();
}
@@ -271,6 +273,7 @@ class BeanMethodQualificationTests {
@Retention(RetentionPolicy.RUNTIME)
@interface InterestingNeedWithRequiredOverride {
@AliasFor(annotation = Autowired.class)
boolean required();
}