Class SystemPropertyClassExtension

java.lang.Object
org.sdase.commons.server.testing.SystemPropertyClassExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.Extension

public class SystemPropertyClassExtension extends Object implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
JUnit 5 extension for setting system properties for (integration) tests.

Example usage:

   @RegisterExtension
   static final SystemPropertyClassExtension PROP =
       new SystemPropertyClassExtension()
           .setProperty("name", "value");
 
  • Constructor Details

    • SystemPropertyClassExtension

      public SystemPropertyClassExtension()
  • Method Details

    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Throws:
      Exception
    • afterAll

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
      Throws:
      Exception
    • setProperty

      public SystemPropertyClassExtension setProperty(String key, Supplier<String> value)
      Set a property to a computed value for the test. The value supplier is called when the extension is started and the property is set. This is useful, if the SystemPropertyClassExtension is called in a specific order and the value can only be accessed after other extensions have been started.
      Parameters:
      key - the property to set
      value - the supplier that provides the value to set
      Returns:
      the rule
    • setProperty

      public SystemPropertyClassExtension setProperty(String key, String value)
      Set a property to a value for the test.
      Parameters:
      key - the property to set
      value - the value to set
      Returns:
      the rule
    • unsetProperty

      public SystemPropertyClassExtension unsetProperty(String key)
      Unset a property for the test.
      Parameters:
      key - the property to unser
      Returns:
      the rule