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 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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterAll
(org.junit.jupiter.api.extension.ExtensionContext context) void
beforeAll
(org.junit.jupiter.api.extension.ExtensionContext context) setProperty
(String key, String value) Set a property to a value for the test.setProperty
(String key, Supplier<String> value) Set a property to a computed value for the test.unsetProperty
(String key) Unset a property for the test.
-
Constructor Details
-
SystemPropertyClassExtension
public SystemPropertyClassExtension()
-
-
Method Details
-
beforeAll
- Specified by:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
- Throws:
Exception
-
afterAll
- Specified by:
afterAll
in interfaceorg.junit.jupiter.api.extension.AfterAllCallback
- Throws:
Exception
-
setProperty
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
Set a property to a value for the test.- Parameters:
key
- the property to setvalue
- the value to set- Returns:
- the rule
-
unsetProperty
Unset a property for the test.- Parameters:
key
- the property to unser- Returns:
- the rule
-