Skip to content

brymck/with-environment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

with-environment

CircleCI codecov

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 s o in Java:

Map<String, String> overrides = new HashMap<>();
overrides.put("FOO", "bar");
WithEnvironment.withEnvironmentOverrides(overrides, () -> {
  String foo = System.getenv("FOO");
  System.out.println(foo);  // prints "bar"
});

or Kotlin:

val overrides = mapOf("FOO" to "bar")
withEnvironmentOverrides(overrides) {
  val foo = System.getenv("FOO");
  println(foo)  // prints "bar"
}

About

Override the JVM environment and execute a block

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages