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.ExternalResourceA 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 Constructor Description EnvironmentVariableHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafter()voidremove(String key)voidremove(SystemSetting setting)voidreset()static voidrun(Consumer<EnvironmentVariableHelper> helperConsumer)Static run method that allows for "single-use" environment variable modification.voidset(String key, String value)voidset(SystemSetting setting, String value)
-
-
-
Method Detail
-
remove
public void remove(SystemSetting setting)
-
remove
public void remove(String key)
-
set
public void set(SystemSetting setting, String value)
-
reset
public void reset()
-
after
protected void after()
- Overrides:
afterin classorg.junit.rules.ExternalResource
-
run
public static void run(Consumer<EnvironmentVariableHelper> helperConsumer)
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
-
-