From a71d73c30751901aee483a3cc15f36d476d4c376 Mon Sep 17 00:00:00 2001 From: Ashley Frieze Date: Sun, 12 Nov 2023 15:40:56 +0000 Subject: [PATCH] Support removal of environment variables and system properties --- README.md | 38 ++++++ .../EnvironmentVariableMocker.java | 9 +- .../environment/EnvironmentVariables.java | 17 ++- .../properties/SystemProperties.java | 73 +---------- .../properties/SystemPropertiesImpl.java | 110 +++++++++++++++++ .../resource/NameValuePairSetter.java | 10 +- .../environment/EnvironmentVariablesTest.java | 59 +++++++++ .../properties/SystemPropertiesTest.java | 113 ++++++++++++++++++ system-stubs-junit4/pom.xml | 6 + .../rules/EnvironmentVariablesRule.java | 7 ++ .../rules/SystemPropertiesRule.java | 18 +-- .../rules/EnvironmentVariablesRuleTest.java | 34 ++++++ 12 files changed, 401 insertions(+), 93 deletions(-) create mode 100644 system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesImpl.java diff --git a/README.md b/README.md index 711723c..e2b3e8f 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,9 @@ See the full guide to [JUnit 5](system-stubs-jupiter/README.md), or use it with ## Using System Stubs Individually +The plugins for JUnit etc will allow the stub objects to be used during a test, where they will +be set up and torn down around the test method. However, they can also be used without the framework. + You can declare a system stub object: ```java @@ -310,6 +313,22 @@ mutable version of the `and` method used in the first example. affect the runtime environment. Calling it outside of execution will store the value for writing into the environment within `execute`. +You can remove an environment variable with `remove`: + +```java +// assuming that there's an environment variable "STAGE" set here +new EnvironmentVariables() + .remove("STAGE") + .execute(() -> { + // the variable has been removed + assertThat(System.getenv("STAGE")).isNull(); + }); +``` + +The `remove` method deletes environment variables requested in the `EnvironmentVariables` object previously +and also takes those environment variables out of the system environment while the `EnvironmentVariables` +object is active. + ### System Properties #### With `SystemStubs` @@ -333,6 +352,15 @@ void execute_code_that_manipulates_system_properties() throws Exception { } ``` +This also supports removing properties from the system properties: + +```java +// will be restored +restoreSystemProperties(() ->{ + System.getProperties().remove("someProp"); +}); +``` + #### With `SystemProperties` A `SystemProperties` object allows you to set the system properties that will be provided @@ -358,6 +386,16 @@ someProperties.execute(() -> { // here the system properties are reverted ``` +We can also specify properties to delete from the default system properties: + +```java +// when this object is active, some properties will be removed +// from system properties +SystemProperties someProperties = new SystemProperties() + .remove("property1") + .remove("property2"); +``` + ### Sources of `Properties` for `EnvironmentVariables` and `SystemProperties` Once you have constructed an `EnvironmentVariables` or `SystemProperties` object, you can use the `set` method to apply properties. If these objects are presently _active_ diff --git a/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariableMocker.java b/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariableMocker.java index 3bc46d8..7be0991 100644 --- a/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariableMocker.java +++ b/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariableMocker.java @@ -64,18 +64,25 @@ private static void installInterceptorIntoBootLoader(Instrumentation instrumenta instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(tempFile)); } + @Deprecated(since = "2.1.5") + public static void connect(Map newEnvironmentVariables) { + connect(newEnvironmentVariables, Collections.emptySet()); + } + /** * Attach a map as the mutable replacement environment variables for now. This can be done * multiple times and each time the replacement will supersede the maps before. Then when {@link #pop()} * is called, we'll rollback to the previous. * @param newEnvironmentVariables the mutable map - note: this will be populated by the current * environment + * @param variablesToRemove a list of variables to take out of the resulting environment variables */ - public static void connect(Map newEnvironmentVariables) { + public static void connect(Map newEnvironmentVariables, Set variablesToRemove) { // add all entries not already present in the new environment variables System.getenv().entrySet().stream() .filter(entry -> !newEnvironmentVariables.containsKey(entry.getKey())) .forEach(entry -> newEnvironmentVariables.put(entry.getKey(), entry.getValue())); + variablesToRemove.forEach(newEnvironmentVariables::remove); REPLACEMENT_ENV.push(newEnvironmentVariables); ProcessEnvironmentInterceptor.setEnv(newEnvironmentVariables); } diff --git a/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariables.java b/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariables.java index 601d651..58eb317 100644 --- a/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariables.java +++ b/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariables.java @@ -6,9 +6,7 @@ import uk.org.webcompere.systemstubs.resource.SingularTestResource; import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; +import java.util.*; import static java.util.Collections.emptyMap; import static uk.org.webcompere.systemstubs.properties.PropertiesUtils.toStringMap; @@ -35,7 +33,8 @@ * @since 1.0.0 */ public class EnvironmentVariables extends SingularTestResource implements NameValuePairSetter { - protected final Map variables; + private final Map variables; + private final Set toRemove = new HashSet<>(); /** * Default constructor with an empty set of environment variables. Use {@link #set(String, String)} to @@ -113,6 +112,14 @@ public EnvironmentVariables set(String name, String value) { return this; } + @Override + public EnvironmentVariables remove(String name) { + toRemove.add(name); + variables.remove(name); + + return this; + } + /** * Return a copy of all the variables set for testing * @return a copy of the map @@ -141,7 +148,7 @@ private String format(String text) { @Override protected void doSetup() { - EnvironmentVariableMocker.connect(variables); + EnvironmentVariableMocker.connect(variables, toRemove); } @Override diff --git a/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/properties/SystemProperties.java b/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/properties/SystemProperties.java index 4688e33..92e990b 100644 --- a/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/properties/SystemProperties.java +++ b/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/properties/SystemProperties.java @@ -1,88 +1,23 @@ package uk.org.webcompere.systemstubs.properties; -import uk.org.webcompere.systemstubs.resource.NameValuePairSetter; -import uk.org.webcompere.systemstubs.resource.SingularTestResource; - import java.util.Properties; -import static java.lang.System.getProperties; -import static java.lang.System.setProperties; - /** * Maintain system properties after a test from the ones before the test. Stores the * existing properties when started, and restores them when complete. Allows for a list of properties * that will be applied to the system to be set before the stubbing is triggered. */ -public class SystemProperties extends SingularTestResource implements NameValuePairSetter { - private Properties originalProperties; - private Properties properties; +public class SystemProperties extends SystemPropertiesImpl { - /** - * Default constructor with no properties. Use {@link #set} to set properties - * either while active or before activation. - * @since 1.0.0 - */ public SystemProperties() { - this.properties = new Properties(); + super(); } - /** - * Construct with a specific set of properties. - * @param properties properties to use - * @since 1.0.0 - */ public SystemProperties(Properties properties) { - this.properties = PropertiesUtils.copyOf(properties); + super(properties); } - /** - * Construct with a set of properties to apply when the object is active - * @param name name of the first property - * @param value value of the first property - * @param nameValues pairs of names and values for further properties - * @since 1.0.0 - */ public SystemProperties(String name, String value, String... nameValues) { - this(); - if (nameValues.length % 2 != 0) { - throw new IllegalArgumentException("Must have pairs of values"); - } - properties.setProperty(name, value); - for (int i = 0; i < nameValues.length; i += 2) { - properties.setProperty(nameValues[i], nameValues[i + 1]); - } - } - - /** - * Set a system property. If active, this will set it with {@link System#setProperty(String, String)}. - * If not active, then this will store the property to apply when this object is part of an execution. - * It is also possible to use {@link System#setProperty(String, String)} while this object is active, - * but when the execution finishes, this object will be unaware of the property set, so will not set - * it next time. - * @param name name of the property - * @param value value to set - * @return this object for fluent use - * @since 1.0.0 - */ - @Override - public SystemProperties set(String name, String value) { - properties.setProperty(name, value); - if (isActive()) { - System.setProperty(name, value); - } - return this; - } - - @Override - protected void doSetup() throws Exception { - originalProperties = getProperties(); - Properties copyProperties = PropertiesUtils.copyOf(originalProperties); - copyProperties.putAll(properties); - setProperties(copyProperties); - } - - @Override - protected void doTeardown() throws Exception { - setProperties(originalProperties); + super(name, value, nameValues); } } diff --git a/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesImpl.java b/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesImpl.java new file mode 100644 index 0000000..3e5bf5d --- /dev/null +++ b/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesImpl.java @@ -0,0 +1,110 @@ +package uk.org.webcompere.systemstubs.properties; + +import uk.org.webcompere.systemstubs.resource.NameValuePairSetter; +import uk.org.webcompere.systemstubs.resource.SingularTestResource; + +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import static java.lang.System.getProperties; +import static java.lang.System.setProperties; + +/** + * Maintain system properties after a test from the ones before the test. Stores the + * existing properties when started, and restores them when complete. Allows for a list of properties + * that will be applied to the system to be set before the stubbing is triggered. + */ +public class SystemPropertiesImpl> extends SingularTestResource + implements NameValuePairSetter> { + private Properties originalProperties; + private Properties properties; + + private Set propertiesToRemove = new HashSet<>(); + + /** + * Default constructor with no properties. Use {@link #set} to set properties + * either while active or before activation. + * @since 1.0.0 + */ + public SystemPropertiesImpl() { + this.properties = new Properties(); + } + + /** + * Construct with a specific set of properties. + * @param properties properties to use + * @since 1.0.0 + */ + public SystemPropertiesImpl(Properties properties) { + this.properties = PropertiesUtils.copyOf(properties); + } + + /** + * Construct with a set of properties to apply when the object is active + * @param name name of the first property + * @param value value of the first property + * @param nameValues pairs of names and values for further properties + * @since 1.0.0 + */ + public SystemPropertiesImpl(String name, String value, String... nameValues) { + this(); + if (nameValues.length % 2 != 0) { + throw new IllegalArgumentException("Must have pairs of values"); + } + properties.setProperty(name, value); + for (int i = 0; i < nameValues.length; i += 2) { + properties.setProperty(nameValues[i], nameValues[i + 1]); + } + } + + /** + * Set a system property. If active, this will set it with {@link System#setProperty(String, String)}. + * If not active, then this will store the property to apply when this object is part of an execution. + * It is also possible to use {@link System#setProperty(String, String)} while this object is active, + * but when the execution finishes, this object will be unaware of the property set, so will not set + * it next time. + * @param name name of the property + * @param value value to set + * @return this object for fluent use + * @since 1.0.0 + */ + @Override + public SystemPropertiesImpl set(String name, String value) { + properties.setProperty(name, value); + if (isActive()) { + System.setProperty(name, value); + } + return this; + } + + /** + * Remove a property - this removes it from system properties if active, and remembers to remove it + * while the object is active + * @param name the name of the property to remove + * @return this for fluent use + * @since 2.1.5 + */ + @Override + public SystemPropertiesImpl remove(String name) { + propertiesToRemove.add(name); + if (isActive()) { + System.getProperties().remove(name); + } + return this; + } + + @Override + protected void doSetup() throws Exception { + originalProperties = getProperties(); + Properties copyProperties = PropertiesUtils.copyOf(originalProperties); + propertiesToRemove.forEach(copyProperties::remove); + copyProperties.putAll(properties); + setProperties(copyProperties); + } + + @Override + protected void doTeardown() throws Exception { + setProperties(originalProperties); + } +} diff --git a/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/resource/NameValuePairSetter.java b/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/resource/NameValuePairSetter.java index 6f8ab36..cad9059 100644 --- a/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/resource/NameValuePairSetter.java +++ b/system-stubs-core/src/main/java/uk/org/webcompere/systemstubs/resource/NameValuePairSetter.java @@ -7,8 +7,7 @@ * The general interface of something that can set name value pairs on itself * @param the final type of the class which provides this */ -@FunctionalInterface -public interface NameValuePairSetter { +public interface NameValuePairSetter> { /** * Set a name value pair * @param name the name @@ -43,4 +42,11 @@ default T set(Map properties) { properties.forEach((key, value) -> set(String.valueOf(key), String.valueOf(value))); return (T)this; } + + /** + * Remove one of the name value pairs + * @param name the name + * @return this for fluent calling + */ + T remove(String name); } diff --git a/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariablesTest.java b/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariablesTest.java index a1af6b5..7b81156 100644 --- a/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariablesTest.java +++ b/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/environment/EnvironmentVariablesTest.java @@ -122,6 +122,65 @@ void convenienceConstructorSetsMultipleVariables() throws Exception { }); } + @Test + void canSetVariablesNested() throws Exception { + new EnvironmentVariables("TOO", "tar", "BOO", "bar") + .execute(() -> { + assertThat(System.getenv("TOO")).isEqualTo("tar"); + assertThat(System.getenv("BOO")).isEqualTo("bar"); + + new EnvironmentVariables("CHEESE", "CRACKER") + .execute(() -> { + assertThat(System.getenv("TOO")).isEqualTo("tar"); + assertThat(System.getenv("BOO")).isEqualTo("bar"); + assertThat(System.getenv("CHEESE")).isEqualTo("CRACKER"); + }); + }); + } + + @Test + void canRemoveVariablesNested() throws Exception { + new EnvironmentVariables("TOO", "tar", "BOO", "bar") + .execute(() -> { + new EnvironmentVariables("CHEESE", "CRACKER") + .remove("BOO") + .remove("TOO") + .execute(() -> { + assertThat(System.getenv("BOO")).isNull(); + assertThat(System.getenv("TOO")).isNull(); + }); + }); + } + + @Test + void canRemoveVariablesNestedWhileActive() throws Exception { + new EnvironmentVariables("TOO", "tar", "BOO", "bar") + .execute(() -> { + var env = new EnvironmentVariables("CHEESE", "CRACKER"); + env.execute(() -> { + env.remove("BOO") + .remove("TOO"); + + assertThat(System.getenv("BOO")).isNull(); + assertThat(System.getenv("TOO")).isNull(); + }); + }); + } + + @Test + void canReAddRemovedVariables() throws Exception { + new EnvironmentVariables("TOO", "tar", "BOO", "bar") + .execute(() -> { + var env = new EnvironmentVariables("CHEESE", "CRACKER") + .remove("BOO") + .remove("TOO"); + env.execute(() -> { + env.set("TOO", "FAR"); + assertThat(System.getenv("TOO")).isEqualTo("FAR"); + }); + }); + } + @Test void canInspectTheVariablesSetSoFar() { Map set = new EnvironmentVariables() diff --git a/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesTest.java b/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesTest.java index 0bb927a..58a83ae 100644 --- a/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesTest.java +++ b/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesTest.java @@ -42,4 +42,117 @@ void propertiesSetWhileRunningApplyNextTimeToo() throws Exception{ assertThat(System.getProperty("g")).isEqualTo("h"); }); } + + @Test + void canRunPropertiesNested() throws Exception { + assertThat(System.getProperty("bar")).isNull(); + + SystemProperties properties = new SystemProperties(); + properties.execute(() -> { + properties.set("bar", "h"); + assertThat(System.getProperty("bar")).isEqualTo("h"); + + + SystemProperties nested = new SystemProperties(); + nested.execute(() -> { + properties.set("bar", "zh"); + assertThat(System.getProperty("bar")).isEqualTo("zh"); + }); + + assertThat(System.getProperty("bar")).isEqualTo("h"); + }); + } + + @Test + void canDeletePropertiesNested() throws Exception { + assertThat(System.getProperty("bar")).isNull(); + + SystemProperties properties = new SystemProperties(); + properties.execute(() -> { + properties.set("bar", "h"); + assertThat(System.getProperty("bar")).isEqualTo("h"); + + + SystemProperties nested = new SystemProperties(); + nested.execute(() -> { + System.getProperties().remove("bar"); + assertThat(System.getProperty("bar")).isNull(); + }); + + assertThat(System.getProperty("bar")).isEqualTo("h"); + }); + } + + @Test + void canDeletePropertiesNestedViaPropertiesObject() throws Exception { + assertThat(System.getProperty("bar")).isNull(); + + SystemProperties properties = new SystemProperties(); + properties.execute(() -> { + properties.set("bar", "h"); + assertThat(System.getProperty("bar")).isEqualTo("h"); + + + SystemProperties nested = new SystemProperties(); + nested.execute(() -> { + nested.remove("bar"); + assertThat(System.getProperty("bar")).isNull(); + }); + + assertThat(System.getProperty("bar")).isEqualTo("h"); + }); + } + + @Test + void canPreDeletePropertiesNestedViaPropertiesObject() throws Exception { + assertThat(System.getProperty("bar")).isNull(); + + SystemProperties properties = new SystemProperties(); + properties.execute(() -> { + properties.set("bar", "h"); + assertThat(System.getProperty("bar")).isEqualTo("h"); + + SystemProperties nested = new SystemProperties(); + nested.remove("bar"); + nested.execute(() -> { + assertThat(System.getProperty("bar")).isNull(); + }); + }); + } + + @Test + void canPreDeleteMultiplePropertiesNestedViaPropertiesObject() throws Exception { + SystemProperties properties = new SystemProperties(); + properties.execute(() -> { + properties.set("bar", "h"); + properties.set("baz", "h"); + assertThat(System.getProperty("bar")).isEqualTo("h"); + assertThat(System.getProperty("baz")).isEqualTo("h"); + + SystemProperties nested = new SystemProperties(); + nested.remove("bar").remove("baz"); + nested.execute(() -> { + assertThat(System.getProperty("bar")).isNull(); + assertThat(System.getProperty("baz")).isNull(); + }); + }); + } + + @Test + void settingAfterPreDeleteAlsoWorks() throws Exception { + assertThat(System.getProperty("bar")).isNull(); + + SystemProperties properties = new SystemProperties(); + properties.execute(() -> { + properties.set("bar", "h"); + assertThat(System.getProperty("bar")).isEqualTo("h"); + + SystemProperties nested = new SystemProperties(); + nested.remove("bar"); + nested.execute(() -> { + nested.set("bar", "bong"); + assertThat(System.getProperty("bar")).isEqualTo("bong"); + }); + }); + } } diff --git a/system-stubs-junit4/pom.xml b/system-stubs-junit4/pom.xml index 9eab289..d18664c 100644 --- a/system-stubs-junit4/pom.xml +++ b/system-stubs-junit4/pom.xml @@ -47,6 +47,12 @@ org.apache.maven.plugins maven-surefire-plugin + + + buildme + buildmetoo + + org.jacoco diff --git a/system-stubs-junit4/src/main/java/uk/org/webcompere/systemstubs/rules/EnvironmentVariablesRule.java b/system-stubs-junit4/src/main/java/uk/org/webcompere/systemstubs/rules/EnvironmentVariablesRule.java index 96dbe13..add4fca 100644 --- a/system-stubs-junit4/src/main/java/uk/org/webcompere/systemstubs/rules/EnvironmentVariablesRule.java +++ b/system-stubs-junit4/src/main/java/uk/org/webcompere/systemstubs/rules/EnvironmentVariablesRule.java @@ -67,4 +67,11 @@ public EnvironmentVariablesRule set(String name, String value) { public EnvironmentVariablesRule set(Map properties) { return (EnvironmentVariablesRule)super.set(properties); } + + /** + * {@inheritDoc} + */ + public EnvironmentVariablesRule remove(String name) { + return (EnvironmentVariablesRule)super.remove(name); + } } diff --git a/system-stubs-junit4/src/main/java/uk/org/webcompere/systemstubs/rules/SystemPropertiesRule.java b/system-stubs-junit4/src/main/java/uk/org/webcompere/systemstubs/rules/SystemPropertiesRule.java index f229d3a..3fd8295 100644 --- a/system-stubs-junit4/src/main/java/uk/org/webcompere/systemstubs/rules/SystemPropertiesRule.java +++ b/system-stubs-junit4/src/main/java/uk/org/webcompere/systemstubs/rules/SystemPropertiesRule.java @@ -1,6 +1,6 @@ package uk.org.webcompere.systemstubs.rules; -import uk.org.webcompere.systemstubs.properties.SystemProperties; +import uk.org.webcompere.systemstubs.properties.SystemPropertiesImpl; import uk.org.webcompere.systemstubs.rules.internal.SystemStubTestRule; import java.util.Map; @@ -11,7 +11,7 @@ * the ability for properties to be prepared before the test starts, via {@link #set}. * @since 1.0.0 */ -public class SystemPropertiesRule extends SystemProperties implements SystemStubTestRule { +public class SystemPropertiesRule extends SystemPropertiesImpl implements SystemStubTestRule { /** * Default constructor provides restoration of properties @@ -27,24 +27,10 @@ public SystemPropertiesRule(Properties properties) { super(properties); } - /** - * Construct with a variable number of properties that will be set when the rule is active - * @param name name of the first property - * @param value value of the first property - * @param nameValues pairs of name/values as Strings - */ public SystemPropertiesRule(String name, String value, String... nameValues) { super(name, value, nameValues); } - /** - * {@inheritDoc} - */ - @Override - public SystemPropertiesRule set(String name, String value) { - return (SystemPropertiesRule)super.set(name, value); - } - /** * {@inheritDoc} */ diff --git a/system-stubs-junit4/src/test/java/uk/org/webcompere/systemstubs/rules/EnvironmentVariablesRuleTest.java b/system-stubs-junit4/src/test/java/uk/org/webcompere/systemstubs/rules/EnvironmentVariablesRuleTest.java index baf3b48..243292f 100644 --- a/system-stubs-junit4/src/test/java/uk/org/webcompere/systemstubs/rules/EnvironmentVariablesRuleTest.java +++ b/system-stubs-junit4/src/test/java/uk/org/webcompere/systemstubs/rules/EnvironmentVariablesRuleTest.java @@ -72,4 +72,38 @@ public void withMultipleEnvironmentVariablesSetByConstructor() { assertThat(System.getenv("value1")).isEqualTo("foo"); } } + + public static class UsingRemoveViaConstructor { + @Rule + public EnvironmentVariablesRule environmentVariablesRule = + new EnvironmentVariablesRule(fromResource("test.properties")); + + @Test + public void withMultipleEnvironmentVariablesSetByConstructor() { + assertThat(System.getenv("value1")).isEqualTo("foo"); + } + } + + public static class BuildVariableIsSet { + @Test + public void variablesAreVisibleNormally() { + assertThat(System.getenv("SET_IN_BUILD")).isEqualTo("buildme"); + assertThat(System.getenv("SET_IN_BUILD2")).isEqualTo("buildmetoo"); + } + } + + public static class BuildVariableIsRemoveable{ + @Rule + public EnvironmentVariablesRule environmentVariablesRule = + new EnvironmentVariablesRule() + .remove("SET_IN_BUILD") + .remove("SET_IN_BUILD2"); + + + @Test + public void variablesAreVisibleNormally() { + assertThat(System.getenv("SET_IN_BUILD")).isNull(); + assertThat(System.getenv("SET_IN_BUILD2")).isNull(); + } + } }