Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRange.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.Retention;
18 import java.lang.annotation.RetentionPolicy;
19 import java.lang.annotation.Target;
20
21 import org.apiguardian.api.API;
22 import org.junit.jupiter.api.extension.ExtendWith;
23
24 /**
25 * {@code @EnabledForJreRange} is used to signal that the annotated test class or
26 * test method is only <em>enabled</em> for a specific range of Java Runtime
27 * Environment (JRE) versions from {@link #min} to {@link #max}.
28 *
29 * <p>When applied at the class level, all test methods within that class will
30 * be enabled on the same specified JRE versions.
31 *
32 * <p>This annotation is not {@link java.lang.annotation.Inherited @Inherited}.
33 * Consequently, if you wish to apply the same semantics to a subclass, this
34 * annotation must be redeclared on the subclass.
35 *
36 * <p>If a test method is disabled via this annotation, that does not prevent
37 * the test class from being instantiated. Rather, it prevents the execution of
38 * the test method and method-level lifecycle callbacks such as {@code @BeforeEach}
39 * methods, {@code @AfterEach} methods, and corresponding extension APIs.
40 *
41 * <p>This annotation may be used as a meta-annotation in order to create a
42 * custom <em>composed annotation</em> that inherits the semantics of this
43 * annotation.
44 *
45 * <h2>Warning</h2>
46 *
47 * <p>This annotation can only be declared once on an
48 * {@link java.lang.reflect.AnnotatedElement AnnotatedElement} (i.e., test
49 * interface, test class, or test method). If this annotation is directly
50 * present, indirectly present, or meta-present multiple times on a given
51 * element, only the first such annotation discovered by JUnit will be used;
52 * any additional declarations will be silently ignored. Note, however, that
53 * this annotation may be used in conjunction with other {@code @Enabled*} or
54 * {@code @Disabled*} annotations in this package.
55 *
56 * @since 5.6
57 * @see JRE
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.DisabledForJreRange
65 * @see org.junit.jupiter.api.condition.EnabledInNativeImage
66 * @see org.junit.jupiter.api.condition.DisabledInNativeImage
67 * @see org.junit.jupiter.api.condition.EnabledIfSystemProperty
68 * @see org.junit.jupiter.api.condition.DisabledIfSystemProperty
69 * @see org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
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 @ExtendWith(EnabledForJreRangeCondition.class)
77 @API(status = STABLE, since = "5.6")
78 @SuppressWarnings("exports")
79 public @interface EnabledForJreRange {
80
81 /**
82 * Java Runtime Environment version which should be used as the lower boundary
83 * for the version range that determines if the annotated class or method
84 * should be enabled.
85 *
86 * <p>Defaults to {@link JRE#JAVA_8 JAVA_8}, as this is the lowest
87 * supported JRE version.
88 *
89 * @see JRE
90 */
91 JRE min() default JRE.JAVA_8;
92
93 /**
94 * Java Runtime Environment version which should be used as the upper boundary
95 * for the version range that determines if the annotated class or method
96 * should be enabled.
97 *
98 * <p>Defaults to {@link JRE#OTHER OTHER}, as this will always be the highest
99 * possible version.
100 *
101 * @see JRE
102 */
103 JRE max() default JRE.OTHER;
104
105 /**
106 * Custom reason to provide if the test or container is disabled.
107 *
108 * <p>If a custom reason is supplied, it will be combined with the default
109 * reason for this annotation. If a custom reason is not supplied, the default
110 * reason will be used.
111 *
112 * @since 5.7
113 */
114 @API(status = STABLE, since = "5.7")
115 String disabledReason() default "";
116
117 }