Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRangeCondition.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.junit.jupiter.api.condition.EnabledOnJreCondition.DISABLED_ON_CURRENT_JRE;
14 import static org.junit.jupiter.api.condition.EnabledOnJreCondition.ENABLED_ON_CURRENT_JRE;
15
16 import org.junit.jupiter.api.extension.ExecutionCondition;
17 import org.junit.platform.commons.util.Preconditions;
18
19 /**
20 * {@link ExecutionCondition} for {@link EnabledForJreRange @EnabledForJreRange}.
21 *
22 * @since 5.6
23 * @see EnabledForJreRange
24 */
25 class EnabledForJreRangeCondition extends BooleanExecutionCondition<EnabledForJreRange> {
26
27 EnabledForJreRangeCondition() {
28 super(EnabledForJreRange.class, ENABLED_ON_CURRENT_JRE, DISABLED_ON_CURRENT_JRE,
29 EnabledForJreRange::disabledReason);
30 }
31
32 @Override
33 boolean isEnabled(EnabledForJreRange annotation) {
34 JRE min = annotation.min();
35 JRE max = annotation.max();
36
37 Preconditions.condition((min != JRE.JAVA_8 || max != JRE.OTHER),
38 "You must declare a non-default value for min or max in @EnabledForJreRange");
39 Preconditions.condition(max.compareTo(min) >= 0,
40 "@EnabledForJreRange.min must be less than or equal to @EnabledForJreRange.max");
41
42 return JRE.isCurrentVersionWithinRange(min, max);
43 }
44
45 }