From 0abcd9fac16bbb9357721550a80078e09f98a8c9 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Tue, 2 Jan 2024 15:19:49 +0100 Subject: [PATCH] Increase coverage for JavaVersionHelper --- .../core/lang/helpers/JavaVersionHelper.java | 7 ++- .../lang/helpers/TestJavaVersionHelper.java | 54 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/JavaVersionHelper.java b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/JavaVersionHelper.java index d42e5294..52d6e4ed 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/JavaVersionHelper.java +++ b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/JavaVersionHelper.java @@ -33,9 +33,8 @@ private JavaVersionHelper() {} public static final int UNDEFINED = -1; - public static int parseUniversalJavaMajorVersion() { + public static int parseUniversalJavaMajorVersion( String javaVersion ) { int res = UNDEFINED; - String javaVersion = System.getProperty( SYS_PROP ); if ( StringUtils.isEmpty( javaVersion ) ) { throw new ConfigRuntimeException( "null property "+SYS_PROP ); } else { @@ -61,4 +60,8 @@ public static int parseUniversalJavaMajorVersion() { return res; } + public static int parseUniversalJavaMajorVersion() { + return parseUniversalJavaMajorVersion( System.getProperty( SYS_PROP ) ); + } + } diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/TestJavaVersionHelper.java b/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/TestJavaVersionHelper.java index b7ad6b79..480e8542 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/TestJavaVersionHelper.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/TestJavaVersionHelper.java @@ -1,5 +1,6 @@ package test.org.fugerit.java.core.lang.helpers; +import org.fugerit.java.core.cfg.ConfigRuntimeException; import org.fugerit.java.core.lang.helpers.JavaVersionHelper; import org.junit.Assert; import org.junit.Test; @@ -18,5 +19,58 @@ public void test() { || majorVersion == JavaVersionHelper.MAJOR_VERSION_JAVA_21 ); Assert.assertTrue( "Wrong java major version : "+majorVersion , supportedBuildVersion ); } + + @Test + public void test7() { + int majorVersion = JavaVersionHelper.parseUniversalJavaMajorVersion( "1.7.0_123" ); + log.info("major version -> '{}'", majorVersion); + boolean supportedBuildVersion = ( majorVersion == 7 ); + Assert.assertTrue( "Wrong java major version : "+majorVersion , supportedBuildVersion ); + } + + @Test + public void testUndefined() { + int majorVersion = JavaVersionHelper.parseUniversalJavaMajorVersion( "1.8X.0_362" ); + log.info("major version -> '{}'", majorVersion); + boolean supportedBuildVersion = ( majorVersion == JavaVersionHelper.UNDEFINED ); + Assert.assertTrue( "Wrong java major version : "+majorVersion , supportedBuildVersion ); + } + + @Test + public void test8() { + int majorVersion = JavaVersionHelper.parseUniversalJavaMajorVersion( "1.8.0_362" ); + log.info("major version -> '{}'", majorVersion); + boolean supportedBuildVersion = ( majorVersion == JavaVersionHelper.MAJOR_VERSION_JAVA_8 ); + Assert.assertTrue( "Wrong java major version : "+majorVersion , supportedBuildVersion ); + } + + @Test + public void test11() { + int majorVersion = JavaVersionHelper.parseUniversalJavaMajorVersion( "11.0.18" ); + log.info("major version -> '{}'", majorVersion); + boolean supportedBuildVersion = ( majorVersion == JavaVersionHelper.MAJOR_VERSION_JAVA_11 ); + Assert.assertTrue( "Wrong java major version : "+majorVersion , supportedBuildVersion ); + } + + @Test + public void test17() { + int majorVersion = JavaVersionHelper.parseUniversalJavaMajorVersion( "17.0.7" ); + log.info("major version -> '{}'", majorVersion); + boolean supportedBuildVersion = ( majorVersion == JavaVersionHelper.MAJOR_VERSION_JAVA_17 ); + Assert.assertTrue( "Wrong java major version : "+majorVersion , supportedBuildVersion ); + } + + @Test + public void test21() { + int majorVersion = JavaVersionHelper.parseUniversalJavaMajorVersion( "21" ); + log.info("major version -> '{}'", majorVersion); + boolean supportedBuildVersion = ( majorVersion == JavaVersionHelper.MAJOR_VERSION_JAVA_21 ); + Assert.assertTrue( "Wrong java major version : "+majorVersion , supportedBuildVersion ); + } + @Test + public void testNull() { + Assert.assertThrows( ConfigRuntimeException.class , () -> JavaVersionHelper.parseUniversalJavaMajorVersion( null ) ); + } + }