From 4eab9476a61609aa6d0796c1e70649d38e51e191 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 17 May 2021 14:13:29 +0100 Subject: [PATCH] Polish "Detect use of spring.profiles.include as a YAML list" See gh-26205 --- .../config/ConfigDataEnvironmentTests.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java index 7de6ba9472b..7a3ce09a081 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java @@ -47,7 +47,6 @@ import org.springframework.mock.env.MockPropertySource; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNoException; import static org.mockito.Mockito.mock; /** @@ -221,7 +220,7 @@ class ConfigDataEnvironmentTests { @ParameterizedTest @CsvSource({ "include", "include[0]" }) - void processAndApplyThrowExceptionWhenActivateProfileWithProfileInclude(String property, TestInfo info) { + void processAndApplyWhenHasProfileIncludeInProfileSpecificDocumentThrowsException(String property, TestInfo info) { this.environment.setProperty("spring.config.location", getConfigLocation(info)); ConfigDataEnvironment configDataEnvironment = new ConfigDataEnvironment(this.logFactory, this.bootstrapContext, this.environment, this.resourceLoader, this.additionalProfiles, null) { @@ -237,16 +236,15 @@ class ConfigDataEnvironmentTests { mock(ConfigDataResource.class), false, data, 0)); return super.createContributors(contributors); } - }; + }; assertThatExceptionOfType(InactiveConfigDataAccessException.class) .isThrownBy(configDataEnvironment::processAndApply); } @ParameterizedTest - @CsvSource({ "spring.config.activate.on-profile", "spring.profiles.include", "spring.profiles.include[0]" }) - void processAndApplyDoseNotThrowExceptionWhenUsingEitherActivateProfileOrProfileInclude(String property, - TestInfo info) { + @CsvSource({ "spring.profiles.include", "spring.profiles.include[0]" }) + void processAndApplyIncludesProfilesFromSpringProfilesInclude(String property, TestInfo info) { this.environment.setProperty("spring.config.location", getConfigLocation(info)); ConfigDataEnvironment configDataEnvironment = new ConfigDataEnvironment(this.logFactory, this.bootstrapContext, this.environment, this.resourceLoader, this.additionalProfiles, null) { @@ -255,15 +253,16 @@ class ConfigDataEnvironmentTests { protected ConfigDataEnvironmentContributors createContributors( List contributors) { Map source = new LinkedHashMap<>(); - source.put(property, "only"); + source.put(property, "included"); ConfigData data = new ConfigData(Collections.singleton(new MapPropertySource("test", source))); contributors.add(ConfigDataEnvironmentContributor.ofUnboundImport(ConfigDataLocation.of("test"), mock(ConfigDataResource.class), false, data, 0)); return super.createContributors(contributors); } - }; - assertThatNoException().isThrownBy(configDataEnvironment::processAndApply); + }; + configDataEnvironment.processAndApply(); + assertThat(this.environment.getActiveProfiles()).containsExactly("included"); } @Test