Annotation Interface RestoreSystemProperties


@Retention(RUNTIME) @Target({METHOD,TYPE}) @Inherited @ExtendWith(org.junit.jupiter.api.util.SystemPropertiesExtension.class) @API(status=EXPERIMENTAL, since="6.1") public @interface RestoreSystemProperties
@RestoreSystemProperties is an annotation that is used to restore the entire set of JVM system properties to its original state, or the state of the higher-level container, after execution of the annotated element has completed.

Use this annotation when there is a need to programmatically modify system properties in a test method or in @BeforeAll / @BeforeEach lifecycle methods. To set or clear a system property, consider @SetSystemProperty or @ClearSystemProperty instead.

@RestoreSystemProperties can be used on the method and on the class level.

When declared on a test method, a snapshot of all JVM system properties is stored prior to that test. The snapshot is created before any @BeforeEach lifecycle methods in scope and before any @SetSystemProperty or @ClearSystemProperty annotations on that method. After the test, system properties are restored from the snapshot after all @AfterEach lifecycle methods have completed.

When placed on a test class, a snapshot of all JVM system properties is stored prior to any @BeforeAll lifecycle methods in scope and before any @SetSystemProperty or @ClearSystemProperty annotations on that class. After the test class completes, system properties are restored from the snapshot after any @AfterAll lifecycle methods have completed. In addition, a class-level annotation is inherited by each test method just as if each one were annotated with RestoreSystemProperties.

During parallel test execution, all tests annotated with @SetSystemProperty, @ClearSystemProperty, @ReadsSystemProperty, and @WritesSystemProperty are scheduled in a way that guarantees correctness under mutation of shared global state.

For further details and examples, see the documentation on all JVM system property annotations in the User Guide.

Note: The snapshot of the properties object is created using Properties.clone(). However, this cloned properties object will not include any default values from the original properties object. Consequently, this extension will make a best effort attempt to detect default values and fail if any are detected. For classes that extend Properties, it is assumed that clone() is implemented with sufficient fidelity.

Since:
6.1
See Also: