Annotation Interface RestoreSystemProperties


@Retention(RUNTIME) @Target({METHOD,TYPE}) @Inherited @ExtendWith(org.junit.jupiter.api.util.SystemPropertyExtension.class) @API(status=EXPERIMENTAL, since="6.1") public @interface RestoreSystemProperties
@RestoreSystemProperties is a JUnit Jupiter extension to restore the entire set of system properties to the original value, or the value of the higher-level container, after the annotated element is complete.

Use this annotation when there is a need programmatically modify system properties in a test method or in @BeforeAll / @BeforeEach blocks. 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 placed on a test method, a snapshot of system properties is stored prior to that test. The snapshot is created before any @BeforeEach blocks in scope and before any @SetSystemProperty or @ClearSystemProperty annotations on that method. After the test, system properties are restored from the snapshot after any @AfterEach have completed.

When placed on a test class, a snapshot of system properties is stored prior to any @BeforeAll blocks 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 blocks have completed. In addition, a class level annotation is inherited by each test method just as if each one was annotated with RestoreSystemProperties.

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

For more details and examples, see the documentation on @ClearSystemProperty, @SetSystemProperty, and @RestoreSystemProperties.

Note: The snapshot of the properties object is created using Properties.clone(). This cloned value will not include any default values. 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