Package org.sdase.commons.server.testing
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 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 Summary
Constructors Constructor Description SystemPropertyClassExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
void
beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
SystemPropertyClassExtension
setProperty(java.lang.String key, java.lang.String value)
Set a property to a value for the test.SystemPropertyClassExtension
setProperty(java.lang.String key, java.util.function.Supplier<java.lang.String> value)
Set a property to a computed value for the test.SystemPropertyClassExtension
unsetProperty(java.lang.String key)
Unset a property for the test.
-
-
-
Method Detail
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception
- Specified by:
beforeAll
in interfaceorg.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 interfaceorg.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. Thevalue
supplier is called when the extension is started and the property is set. This is useful, if theSystemPropertyClassExtension
is called in a specific order and the value can only be accessed after other extensions have been started.- Parameters:
key
- the property to setvalue
- 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 setvalue
- 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
-
-