|
23 | 23 | import org.junit.jupiter.api.extension.ExtendWith; |
24 | 24 |
|
25 | 25 | /** |
26 | | - * {@code @RestoreSystemProperties} is a JUnit Jupiter extension to restore the entire set of |
27 | | - * system properties to the original value, or the value of the higher-level container, after the |
28 | | - * annotated element is complete. |
| 26 | + * {@code @RestoreSystemProperties} is an annotation that is used to restore the |
| 27 | + * entire set of JVM system properties to its original state, or the state of the |
| 28 | + * higher-level container, after execution of the annotated element has completed. |
29 | 29 | * |
30 | | - * <p>Use this annotation when there is a need programmatically modify system properties in a test |
31 | | - * method or in {@code @BeforeAll} / {@code @BeforeEach} blocks. |
32 | | - * To set or clear a system property, consider {@link SetSystemProperty @SetSystemProperty} or |
| 30 | + * <p>Use this annotation when there is a need to programmatically modify system |
| 31 | + * properties in a test method or in {@code @BeforeAll} / {@code @BeforeEach} |
| 32 | + * lifecycle methods. To set or clear a system property, consider |
| 33 | + * {@link SetSystemProperty @SetSystemProperty} or |
33 | 34 | * {@link ClearSystemProperty @ClearSystemProperty} instead. |
34 | 35 | * |
35 | | - * <p>{@code @RestoreSystemProperties} can be used on the method and on the class level. |
36 | | - * When placed on a test method, a snapshot of system properties is stored prior to that test. |
37 | | - * The snapshot is created before any {@code @BeforeEach} blocks in scope and before any |
38 | | - * {@link SetSystemProperty @SetSystemProperty} or {@link ClearSystemProperty @ClearSystemProperty} |
39 | | - * annotations on that method. After the test, system properties are restored from the |
40 | | - * snapshot after any {@code @AfterEach} have completed. |
| 36 | + * <p>{@code @RestoreSystemProperties} can be used on the method and on the class |
| 37 | + * level. |
41 | 38 | * |
42 | | - * <p>When placed on a test class, a snapshot of system properties is stored prior to any |
43 | | - * {@code @BeforeAll} blocks in scope and before any {@link SetSystemProperty @SetSystemProperty} |
44 | | - * or {@link ClearSystemProperty @ClearSystemProperty} annotations on that class. |
45 | | - * After the test class completes, system properties are restored from the snapshot after any |
46 | | - * {@code @AfterAll} blocks have completed. |
47 | | - * In addition, a class level annotation is inherited by each test method just as if each one was |
| 39 | + * <p>When declared on a test method, a snapshot of all JVM system properties is |
| 40 | + * stored prior to that test. The snapshot is created before any {@code @BeforeEach} |
| 41 | + * lifecycle methods in scope and before any {@link SetSystemProperty @SetSystemProperty} |
| 42 | + * or {@link ClearSystemProperty @ClearSystemProperty} annotations on that method. |
| 43 | + * After the test, system properties are restored from the snapshot after all |
| 44 | + * {@code @AfterEach} lifecycle methods have completed. |
| 45 | + * |
| 46 | + * <p>When placed on a test class, a snapshot of all JVM system properties is stored |
| 47 | + * prior to any {@code @BeforeAll} lifecycle methods in scope and before any |
| 48 | + * {@link SetSystemProperty @SetSystemProperty} or |
| 49 | + * {@link ClearSystemProperty @ClearSystemProperty} annotations on that class. |
| 50 | + * After the test class completes, system properties are restored from the snapshot |
| 51 | + * after any {@code @AfterAll} lifecycle methods have completed. In addition, a |
| 52 | + * class-level annotation is inherited by each test method just as if each one were |
48 | 53 | * annotated with {@code RestoreSystemProperties}. |
49 | 54 | * |
50 | | - * <p>During |
51 | | - * <a href="https://docs.junit.org/current/writing-tests/parallel-execution.html">parallel test execution</a>, |
52 | | - * all tests annotated with {@link RestoreSystemProperties}, {@link SetSystemProperty}, |
53 | | - * {@link ReadsSystemProperty}, and {@link WritesSystemProperty} |
54 | | - * are scheduled in a way that guarantees correctness under mutation of shared global state. |
| 55 | + * <p>During <a href="https://docs.junit.org/current/writing-tests/parallel-execution.html"> |
| 56 | + * parallel test execution</a>, all tests annotated with |
| 57 | + * {@link SetSystemProperty @SetSystemProperty}, |
| 58 | + * {@link ClearSystemProperty @ClearSystemProperty}, |
| 59 | + * {@link ReadsSystemProperty @ReadsSystemProperty}, and |
| 60 | + * {@link WritesSystemProperty @WritesSystemProperty} are scheduled in a way that |
| 61 | + * guarantees correctness under mutation of shared global state. |
55 | 62 | * |
56 | | - * <p>For more details and examples, see |
57 | | - * <a href="https://docs.junit.org/current/writing-tests/built-in-extensions.html#SystemProperty">the documentation on |
58 | | - * <code>@ClearSystemProperty</code>, <code>@SetSystemProperty</code>, and <code>@RestoreSystemProperties</code></a>.</p> |
| 63 | + * <p>For further details and examples, see the documentation on all JVM system |
| 64 | + * property annotations in the |
| 65 | + * <a href="https://docs.junit.org/current/writing-tests/built-in-extensions.html#system-properties"> |
| 66 | + * User Guide</a>. |
59 | 67 | * |
60 | | - * <p><em>Note:</em> The snapshot of the properties object is created using {@link Properties#clone()}. |
61 | | - * This cloned value will not include any default values. This extension will make a best effort |
62 | | - * attempt to detect default values and fail if any are detected. For classes that extend |
63 | | - * {@code Properties}, it is assumed that {@code clone()} is implemented with sufficient fidelity. |
| 68 | + * <p><em>Note:</em> The snapshot of the properties object is created using |
| 69 | + * {@link Properties#clone()}. However, this cloned properties object will not |
| 70 | + * include any default values from the original properties object. Consequently, |
| 71 | + * this extension will make a best effort attempt to detect default values and |
| 72 | + * fail if any are detected. For classes that extend {@code Properties}, it is |
| 73 | + * assumed that {@code clone()} is implemented with sufficient fidelity. |
64 | 74 | * |
65 | 75 | * @since 6.1 |
| 76 | + * @see ClearSystemProperty @ClearSystemProperty |
| 77 | + * @see SetSystemProperty @SetSystemProperty |
66 | 78 | */ |
67 | 79 | @Retention(RetentionPolicy.RUNTIME) |
68 | 80 | @Target({ ElementType.METHOD, ElementType.TYPE }) |
69 | 81 | @Inherited |
70 | 82 | @WritesSystemProperty |
71 | | -@ExtendWith(SystemPropertyExtension.class) |
| 83 | +@ExtendWith(SystemPropertiesExtension.class) |
72 | 84 | @API(status = EXPERIMENTAL, since = "6.1") |
73 | 85 | @SuppressWarnings("exports") |
74 | 86 | public @interface RestoreSystemProperties { |
|
0 commit comments