with-environment

Execute a block with overridden environment variables

License

License

GroupId

GroupId

com.github.brymck
ArtifactId

ArtifactId

with-environment
Last Version

Last Version

0.9.1
Release Date

Release Date

Type

Type

jar
Description

Description

with-environment
Execute a block with overridden environment variables
Project URL

Project URL

https://github.com/brymck/with-environment
Source Code Management

Source Code Management

https://github.com/brymck/with-environment

Download with-environment

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.brymck/with-environment/ -->
<dependency>
    <groupId>com.github.brymck</groupId>
    <artifactId>with-environment</artifactId>
    <version>0.9.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.brymck/with-environment/
implementation 'com.github.brymck:with-environment:0.9.1'
// https://jarcasting.com/artifacts/com.github.brymck/with-environment/
implementation ("com.github.brymck:with-environment:0.9.1")
'com.github.brymck:with-environment:jar:0.9.1'
<dependency org="com.github.brymck" name="with-environment" rev="0.9.1">
  <artifact name="with-environment" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.brymck', module='with-environment', version='0.9.1')
)
libraryDependencies += "com.github.brymck" % "with-environment" % "0.9.1"
[com.github.brymck/with-environment "0.9.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.jetbrains : annotations jar 15.0
org.slf4j : slf4j-api jar 1.7.25

test (4)

Group / Artifact Type Version
org.slf4j : slf4j-simple jar 1.7.25
org.junit.jupiter : junit-jupiter-api jar 5.5.2
org.junit.jupiter : junit-jupiter-engine jar 5.5.2
org.junit.jupiter : junit-jupiter-params jar 5.5.2

Project Modules

There are no modules declared in this project.

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"
}

Versions

Version
0.9.1
0.9.0