Make TestPropertyValues immutable

Update `TestPropertyValues` so that it is totally immutable. Methods
now return a new instance rather than changing existing state.

See gh-9875
This commit is contained in:
Phillip Webb
2017-07-26 15:38:58 -07:00
parent 07556cda51
commit ad9f28110c
8 changed files with 103 additions and 107 deletions

View File

@@ -95,7 +95,7 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
System.setProperty(key, "value");
try {
assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
get().withSystemProperty(key, null).run((loaded) -> {
get().withSystemProperties(key + "=").run((loaded) -> {
assertThat(System.getProperties()).doesNotContainKey(key);
});
assertThat(System.getProperties().getProperty(key)).isEqualTo("value");

View File

@@ -89,8 +89,8 @@ public class TestPropertyValuesTests {
@Test
public void andShouldChainAndAddSingleKeyValue() throws Exception {
TestPropertyValues.of("foo.bar=baz").and("hello.world", "hi")
.and("bling.blah", "bing").applyTo(this.environment, Type.MAP);
TestPropertyValues.of("foo.bar=baz").and("hello.world=hi").and("bling.blah=bing")
.applyTo(this.environment, Type.MAP);
assertThat(this.environment.getProperty("foo.bar")).isEqualTo("baz");
assertThat(this.environment.getProperty("hello.world")).isEqualTo("hi");
assertThat(this.environment.getProperty("bling.blah")).isEqualTo("bing");
@@ -127,7 +127,7 @@ public class TestPropertyValuesTests {
throws Exception {
System.setProperty("foo", "bar1");
try {
TestPropertyValues.ofPair("foo", null).applyToSystemProperties(() -> {
TestPropertyValues.of("foo").applyToSystemProperties(() -> {
assertThat(System.getProperties()).doesNotContainKey("foo");
return null;
});