Class SystemPropertyExtension

java.lang.Object
com.oracle.bedrock.junit.SystemPropertyExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.Extension

public class SystemPropertyExtension extends Object implements org.junit.jupiter.api.extension.BeforeAllCallback
A JUnit 5 extension that sets System properties in the before all phase.

By using this extension with @Order after other extensions, it is possible to configures properties based on the state of other extensions before tests run.

Since:
22.06
Author:
Jonathan Knight 2022.06.20
  • Constructor Details

    • SystemPropertyExtension

      public SystemPropertyExtension()
  • 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
    • withProperty

      public SystemPropertyExtension withProperty(String key, Supplier<?> value)
      Add a property to set.

      The toString() of the value returned by the supplier will be used as the property value.

      If the Supplier returns null then no property will be set.

      Parameters:
      key - the key of the property
      value - a supplier for the property value
      Returns:
      this builder