with-environment
with-environment
is a library that allows overriding the system environment and executing a block.
Much of this is shamelessly yanked from SystemRules and is just designed to decouple
the functionality from JUnit 4 and provide a natural Kotlin interface.
Usage
Include this in your POM:
<dependency>
<groupId>com.github.brymck</groupId>
<artifactId>with-environment</artifactId>
<version>0.9.1</version>
</dependency>
And use it as so in Java:
Map<String, String> overrides = new HashMap();
overrides.put("FOO", "bar");
WithEnvironment.withEnvironmentOverrides(overrides, () -> {
String foo = System.getenv("FOO");
System.out.println(foo);
});
or Kotlin:
val overrides = mapOf("FOO" to "bar")
withEnvironmentOverrides(overrides) {
val foo = System.getenv("FOO");
println(foo)
}