Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledIfSystemProperty.java

raw symbols SCIP
1 /*
2 * Copyright 2015-2024 the original author or authors.
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v2.0 which
6 * accompanies this distribution and is available at
7 *
8 * https://www.eclipse.org/legal/epl-v20.html
9 */
10
11 package org.junit.jupiter.api.condition;
12
13 import static org.apiguardian.api.API.Status.STABLE;
14
15 import java.lang.annotation.Documented;
16 import java.lang.annotation.ElementType;
17 import java.lang.annotation.Repeatable;
18 import java.lang.annotation.Retention;
19 import java.lang.annotation.RetentionPolicy;
20 import java.lang.annotation.Target;
21
22 import org.apiguardian.api.API;
23 import org.junit.jupiter.api.extension.ExtendWith;
24
25 /**
26 * {@code @DisabledIfSystemProperty} is used to signal that the annotated test
27 * class or test method is <em>disabled</em> if the value of the specified
28 * {@linkplain #named system property} matches the specified
29 * {@linkplain #matches regular expression}.
30 *
31 * <p>When declared at the class level, the result will apply to all test methods
32 * within that class as well.
33 *
34 * <p>This annotation is not {@link java.lang.annotation.Inherited @Inherited}.
35 * Consequently, if you wish to apply the same semantics to a subclass, this
36 * annotation must be redeclared on the subclass.
37 *
38 * <p>If a test method is disabled via this annotation, that does not prevent
39 * the test class from being instantiated. Rather, it prevents the execution of
40 * the test method and method-level lifecycle callbacks such as {@code @BeforeEach}
41 * methods, {@code @AfterEach} methods, and corresponding extension APIs.
42 *
43 * <p>If the specified system property is undefined, the presence of this
44 * annotation will have no effect on whether or not the class or method
45 * is disabled.
46 *
47 * <p>This annotation may be used as a meta-annotation in order to create a
48 * custom <em>composed annotation</em> that inherits the semantics of this
49 * annotation.
50 *
51 * <p>As of JUnit Jupiter 5.6, this annotation is a {@linkplain Repeatable
52 * repeatable} annotation. Consequently, this annotation may be declared multiple
53 * times on an {@link java.lang.reflect.AnnotatedElement AnnotatedElement} (i.e.,
54 * test interface, test class, or test method). Specifically, this annotation will
55 * be found if it is directly present, indirectly present, or meta-present on a
56 * given element.
57 *
58 * @since 5.1
59 * @see org.junit.jupiter.api.condition.EnabledIf
60 * @see org.junit.jupiter.api.condition.DisabledIf
61 * @see org.junit.jupiter.api.condition.EnabledOnOs
62 * @see org.junit.jupiter.api.condition.DisabledOnOs
63 * @see org.junit.jupiter.api.condition.EnabledOnJre
64 * @see org.junit.jupiter.api.condition.DisabledOnJre
65 * @see org.junit.jupiter.api.condition.EnabledForJreRange
66 * @see org.junit.jupiter.api.condition.DisabledForJreRange
67 * @see org.junit.jupiter.api.condition.EnabledInNativeImage
68 * @see org.junit.jupiter.api.condition.DisabledInNativeImage
69 * @see org.junit.jupiter.api.condition.EnabledIfSystemProperty
70 * @see org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
71 * @see org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable
72 * @see org.junit.jupiter.api.Disabled
73 */
74 @Target({ ElementType.TYPE, ElementType.METHOD })
75 @Retention(RetentionPolicy.RUNTIME)
76 @Documented
77 @Repeatable(DisabledIfSystemProperties.class)
78 @ExtendWith(DisabledIfSystemPropertyCondition.class)
79 @API(status = STABLE, since = "5.1")
80 @SuppressWarnings("exports")
81 public @interface DisabledIfSystemProperty {
82
83 /**
84 * The name of the JVM system property to retrieve.
85 *
86 * @return the system property name; never <em>blank</em>
87 * @see System#getProperty(String)
88 */
89 String named();
90
91 /**
92 * A regular expression that will be used to match against the retrieved
93 * value of the {@link #named} JVM system property.
94 *
95 * @return the regular expression; never <em>blank</em>
96 * @see String#matches(String)
97 * @see java.util.regex.Pattern
98 */
99 String matches();
100
101 /**
102 * Custom reason to provide if the test or container is disabled.
103 *
104 * <p>If a custom reason is supplied, it will be combined with the default
105 * reason for this annotation. If a custom reason is not supplied, the default
106 * reason will be used.
107 *
108 * @since 5.7
109 */
110 @API(status = STABLE, since = "5.7")
111 String disabledReason() default "";
112
113 }