Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledOnJreCondition.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 java.util.Arrays;
14
15 import org.junit.jupiter.api.extension.ExecutionCondition;
16 import org.junit.platform.commons.util.Preconditions;
17
18 /**
19 * {@link ExecutionCondition} for {@link EnabledOnJre @EnabledOnJre}.
20 *
21 * @since 5.1
22 * @see EnabledOnJre
23 */
24 class EnabledOnJreCondition extends BooleanExecutionCondition<EnabledOnJre> {
25
26 static final String ENABLED_ON_CURRENT_JRE = //
27 "Enabled on JRE version: " + System.getProperty("java.version");
28
29 static final String DISABLED_ON_CURRENT_JRE = //
30 "Disabled on JRE version: " + System.getProperty("java.version");
31
32 EnabledOnJreCondition() {
33 super(EnabledOnJre.class, ENABLED_ON_CURRENT_JRE, DISABLED_ON_CURRENT_JRE, EnabledOnJre::disabledReason);
34 }
35
36 @Override
37 boolean isEnabled(EnabledOnJre annotation) {
38 JRE[] versions = annotation.value();
39 Preconditions.condition(versions.length > 0, "You must declare at least one JRE in @EnabledOnJre");
40 return Arrays.stream(versions).anyMatch(JRE::isCurrentVersion);
41 }
42
43 }