public class SystemEnvironmentTestListener
extends SystemEnvironmentListener
Overrides System Environment with chosen keys and values
This is a Listener for code that uses Environment Variables. It overrides the specific keys from System.getenv with the specified values, only during the execution of a test.
To do this, this listener uses a trick that makes the System Environment editable, and overrides the keys. Any previous environment (anything not overridden) will also be in the environment. If the chosen key is in the environment, it will be overridden. If the chosen key is not in the environment, it will be included.
After the execution of the test, the environment is set to what it was before.
ATTENTION: This code is susceptible to race conditions. If you attempt to change the environment while it was already changed, the result is inconsistent, as the System Environment Map is a single map.
| Constructor and Description |
|---|
SystemEnvironmentTestListener(java.util.Map<java.lang.String,java.lang.String> environment)
Overrides System Environment with chosen keys and values
|
SystemEnvironmentTestListener(java.lang.String key,
java.lang.String value)
Overrides System Environment with chosen keys and values
|
SystemEnvironmentTestListener(kotlin.Pair<java.lang.String,java.lang.String> environment)
Overrides System Environment with chosen keys and values
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterTest(io.kotlintest.TestCase testCase,
io.kotlintest.TestResult result) |
void |
beforeTest(io.kotlintest.TestCase testCase) |
changeSystemEnvironment, resetSystemEnvironmentpublic SystemEnvironmentTestListener(java.util.Map<java.lang.String,java.lang.String> environment)
Overrides System Environment with chosen keys and values
This is a Listener for code that uses Environment Variables. It overrides the specific keys from System.getenv with the specified values, only during the execution of a test.
To do this, this listener uses a trick that makes the System Environment editable, and overrides the keys. Any previous environment (anything not overridden) will also be in the environment. If the chosen key is in the environment, it will be overridden. If the chosen key is not in the environment, it will be included.
After the execution of the test, the environment is set to what it was before.
ATTENTION: This code is susceptible to race conditions. If you attempt to change the environment while it was already changed, the result is inconsistent, as the System Environment Map is a single map.
public SystemEnvironmentTestListener(java.lang.String key,
java.lang.String value)
Overrides System Environment with chosen keys and values
This is a Listener for code that uses Environment Variables. It overrides the specific keys from System.getenv with the specified values, only during the execution of a test.
To do this, this listener uses a trick that makes the System Environment editable, and overrides the keys. Any previous environment (anything not overridden) will also be in the environment. If the chosen key is in the environment, it will be overridden. If the chosen key is not in the environment, it will be included.
After the execution of the test, the environment is set to what it was before.
ATTENTION: This code is susceptible to race conditions. If you attempt to change the environment while it was already changed, the result is inconsistent, as the System Environment Map is a single map.
public SystemEnvironmentTestListener(kotlin.Pair<java.lang.String,java.lang.String> environment)
Overrides System Environment with chosen keys and values
This is a Listener for code that uses Environment Variables. It overrides the specific keys from System.getenv with the specified values, only during the execution of a test.
To do this, this listener uses a trick that makes the System Environment editable, and overrides the keys. Any previous environment (anything not overridden) will also be in the environment. If the chosen key is in the environment, it will be overridden. If the chosen key is not in the environment, it will be included.
After the execution of the test, the environment is set to what it was before.
ATTENTION: This code is susceptible to race conditions. If you attempt to change the environment while it was already changed, the result is inconsistent, as the System Environment Map is a single map.