From 899dea4ac3bae3853e8394ff70f28230e81b935d Mon Sep 17 00:00:00 2001 From: Jinghao Song Date: Wed, 18 Oct 2023 21:34:02 +0800 Subject: [PATCH] Fix code style --- .../PropertySourceBootstrapConfiguration.java | 3 +- .../config/BootstrapConfigurationTests.java | 39 ++++++++----------- .../src/test/resources/application.properties | 2 +- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java index 0aaaf736e..4a7e6ce85 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java @@ -288,8 +288,9 @@ private List addActiveProfilesTo(List profiles, PropertySource p.getProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME)).anyMatch("local"::equals)) + .isTrue(); + } + @Configuration(proxyBeanMethods = false) @EnableConfigurationProperties protected static class BareConfiguration { @@ -794,26 +811,4 @@ public void setFoo(List foo) { } - @Test - void activeAndIncludeProfileFromBootstrapPropertySource_WhenMultiplePlacesHaveActiveProfileProperties_ShouldOnlyAcceptTheTopPriority() { - String[] properties = new String[]{"spring.config.use-legacy-processing=true"}; - this.context = new SpringApplicationBuilder() - .web(WebApplicationType.NONE) - .properties(properties) - .sources(BareConfiguration.class) - .run("--spring.profiles.active=prod,secure"); - then(this.context.getEnvironment().acceptsProfiles("prod", "secure")).isTrue(); - // active profile from property sources with lower priority should not be included - then(this.context.getEnvironment().acceptsProfiles("local")).isFalse(); - then(this.context.getEnvironment().getActiveProfiles()).contains("prod", "secure"); - then(this.context.getEnvironment().getActiveProfiles()).doesNotContain("local"); - // check if active profile value could possibly exist in other property sources with lower priority - then(this.context.getEnvironment() - .getPropertySources() - .stream() - .map(p -> p.getProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME)) - .anyMatch("local"::equals) - ).isTrue(); - } - } diff --git a/spring-cloud-context/src/test/resources/application.properties b/spring-cloud-context/src/test/resources/application.properties index 4795a6c54..cfb461b5d 100644 --- a/spring-cloud-context/src/test/resources/application.properties +++ b/spring-cloud-context/src/test/resources/application.properties @@ -8,4 +8,4 @@ debug:true logging.level.org.hibernate=ERROR logging.level.com.zaxxer.hikari=ERROR myplaceholder=${vcap.services.myvcap.myvar} -spring.profiles.active=local \ No newline at end of file +spring.profiles.active=local