diff --git a/spring-test/src/test/java/org/springframework/test/context/OverriddenMetaAnnotationAttributesTestContextAnnotationUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/OverriddenMetaAnnotationAttributesTestContextAnnotationUtilsTests.java index aaafad4413e..a24444ed80d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/OverriddenMetaAnnotationAttributesTestContextAnnotationUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/OverriddenMetaAnnotationAttributesTestContextAnnotationUtilsTests.java @@ -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. @@ -117,8 +117,10 @@ class OverriddenMetaAnnotationAttributesTestContextAnnotationUtilsTests { @Retention(RetentionPolicy.RUNTIME) @interface MetaLocationsConfig { + @AliasFor(annotation = ContextConfiguration.class) String[] locations() default {}; + @AliasFor(annotation = ContextConfiguration.class) boolean inheritLocations(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/TestContextAnnotationUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/TestContextAnnotationUtilsTests.java index 2755038a7d7..116c0112884 100644 --- a/spring-test/src/test/java/org/springframework/test/context/TestContextAnnotationUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/TestContextAnnotationUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 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. @@ -29,6 +29,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.core.SpringProperties; +import org.springframework.core.annotation.AliasFor; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @@ -557,14 +558,15 @@ class TestContextAnnotationUtilsTests { @Target(ElementType.TYPE) @interface MetaConfig { + @AliasFor(annotation = ContextConfiguration.class) + Class[] classes() default { DevConfig.class, ProductionConfig.class }; + class DevConfig { } class ProductionConfig { } - - Class[] classes() default { DevConfig.class, ProductionConfig.class }; } // ------------------------------------------------------------------------- diff --git a/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java b/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java index 4a9d5c39c53..d0d8084423f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java @@ -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. @@ -23,6 +23,7 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.core.Ordered; +import org.springframework.core.annotation.AliasFor; import org.springframework.core.annotation.AnnotationConfigurationException; import org.springframework.test.context.event.ApplicationEventsTestExecutionListener; import org.springframework.test.context.event.EventPublishingTestExecutionListener; @@ -209,7 +210,7 @@ class TestExecutionListenersTests { private void assertNumRegisteredListeners(Class testClass, int expected) { TestContextManager testContextManager = new TestContextManager(testClass); - assertThat(testContextManager.getTestExecutionListeners().size()).as("Num registered TELs for " + testClass).isEqualTo(expected); + assertThat(testContextManager.getTestExecutionListeners()).as("Num registered TELs for " + testClass).hasSize(expected); } @@ -294,6 +295,7 @@ class TestExecutionListenersTests { @Retention(RetentionPolicy.RUNTIME) @interface MetaListenersWithOverrides { + @AliasFor(annotation = TestExecutionListeners.class) Class[] listeners() default {FooTestExecutionListener.class, BarTestExecutionListener.class}; } @@ -302,8 +304,10 @@ class TestExecutionListenersTests { @Retention(RetentionPolicy.RUNTIME) @interface MetaInheritedListenersWithOverrides { + @AliasFor(annotation = TestExecutionListeners.class) Class[] listeners() default QuuxTestExecutionListener.class; + @AliasFor(annotation = TestExecutionListeners.class) boolean inheritListeners() default true; } @@ -311,8 +315,10 @@ class TestExecutionListenersTests { @Retention(RetentionPolicy.RUNTIME) @interface MetaNonInheritedListenersWithOverrides { + @AliasFor(annotation = TestExecutionListeners.class) Class[] listeners() default QuuxTestExecutionListener.class; + @AliasFor(annotation = TestExecutionListeners.class) boolean inheritListeners() default false; } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerTests.java index 26a728b7e55..d392198323f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerTests.java @@ -22,6 +22,7 @@ import java.lang.annotation.RetentionPolicy; import org.junit.Test; import org.junit.runners.model.FrameworkMethod; +import org.springframework.core.annotation.AliasFor; import org.springframework.test.annotation.Timed; import org.springframework.test.context.TestContextManager; @@ -94,6 +95,7 @@ public class SpringJUnit4ClassRunnerTests { @Retention(RetentionPolicy.RUNTIME) private static @interface MetaTimedWithOverride { + @AliasFor(annotation = Timed.class) long millis() default 1000; } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java index 1a204d36166..57618ea1258 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 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.runner.RunWith; import org.junit.runner.Runner; import org.junit.runners.JUnit4; +import org.springframework.core.annotation.AliasFor; import org.springframework.test.annotation.Timed; import org.springframework.test.context.TestExecutionListeners; @@ -112,12 +113,13 @@ public class TimedSpringRunnerTests { @Timed(millis = 10) @Retention(RetentionPolicy.RUNTIME) - private static @interface MetaTimed { + private @interface MetaTimed { } @Timed(millis = 1000) @Retention(RetentionPolicy.RUNTIME) - private static @interface MetaTimedWithOverride { + private @interface MetaTimedWithOverride { + @AliasFor(annotation = Timed.class) long millis() default 1000; } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java b/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java index e084468e39b..c1ac5401996 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -24,6 +24,7 @@ import java.lang.annotation.Target; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; +import org.springframework.core.annotation.AliasFor; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfilesResolver; import org.springframework.test.context.ContextConfiguration; @@ -42,6 +43,13 @@ import org.springframework.test.context.ContextConfiguration; @Target(ElementType.TYPE) public @interface ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig { + @AliasFor(annotation = ContextConfiguration.class) + Class[] classes() default { DevConfig.class, ProductionConfig.class, ResolverConfig.class }; + + @AliasFor(annotation = ActiveProfiles.class) + Class resolver() default CustomResolver.class; + + @Configuration @Profile("dev") static class DevConfig { @@ -81,9 +89,4 @@ public @interface ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig { } } - - Class[] classes() default { DevConfig.class, ProductionConfig.class, ResolverConfig.class }; - - Class resolver() default CustomResolver.class; - } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfig.java b/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfig.java index cbba9408899..e8fc3927cca 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -21,6 +21,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.core.annotation.AliasFor; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; @@ -38,8 +39,10 @@ import org.springframework.test.context.ContextConfiguration; @Target(ElementType.TYPE) public @interface ConfigClassesAndProfilesMetaConfig { + @AliasFor(annotation = ContextConfiguration.class) Class[] classes() default {}; + @AliasFor(annotation = ActiveProfiles.class) String[] profiles() default {}; } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java b/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java index b953200f5de..342c4cb54b6 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -24,6 +24,7 @@ import java.lang.annotation.Target; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; +import org.springframework.core.annotation.AliasFor; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; @@ -41,6 +42,12 @@ import org.springframework.test.context.ContextConfiguration; @Target(ElementType.TYPE) public @interface ConfigClassesAndProfilesWithCustomDefaultsMetaConfig { + @AliasFor(annotation = ContextConfiguration.class) + Class[] classes() default { DevConfig.class, ProductionConfig.class }; + + @AliasFor(annotation = ActiveProfiles.class) + String[] profiles() default "dev"; + @Configuration @Profile("dev") static class DevConfig { @@ -61,9 +68,4 @@ public @interface ConfigClassesAndProfilesWithCustomDefaultsMetaConfig { } } - - Class[] classes() default { DevConfig.class, ProductionConfig.class }; - - String[] profiles() default "dev"; - } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java index d305da8a769..3da7e5ed858 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java @@ -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. @@ -24,6 +24,7 @@ import org.springframework.beans.testfixture.beans.Employee; import org.springframework.beans.testfixture.beans.Pet; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.annotation.PojoAndStringConfig; +import org.springframework.test.context.junit4.annotation.meta.ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.ProductionConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -35,8 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 4.0 */ @RunWith(SpringJUnit4ClassRunner.class) -@ConfigClassesAndProfilesWithCustomDefaultsMetaConfig(classes = { PojoAndStringConfig.class, - ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.ProductionConfig.class }, profiles = "prod") +@ConfigClassesAndProfilesWithCustomDefaultsMetaConfig( + classes = { PojoAndStringConfig.class, ProductionConfig.class }, profiles = "prod") public class ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests { @Autowired @@ -65,4 +66,5 @@ public class ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTe public void verifyFoo() { assertThat(this.foo).isEqualTo("Production Foo"); } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java index d7a35fe4379..f4e66c55411 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java @@ -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. @@ -27,6 +27,7 @@ import org.mockito.Mockito; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.AliasFor; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.BootstrapContext; import org.springframework.test.context.BootstrapTestUtils; @@ -158,8 +159,10 @@ abstract class AbstractContextConfigurationUtilsTests { @Target(ElementType.TYPE) public static @interface MetaLocationsFooConfigWithOverrides { + @AliasFor(annotation = ContextConfiguration.class) String[] locations() default "/foo.xml"; + @AliasFor(annotation = ActiveProfiles.class) String[] profiles() default "foo"; } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java index c44b90e9aa1..40c9042ba2a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java @@ -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. @@ -25,6 +25,7 @@ import org.assertj.core.api.AssertionsForClassTypes; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.AliasFor; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.BootstrapTestUtils; import org.springframework.test.context.ContextConfiguration; @@ -466,6 +467,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt @Target(ElementType.TYPE) public static @interface SpringAppConfig { + @AliasFor(annotation = ContextConfiguration.class) Class[] classes() default {}; } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java b/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java index cf61b5e8704..ac314adb7c5 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java @@ -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. @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.annotation.AliasFor; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextHierarchy; @@ -579,6 +580,7 @@ class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConfigurati @Retention(RetentionPolicy.RUNTIME) private static @interface ContextConfigWithOverrides { + @AliasFor(annotation = ContextConfiguration.class) String[] locations() default "A.xml"; } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/DirtiesContextTestExecutionListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/support/DirtiesContextTestExecutionListenerTests.java index f79dfd46a14..6b39388c44a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/DirtiesContextTestExecutionListenerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/DirtiesContextTestExecutionListenerTests.java @@ -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. @@ -24,6 +24,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.BDDMockito; +import org.springframework.core.annotation.AliasFor; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; @@ -403,8 +404,10 @@ class DirtiesContextTestExecutionListenerTests { @Retention(RetentionPolicy.RUNTIME) @interface MetaDirtyWithOverrides { + @AliasFor(annotation = DirtiesContext.class) ClassMode classMode() default AFTER_EACH_TEST_METHOD; + @AliasFor(annotation = DirtiesContext.class) HierarchyMode hierarchyMode() default HierarchyMode.CURRENT_LEVEL; } diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java index 23b961e6ef6..ef5b9abf978 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java @@ -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. @@ -287,9 +287,10 @@ class TransactionalTestExecutionListenerTests { @Retention(RetentionPolicy.RUNTIME) private static @interface MetaTxWithOverride { - @AliasFor(annotation = Transactional.class, attribute = "value") + @AliasFor(annotation = Transactional.class) String transactionManager() default ""; + @AliasFor(annotation = Transactional.class) Propagation propagation() default REQUIRED; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java index 56d68011289..52e396e62cb 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java @@ -30,6 +30,7 @@ import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.DirectFieldAccessor; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.core.annotation.AliasFor; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.env.PropertiesPropertySource; @@ -550,8 +551,10 @@ class CrossOriginTests { @CrossOrigin private @interface ComposedCrossOrigin { + @AliasFor(annotation = CrossOrigin.class) String[] origins() default {}; + @AliasFor(annotation = CrossOrigin.class) String allowCredentials() default ""; } @@ -563,8 +566,6 @@ class CrossOriginTests { @RequestMapping(path = "/foo", method = RequestMethod.GET) public void foo() { } - - }