From d7340d0a3f1e9e7e7bda6ce1e3a09ed41dd89867 Mon Sep 17 00:00:00 2001 From: Timur Saglam Date: Tue, 9 Jul 2024 17:19:12 +0200 Subject: [PATCH] Use runtime version instead of system property in the language feature test. --- core/src/test/java/de/jplag/NewJavaFeaturesTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/de/jplag/NewJavaFeaturesTest.java b/core/src/test/java/de/jplag/NewJavaFeaturesTest.java index bfc131ff0..88b0ecfcb 100644 --- a/core/src/test/java/de/jplag/NewJavaFeaturesTest.java +++ b/core/src/test/java/de/jplag/NewJavaFeaturesTest.java @@ -19,19 +19,17 @@ public class NewJavaFeaturesTest extends TestBase { private static final String CHANGE_MESSAGE = "Number of %s changed! If intended, modify the test case!"; private static final String VERSION_MISMATCH_MESSAGE = "Using Java version %s instead of %s may skew the results."; private static final String VERSION_MATCH_MESSAGE = "Java version matches, but results deviate from expected values"; - private static final String JAVA_VERSION_KEY = "java.version"; private static final String CI_VARIABLE = "CI"; - public static final int JAVA_VERSION = 21; + public static final int EXPECTED_JAVA_VERSION = 21; @Test @DisplayName("test comparison of Java files with modern language features") public void testJavaFeatureDuplicates() throws ExitException { // pre-condition - String actualJavaVersion = System.getProperty(JAVA_VERSION_KEY); + int javaVersion = Runtime.version().feature(); boolean isCiRun = System.getenv(CI_VARIABLE) != null; - boolean isCorrectJavaVersion = actualJavaVersion.startsWith(String.valueOf(JAVA_VERSION)); - assumeTrue(isCorrectJavaVersion || isCiRun, VERSION_MISMATCH_MESSAGE.formatted(actualJavaVersion, JAVA_VERSION)); + assumeTrue(javaVersion == EXPECTED_JAVA_VERSION || isCiRun, VERSION_MISMATCH_MESSAGE.formatted(javaVersion, EXPECTED_JAVA_VERSION)); JPlagResult result = runJPlagWithExclusionFile(ROOT_DIRECTORY, EXCLUSION_FILE_NAME);