From 136af0b1643ac43f3be87ca11a10a22047632965 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 25 Jul 2019 23:15:33 +0200 Subject: [PATCH] Overhaul repeatable @TestPropertySource support Prior to this commit, if multiple, directly present `@TestPropertySource` annotations declared the same property, the precedence ordering was top-down instead of bottom-up, in contrast to the semantics for class hierarchies. In other words, a subsequent `@TestPropertySource` annotation could not override a property in a previous `@TestPropertySource` annotation. This commit overhauls the internals of `TestPropertySourceUtils` in order to provide proper support for property overrides within local, directly present `@TestPropertySource` declarations. Specifically, the `locations` and `properties` attributes from all `@TestPropertySource` declarations that are directly present or meta-present on a given class are now merged into a single instance of `TestPropertySourceAttributes` internally, with assertions in place to ensure that such "same level" `@TestPropertySource` declarations do not configure different values for the `inheritLocations` and `inheritProperties` flags. Effectively, all "same level" `@TestPropertySource` declarations are treated internally as if there were only one such annotation declared by the user. See gh-23320 --- .../test/context/TestPropertySource.java | 2 + .../test/context/TestPropertySources.java | 19 +- .../support/TestPropertySourceAttributes.java | 82 +++------ .../support/TestPropertySourceUtils.java | 172 ++++++++++++++---- .../env/TestPropertySourceTestSuite.java | 44 +++++ ...ava => AbstractClassWithTestProperty.java} | 9 +- ...actRepeatableTestPropertySourceTests.java} | 28 +-- ...ectionRepeatedTestPropertySourceTests.java | 42 +++++ ...sFilesRepeatedTestPropertySourceTests.java | 45 +++++ ...ertyAndInheritedInlinedPropertyTests.java} | 23 ++- ...dPropertyAndMetaInlinedPropertyTests.java} | 18 +- ...nheritedAndMetaInlinedPropertiesTests.java | 52 ++++++ ...verridesInheritedInlinedPropertyTests.java | 43 +++++ ...rtyOverridesMetaInlinedPropertyTests.java} | 23 ++- ...pertiesFileAndMetaPropertiesFileTests.java | 62 +++++++ ...erty.java => MetaInlinedTestProperty.java} | 8 +- .../ParentClassWithTestProperties.java | 30 --- .../RepeatedTestPropertySourceTests.java | 43 +++++ ...sFilesRepeatedTestPropertySourceTests.java | 41 +++++ .../TestPropertySourceInheritTests.java | 71 -------- ...omMetaAnnotationOverridesLocallyTests.java | 67 ------- ...ourceInheritedFromMetaAnnotationTests.java | 73 -------- ...MetaAnnotationWithPropertiesFileTests.java | 76 -------- ...artialOverridesInheritedPropertyTests.java | 63 ------- ...ropertySourceRepeatableOverridesTests.java | 58 ------ .../TestPropertySourceRepeatableTests.java | 73 -------- ...eatableWithDefaultPropertiesFileTests.java | 73 -------- ...urceRepeatableWithPropertiesFileTests.java | 73 -------- .../support/TestPropertySourceUtilsTests.java | 112 ++++++++---- .../src/test/resources/log4j2-test.xml | 1 + ...RepeatedTestPropertySourceTests.properties | 1 + ...eWithDefaultPropertiesFileTests.properties | 1 - .../context/env/repeatable/first.properties | 4 +- .../context/env/repeatable/local.properties | 2 +- .../context/env/repeatable/meta.properties | 2 +- .../context/env/repeatable/second.properties | 3 +- 36 files changed, 686 insertions(+), 853 deletions(-) create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/TestPropertySourceTestSuite.java rename spring-test/src/test/java/org/springframework/test/context/env/repeatable/{ParentClassWithMultipleTestProperties.java => AbstractClassWithTestProperty.java} (73%) rename spring-test/src/test/java/org/springframework/test/context/env/repeatable/{TestPropertySourceOverridesInheritedPropertyTests.java => AbstractRepeatableTestPropertySourceTests.java} (57%) create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/DefaultPropertiesFileDetectionRepeatedTestPropertySourceTests.java create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/ExplicitPropertiesFilesRepeatedTestPropertySourceTests.java rename spring-test/src/test/java/org/springframework/test/context/env/repeatable/{AnnotationWithTestPropertyInPropertiesFile.java => LocalInlinedPropertyAndInheritedInlinedPropertyTests.java} (65%) rename spring-test/src/test/java/org/springframework/test/context/env/repeatable/{FooTestPropertyDeclaration.java => LocalInlinedPropertyAndMetaInlinedPropertyTests.java} (63%) create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesInheritedAndMetaInlinedPropertiesTests.java create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesInheritedInlinedPropertyTests.java rename spring-test/src/test/java/org/springframework/test/context/env/repeatable/{FooTestProperty.java => LocalInlinedPropertyOverridesMetaInlinedPropertyTests.java} (64%) create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalPropertiesFileAndMetaPropertiesFileTests.java rename spring-test/src/test/java/org/springframework/test/context/env/repeatable/{AnnotationWithTestProperty.java => MetaInlinedTestProperty.java} (82%) delete mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/ParentClassWithTestProperties.java create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/RepeatedTestPropertySourceTests.java create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/ReversedExplicitPropertiesFilesRepeatedTestPropertySourceTests.java delete mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/TestPropertySourceInheritTests.java delete mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/TestPropertySourceInheritedFromMetaAnnotationOverridesLocallyTests.java delete mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/TestPropertySourceInheritedFromMetaAnnotationTests.java delete mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/TestPropertySourceInheritedFromMetaAnnotationWithPropertiesFileTests.java delete mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/TestPropertySourcePartialOverridesInheritedPropertyTests.java delete mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/TestPropertySourceRepeatableOverridesTests.java delete mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/TestPropertySourceRepeatableTests.java delete mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/TestPropertySourceRepeatableWithDefaultPropertiesFileTests.java delete mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/TestPropertySourceRepeatableWithPropertiesFileTests.java create mode 100644 spring-test/src/test/resources/org/springframework/test/context/env/repeatable/DefaultPropertiesFileDetectionRepeatedTestPropertySourceTests.properties delete mode 100644 spring-test/src/test/resources/org/springframework/test/context/env/repeatable/TestPropertySourceRepeatableWithDefaultPropertiesFileTests.properties diff --git a/spring-test/src/main/java/org/springframework/test/context/TestPropertySource.java b/spring-test/src/main/java/org/springframework/test/context/TestPropertySource.java index a3c57b97e3..b42e2649bb 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestPropertySource.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestPropertySource.java @@ -68,6 +68,8 @@ import org.springframework.core.annotation.AliasFor; *