SPR-17606 @Profile mishandles "not" operand mixed with "&" (#2066)
Correct handling of not/and expressions in ProfilesParser Issue: SPR-17606
This commit is contained in:
committed by
Juergen Hoeller
parent
815f151448
commit
952045c216
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -195,6 +195,56 @@ public class ProfilesTests {
|
||||
assertTrue(profiles.matches(activeProfiles("java")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofAndExpressionWithInvertedSingleElement() {
|
||||
Profiles profiles = Profiles.of("!spring & framework");
|
||||
assertOfAndExpressionWithInvertedSingleElement(profiles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofAndExpressionWithInBracketsInvertedSingleElement() {
|
||||
Profiles profiles = Profiles.of("(!spring) & framework");
|
||||
assertOfAndExpressionWithInvertedSingleElement(profiles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofAndExpressionWithInvertedSingleElementInBrackets() {
|
||||
Profiles profiles = Profiles.of("! (spring) & framework");
|
||||
assertOfAndExpressionWithInvertedSingleElement(profiles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofAndExpressionWithInvertedSingleElementInBracketsWithoutSpaces() {
|
||||
Profiles profiles = Profiles.of("!(spring)&framework");
|
||||
assertOfAndExpressionWithInvertedSingleElement(profiles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofAndExpressionWithInvertedSingleElementWithoutSpaces() {
|
||||
Profiles profiles = Profiles.of("!spring&framework");
|
||||
assertOfAndExpressionWithInvertedSingleElement(profiles);
|
||||
}
|
||||
|
||||
private void assertOfAndExpressionWithInvertedSingleElement(Profiles profiles) {
|
||||
assertTrue(profiles.matches(activeProfiles("framework")));
|
||||
assertFalse(profiles.matches(activeProfiles("java")));
|
||||
assertFalse(profiles.matches(activeProfiles("spring", "framework")));
|
||||
assertFalse(profiles.matches(activeProfiles("spring")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofOrExpressionWithInvertedSingleElementWithoutSpaces() {
|
||||
Profiles profiles = Profiles.of("!spring|framework");
|
||||
assertOfOrExpressionWithInvertedSingleElement(profiles);
|
||||
}
|
||||
|
||||
private void assertOfOrExpressionWithInvertedSingleElement(Profiles profiles) {
|
||||
assertTrue(profiles.matches(activeProfiles("framework")));
|
||||
assertTrue(profiles.matches(activeProfiles("java")));
|
||||
assertTrue(profiles.matches(activeProfiles("spring", "framework")));
|
||||
assertFalse(profiles.matches(activeProfiles("spring")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofNotOrExpression() {
|
||||
Profiles profiles = Profiles.of("!(spring | framework)");
|
||||
|
||||
Reference in New Issue
Block a user