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 Details

    • EnvironmentVariableHelper

      public EnvironmentVariableHelper()
  • Method Details

    • remove

      public void remove(SystemSetting setting)
    • remove

      public void remove(String key)
    • set

      public void set(SystemSetting setting, String value)
    • set

      public void set(String key, String value)
    • reset

      public void reset()
    • after

      protected void after()
      Overrides:
      after in class org.junit.rules.ExternalResource
    • run

      public static void run(Consumer<EnvironmentVariableHelper> helperConsumer)
      Static run method that allows for "single-use" environment variable modification. Example use:
       
       EnvironmentVariableHelper.run(helper -> {
          helper.set("variable", "value");
          //run some test that uses "variable"
       });
       
       
      Will call reset() at the end of the block (even if the block exits exceptionally).
      Parameters:
      helperConsumer - a code block to run that gets an EnvironmentVariableHelper as an argument