Skip to content

Commit

Permalink
Increase coverage for JavaVersionHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Jan 2, 2024
1 parent ac11ed3 commit 0abcd9f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -61,4 +60,8 @@ public static int parseUniversalJavaMajorVersion() {
return res;
}

public static int parseUniversalJavaMajorVersion() {
return parseUniversalJavaMajorVersion( System.getProperty( SYS_PROP ) );
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 ) );
}

}

0 comments on commit 0abcd9f

Please sign in to comment.