forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support arbitrary Java versions with JRE conditions
This commit introduces support for arbitrary Java versions in the JRE enum, @EnabledOnJre, @DisabledOnJre, @EnabledForJreRange, and @DisabledForJreRange. Closes: junit-team#3930 Closes: junit-team#3931
- Loading branch information
Showing
25 changed files
with
1,170 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2015-2025 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.condition; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.function.Function; | ||
|
||
import org.junit.platform.commons.util.Preconditions; | ||
|
||
/** | ||
* Abstract base class for {@link EnabledOnJreCondition} and | ||
* {@link DisabledOnJreCondition}. | ||
* | ||
* @since 5.12 | ||
*/ | ||
abstract class AbstractJreCondition<A extends Annotation> extends BooleanExecutionCondition<A> { | ||
|
||
static final String ENABLED_ON_CURRENT_JRE = // | ||
"Enabled on JRE version: " + System.getProperty("java.version"); | ||
|
||
static final String DISABLED_ON_CURRENT_JRE = // | ||
"Disabled on JRE version: " + System.getProperty("java.version"); | ||
|
||
private final String annotationName; | ||
|
||
AbstractJreCondition(Class<A> annotationType, Function<A, String> customDisabledReason) { | ||
super(annotationType, ENABLED_ON_CURRENT_JRE, DISABLED_ON_CURRENT_JRE, customDisabledReason); | ||
this.annotationName = annotationType.getSimpleName(); | ||
} | ||
|
||
protected void validateVersions(JRE[] jres, int[] versions) { | ||
Preconditions.condition(jres.length > 0 || versions.length > 0, | ||
() -> "You must declare at least one JRE or version in @" + this.annotationName); | ||
for (JRE jre : jres) { | ||
Preconditions.condition(jre != JRE.UNDEFINED, | ||
() -> "JRE.UNDEFINED is not supported in @" + this.annotationName); | ||
} | ||
for (int version : versions) { | ||
Preconditions.condition(version >= 8, | ||
() -> String.format("Version [%d] in @%s must be greater than or equal to 8", version, | ||
this.annotationName)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.