-
Notifications
You must be signed in to change notification settings - Fork 71
/
ClearSystemProperty.java
74 lines (65 loc) · 2.5 KB
/
ClearSystemProperty.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright 2016-2023 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v20.html
*/
package org.junitpioneer.jupiter;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* {@code @ClearSystemProperty} is a JUnit Jupiter extension to clear the value
* of a system property for a test execution.
*
* <p>The key of the system property to be cleared must be specified via {@link #key()}.
* After the annotated element has been executed, the original value or the value of the
* higher-level container is restored.</p>
*
* <p>{@code ClearSystemProperty} can be used on the method and on the class level.
* It is repeatable and inherited from higher-level containers. If a class is
* annotated, the configured property will be cleared before every test inside that
* class.</p>
*
* <p>During
* <a href="https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution" target="_top">parallel test execution</a>,
* all tests annotated with {@link ClearSystemProperty}, {@link SetSystemProperty}, {@link ReadsSystemProperty}, and {@link WritesSystemProperty}
* are scheduled in a way that guarantees correctness under mutation of shared global state.
* </p>
*
* <p>For more details and examples, see
* <a href="https://junit-pioneer.org/docs/system-properties/" target="_top">the documentation on <code>@ClearSystemProperty and @SetSystemProperty</code></a>.
* </p>
*
* @since 0.5
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
@Inherited
@Repeatable(ClearSystemProperty.ClearSystemProperties.class)
@WritesSystemProperty
@ExtendWith(SystemPropertyExtension.class)
public @interface ClearSystemProperty {
/**
* The key of the system property to be cleared.
*/
String key();
/**
* Containing annotation of repeatable {@code @ClearSystemProperty}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
@Inherited
@WritesSystemProperty
@ExtendWith(SystemPropertyExtension.class)
@interface ClearSystemProperties {
ClearSystemProperty[] value();
}
}