Class SystemPropertiesExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.Extension
In order to provide the property values to be injected, you must provide either a Properties
or
Map<String,String>
object named "SYSTEM_PROPERTIES" on the test class as a static field.
Alternately, you may specify the field name containing your properties using the ApplyProperties
annotation
on the test method.
Before each test method is executed, the configured properties will be injected into the System properties; however, the original values will be stored and replaced after the test method has finished.
NOTE: Due to the global nature of the System properties, the test methods under this extension are locked so that only one should run at a time - that being said, if you run into odd issues, try executing these tests in a single-threaded manner (and/or report a bug if you feel the functionality could be improved).
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterEach
(org.junit.jupiter.api.extension.ExtensionContext context) static Properties
asProperties
(Map<String, String> map) A helper method that may be used to convert aMap
to aProperties
object containing the same data.void
beforeEach
(org.junit.jupiter.api.extension.ExtensionContext context)
-
Constructor Details
-
SystemPropertiesExtension
public SystemPropertiesExtension()
-
-
Method Details
-
beforeEach
- Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
- Throws:
Exception
-
afterEach
- Specified by:
afterEach
in interfaceorg.junit.jupiter.api.extension.AfterEachCallback
- Throws:
Exception
-
asProperties
A helper method that may be used to convert aMap
to aProperties
object containing the same data.- Parameters:
map
- the map of property data- Returns:
- a Properties object containing the map data
-