Package software.amazon.awssdk.testutils
Class EnvironmentVariableHelper
java.lang.Object
org.junit.rules.ExternalResource
software.amazon.awssdk.testutils.EnvironmentVariableHelper
- All Implemented Interfaces:
org.junit.rules.TestRule
public class EnvironmentVariableHelper
extends org.junit.rules.ExternalResource
A utility that can temporarily forcibly set environment variables and then allows resetting them to the original values.
This only works for environment variables read by the SDK.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafter()voidvoidremove(SystemSetting setting) voidreset()static voidrun(Consumer<EnvironmentVariableHelper> helperConsumer) Static run method that allows for "single-use" environment variable modification.voidvoidset(SystemSetting setting, String value) Methods inherited from class org.junit.rules.ExternalResource
apply, before
-
Constructor Details
-
EnvironmentVariableHelper
public EnvironmentVariableHelper()
-
-
Method Details
-
remove
-
remove
-
set
-
set
-
reset
public void reset() -
after
protected void after()- Overrides:
afterin classorg.junit.rules.ExternalResource
-
run
Static run method that allows for "single-use" environment variable modification. Example use:
Will callEnvironmentVariableHelper.run(helper -> { helper.set("variable", "value"); //run some test that uses "variable" });reset()at the end of the block (even if the block exits exceptionally).- Parameters:
helperConsumer- a code block to run that gets anEnvironmentVariableHelperas an argument
-