Class 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 java.lang.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 Detail

      • SystemPropertyClassExtension

        public SystemPropertyClassExtension()
    • Method Detail

      • beforeAll

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

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

        public SystemPropertyClassExtension setProperty​(java.lang.String key,
                                                        java.util.function.Supplier<java.lang.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​(java.lang.String key,
                                                        java.lang.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​(java.lang.String key)
        Unset a property for the test.
        Parameters:
        key - the property to unser
        Returns:
        the rule