diff --git a/spring-boot/src/main/java/org/springframework/boot/yaml/SpringProfileDocumentMatcher.java b/spring-boot/src/main/java/org/springframework/boot/yaml/SpringProfileDocumentMatcher.java index 771086af83ac..e1b5e1db34a0 100644 --- a/spring-boot/src/main/java/org/springframework/boot/yaml/SpringProfileDocumentMatcher.java +++ b/spring-boot/src/main/java/org/springframework/boot/yaml/SpringProfileDocumentMatcher.java @@ -68,10 +68,10 @@ public MatchStatus matches(Properties properties) { if (StringUtils.hasLength(negative)) { properties = new Properties(properties); properties.setProperty(SPRING_PROFILES, negative); - switch (activeProfilesMatcher.matches(properties)) { - case FOUND: + if (activeProfilesMatcher.matches(properties) == MatchStatus.FOUND) { return MatchStatus.NOT_FOUND; - case NOT_FOUND: + } + if (StringUtils.isEmpty(positive)) { return MatchStatus.FOUND; } properties.setProperty(SPRING_PROFILES, positive); diff --git a/spring-boot/src/test/java/org/springframework/boot/yaml/SpringProfileDocumentMatcherTests.java b/spring-boot/src/test/java/org/springframework/boot/yaml/SpringProfileDocumentMatcherTests.java index b246b18957ed..41ea2aed0a05 100644 --- a/spring-boot/src/test/java/org/springframework/boot/yaml/SpringProfileDocumentMatcherTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/yaml/SpringProfileDocumentMatcherTests.java @@ -87,8 +87,10 @@ public void testInverseMatchMulti() throws IOException { @Test public void negatedAndNonNegated() throws IOException { DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar", "blah"); - Properties properties = getProperties("spring.profiles: !baz,blah"); - assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.FOUND); + Properties expectFound = getProperties("spring.profiles: !baz,blah"); + assertThat(matcher.matches(expectFound)).isEqualTo(MatchStatus.FOUND); + Properties expectNotFound = getProperties("spring.profiles: !baz,another"); + assertThat(matcher.matches(expectNotFound)).isEqualTo(MatchStatus.NOT_FOUND); } @Test