Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariable.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 @EnabledIfEnvironmentVariable} is used to signal that the annotated test
27 * class or test method is only <em>enabled</em> if the value of the specified
28 * {@linkplain #named environment variable} 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 environment variable is undefined, the annotated class or
44 * method will be disabled.
45 *
46 * <p>This annotation may be used as a meta-annotation in order to create a
47 * custom <em>composed annotation</em> that inherits the semantics of this
48 * annotation.
49 *
50 * <p>As of JUnit Jupiter 5.6, this annotation is a {@linkplain Repeatable
51 * repeatable} annotation. Consequently, this annotation may be declared multiple
52 * times on an {@link java.lang.reflect.AnnotatedElement AnnotatedElement} (i.e.,
53 * test interface, test class, or test method). Specifically, this annotation will
54 * be found if it is directly present, indirectly present, or meta-present on a
55 * given element.
56 *
57 * @since 5.1
58 * @see org.junit.jupiter.api.condition.EnabledIf
59 * @see org.junit.jupiter.api.condition.DisabledIf
60 * @see org.junit.jupiter.api.condition.EnabledOnOs
61 * @see org.junit.jupiter.api.condition.DisabledOnOs
62 * @see org.junit.jupiter.api.condition.EnabledOnJre
63 * @see org.junit.jupiter.api.condition.DisabledOnJre
64 * @see org.junit.jupiter.api.condition.EnabledForJreRange
65 * @see org.junit.jupiter.api.condition.DisabledForJreRange
66 * @see org.junit.jupiter.api.condition.EnabledInNativeImage
67 * @see org.junit.jupiter.api.condition.DisabledInNativeImage
68 * @see org.junit.jupiter.api.condition.EnabledIfSystemProperty
69 * @see org.junit.jupiter.api.condition.DisabledIfSystemProperty
70 * @see org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable
71 * @see org.junit.jupiter.api.Disabled
72 */
73 @Target({ ElementType.TYPE, ElementType.METHOD })
74 @Retention(RetentionPolicy.RUNTIME)
75 @Documented
76 @Repeatable(EnabledIfEnvironmentVariables.class)
77 @ExtendWith(EnabledIfEnvironmentVariableCondition.class)
78 @API(status = STABLE, since = "5.1")
79 @SuppressWarnings("exports")
80 public @interface EnabledIfEnvironmentVariable {
81
82 /**
83 * The name of the environment variable to retrieve.
84 *
85 * @return the environment variable name; never <em>blank</em>
86 * @see System#getenv(String)
87 */
88 String named();
89
90 /**
91 * A regular expression that will be used to match against the retrieved
92 * value of the {@link #named} environment variable.
93 *
94 * @return the regular expression; never <em>blank</em>
95 * @see String#matches(String)
96 * @see java.util.regex.Pattern
97 */
98 String matches();
99
100 /**
101 * Custom reason to provide if the test or container is disabled.
102 *
103 * <p>If a custom reason is supplied, it will be combined with the default
104 * reason for this annotation. If a custom reason is not supplied, the default
105 * reason will be used.
106 *
107 * @since 5.7
108 */
109 @API(status = STABLE, since = "5.7")
110 String disabledReason() default "";
111
112 }