Browse Source

Stop using convention-based attribute overrides in tests in spring-test and spring-mvc

See gh-28760
pull/28771/head
Sam Brannen 4 years ago
parent
commit
0beee7dc69
  1. 4
      spring-test/src/test/java/org/springframework/test/context/OverriddenMetaAnnotationAttributesTestContextAnnotationUtilsTests.java
  2. 8
      spring-test/src/test/java/org/springframework/test/context/TestContextAnnotationUtilsTests.java
  3. 10
      spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java
  4. 2
      spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerTests.java
  5. 8
      spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java
  6. 15
      spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java
  7. 5
      spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfig.java
  8. 14
      spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java
  9. 8
      spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java
  10. 5
      spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java
  11. 4
      spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java
  12. 4
      spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java
  13. 5
      spring-test/src/test/java/org/springframework/test/context/support/DirtiesContextTestExecutionListenerTests.java
  14. 5
      spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java
  15. 5
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java

4
spring-test/src/test/java/org/springframework/test/context/OverriddenMetaAnnotationAttributesTestContextAnnotationUtilsTests.java

@ -1,5 +1,5 @@ @@ -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 { @@ -117,8 +117,10 @@ class OverriddenMetaAnnotationAttributesTestContextAnnotationUtilsTests {
@Retention(RetentionPolicy.RUNTIME)
@interface MetaLocationsConfig {
@AliasFor(annotation = ContextConfiguration.class)
String[] locations() default {};
@AliasFor(annotation = ContextConfiguration.class)
boolean inheritLocations();
}

8
spring-test/src/test/java/org/springframework/test/context/TestContextAnnotationUtilsTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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 };
}
// -------------------------------------------------------------------------

10
spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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 { @@ -294,6 +295,7 @@ class TestExecutionListenersTests {
@Retention(RetentionPolicy.RUNTIME)
@interface MetaListenersWithOverrides {
@AliasFor(annotation = TestExecutionListeners.class)
Class<? extends TestExecutionListener>[] listeners() default
{FooTestExecutionListener.class, BarTestExecutionListener.class};
}
@ -302,8 +304,10 @@ class TestExecutionListenersTests { @@ -302,8 +304,10 @@ class TestExecutionListenersTests {
@Retention(RetentionPolicy.RUNTIME)
@interface MetaInheritedListenersWithOverrides {
@AliasFor(annotation = TestExecutionListeners.class)
Class<? extends TestExecutionListener>[] listeners() default QuuxTestExecutionListener.class;
@AliasFor(annotation = TestExecutionListeners.class)
boolean inheritListeners() default true;
}
@ -311,8 +315,10 @@ class TestExecutionListenersTests { @@ -311,8 +315,10 @@ class TestExecutionListenersTests {
@Retention(RetentionPolicy.RUNTIME)
@interface MetaNonInheritedListenersWithOverrides {
@AliasFor(annotation = TestExecutionListeners.class)
Class<? extends TestExecutionListener>[] listeners() default QuuxTestExecutionListener.class;
@AliasFor(annotation = TestExecutionListeners.class)
boolean inheritListeners() default false;
}

2
spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerTests.java

@ -22,6 +22,7 @@ import java.lang.annotation.RetentionPolicy; @@ -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 { @@ -94,6 +95,7 @@ public class SpringJUnit4ClassRunnerTests {
@Retention(RetentionPolicy.RUNTIME)
private static @interface MetaTimedWithOverride {
@AliasFor(annotation = Timed.class)
long millis() default 1000;
}

8
spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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;
}

15
spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java

@ -1,5 +1,5 @@ @@ -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; @@ -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; @@ -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<? extends ActiveProfilesResolver> resolver() default CustomResolver.class;
@Configuration
@Profile("dev")
static class DevConfig {
@ -81,9 +89,4 @@ public @interface ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig { @@ -81,9 +89,4 @@ public @interface ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig {
}
}
Class<?>[] classes() default { DevConfig.class, ProductionConfig.class, ResolverConfig.class };
Class<? extends ActiveProfilesResolver> resolver() default CustomResolver.class;
}

5
spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfig.java

@ -1,5 +1,5 @@ @@ -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; @@ -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; @@ -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 {};
}

14
spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java

@ -1,5 +1,5 @@ @@ -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; @@ -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; @@ -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 { @@ -61,9 +68,4 @@ public @interface ConfigClassesAndProfilesWithCustomDefaultsMetaConfig {
}
}
Class<?>[] classes() default { DevConfig.class, ProductionConfig.class };
String[] profiles() default "dev";
}

8
spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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; @@ -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 @@ -65,4 +66,5 @@ public class ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTe
public void verifyFoo() {
assertThat(this.foo).isEqualTo("Production Foo");
}
}

5
spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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";
}

4
spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 @@ -466,6 +467,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
@Target(ElementType.TYPE)
public static @interface SpringAppConfig {
@AliasFor(annotation = ContextConfiguration.class)
Class<?>[] classes() default {};
}

4
spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 @@ -579,6 +580,7 @@ class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConfigurati
@Retention(RetentionPolicy.RUNTIME)
private static @interface ContextConfigWithOverrides {
@AliasFor(annotation = ContextConfiguration.class)
String[] locations() default "A.xml";
}

5
spring-test/src/test/java/org/springframework/test/context/support/DirtiesContextTestExecutionListenerTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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;
}

5
spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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;
}

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

@ -30,6 +30,7 @@ import org.junit.jupiter.api.BeforeEach; @@ -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 { @@ -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 { @@ -563,8 +566,6 @@ class CrossOriginTests {
@RequestMapping(path = "/foo", method = RequestMethod.GET)
public void foo() {
}
}

Loading…
Cancel
Save