| 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 @EnabledOnJre} is used to signal that the annotated test class or |
| 26 | * test method is only <em>enabled</em> on one or more specified Java |
| 27 | * Runtime Environment (JRE) {@linkplain #value versions}. |
| 28 | * |
| 29 | * <p>When applied at the class level, all test methods within that class |
| 30 | * will 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>As of JUnit Jupiter 5.1, 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.1 |
| 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.DisabledOnJre |
| 63 | * @see org.junit.jupiter.api.condition.EnabledForJreRange |
| 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(EnabledOnJreCondition.class) |
| 77 | @API(status = STABLE, since = "5.1") |
| 78 | @SuppressWarnings("exports") |
| 79 | public @interface EnabledOnJre { |
| 80 | |
| 81 | /** |
| 82 | * Java Runtime Environment versions on which the annotated class or |
| 83 | * method should be enabled. |
| 84 | * |
| 85 | * @see JRE |
| 86 | */ |
| 87 | JRE[] value(); |
| 88 | |
| 89 | /** |
| 90 | * Custom reason to provide if the test or container is disabled. |
| 91 | * |
| 92 | * <p>If a custom reason is supplied, it will be combined with the default |
| 93 | * reason for this annotation. If a custom reason is not supplied, the default |
| 94 | * reason will be used. |
| 95 | * |
| 96 | * @since 5.7 |
| 97 | */ |
| 98 | @API(status = STABLE, since = "5.7") |
| 99 | String disabledReason() default ""; |
| 100 | } |