Bug530901 - Prepare Java SE platform detection code for Java 11.
Signed-off-by: Tomas Kraus <tomas.kraus@oracle.com>
Reviewed-by: Lukas Jungmann <lukas.jungmann@oracle.com>
diff --git a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaSEPlatformTest.java b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaSEPlatformTest.java
new file mode 100644
index 0000000..f97dc4e
--- /dev/null
+++ b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaSEPlatformTest.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Tomas Kraus - 2018/01/08
+ * Bug 530901 - Prepare Java SE platform detection code for Java 11
+ ******************************************************************************/
+package org.eclipse.persistence.testing.tests.junit.helper;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.persistence.internal.helper.JavaSEPlatform;
+import org.junit.Test;
+
+/**
+ * JavaSEPlatform class jUnit tests.
+ */
+public class JavaSEPlatformTest {
+
+ /** This value must match {@code JavaSEPlatform.LATEST} */
+ static final JavaSEPlatform LATEST = JavaUtilTest.initDefault();
+
+ /**
+ * Versions data holder.
+ */
+ private static final class VersionData {
+ private final int major;
+ private final int minor;
+ private final JavaSEPlatform platform;
+ private VersionData(final int major, final int minor, final JavaSEPlatform platform) {
+ this.major = major;
+ this.minor = minor;
+ this.platform = platform;
+ }
+ }
+
+ /** Input data for {@code testToValue()} test method.
+ * Contains input major and minor version numbers with expected JavaSEPlatform value to be returned.
+ * Data must match expected {@link JavaSEPlatform#toValue(int, int)} method returned values. */
+ private static final VersionData[] TO_VALUE_DATA = {
+ new VersionData( 1, 1, JavaSEPlatform.v1_1),
+ new VersionData( 1, 2, JavaSEPlatform.v1_2),
+ new VersionData( 1, 3, JavaSEPlatform.v1_3),
+ new VersionData( 1, 4, JavaSEPlatform.v1_4),
+ new VersionData( 1, 5, JavaSEPlatform.v1_5),
+ new VersionData( 1, 6, JavaSEPlatform.v1_6),
+ new VersionData( 1, 7, JavaSEPlatform.v1_7),
+ new VersionData( 1, 8, JavaSEPlatform.v1_8),
+ new VersionData( 1, 9, JavaSEPlatform.v9_0),
+ new VersionData( 1, 10, LATEST),
+ new VersionData( 9, 0, JavaSEPlatform.v9_0),
+ new VersionData(10, 0, JavaSEPlatform.v10_0),
+ new VersionData(11, 0, JavaSEPlatform.v11_0),
+ new VersionData(12, 0, LATEST)
+ };
+
+ /**
+ * Test {@code toValue(int,int)} static method.
+ */
+ @Test
+ public void testToValue() {
+ for (final VersionData data : TO_VALUE_DATA) {
+ final JavaSEPlatform out = JavaSEPlatform.toValue(data.major, data.minor);
+ assertEquals("Expected " + data.platform.toString()
+ + " for version number " + Integer.toString(data.major) + "."
+ + Integer.toString(data.minor), data.platform, out);
+ }
+ }
+
+}
diff --git a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaUtilTest.java b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaUtilTest.java
index b0cb207..c1d53f6 100644
--- a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaUtilTest.java
+++ b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaUtilTest.java
@@ -12,6 +12,11 @@
******************************************************************************/
package org.eclipse.persistence.testing.tests.junit.helper;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import org.eclipse.persistence.internal.helper.JavaSEPlatform;
import org.eclipse.persistence.internal.helper.JavaVersion;
import org.eclipse.persistence.testing.framework.ReflectionHelper;
@@ -21,19 +26,20 @@
* Test Java related utilities.
* @author Tomas Kraus, Peter Benedikovic
*/
-public class JavaUtilTest extends junit.framework.TestCase {
+public class JavaUtilTest {
// Valid version number pairs.
static final int[][] VALID = {
{1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {1, 9},
- {9, 0}, {10, 0}, {18, 3}, {18, 9}
+ {9, 0}, {10, 0}, {11, 0}
};
// Invalid version number pairs.
static final int[][] INVALID = {
{0, 0}, {0, 1}, {0, 3}, {0, 5}, {0, 7}, {0, 9},
{1, 0}, {2, 0}, {2, 1}, {2, 2}, {3, 0}, {4, 0}, {1, 10},
- {18, 1}, {18, 2}, {18, 4}, {18, 5}, {18, 6}, {18, 7}, {18, 8}, {18, 10}, {18, 11}, {18, 12}
+ {18, 1}, {18, 2}, {18, 3}, {18, 4}, {18, 5}, {18, 6},
+ {18, 7}, {18, 8}, {18, 9}, {18, 10}, {18, 11}, {18, 12}
};
// DEFAULT platform value.
@@ -61,20 +67,13 @@
* Initialize value of JavaSEPlatform.DEFAULT.
* @return value of JavaSEPlatform.DEFAULT.
*/
- private static final JavaSEPlatform initDefault() {
+ static final JavaSEPlatform initDefault() {
try {
return ReflectionHelper.getPrivateStatic(JavaSEPlatform.class, "LATEST");
} catch (ReflectiveOperationException e) {
return null;
}
}
- /**
- * Constructs an instance of Java utilities.
- * @param name java.lang.String
- */
- public JavaUtilTest(String name) {
- super(name);
- }
/**
* Test <code>JavaVersion.comapreTo</code> functionality.
@@ -127,7 +126,7 @@
int minor = version[1];
String versionString = JavaSEPlatform.versionString(major, minor);
JavaSEPlatform platform = JavaSEPlatform.toValue(major, minor);
- assertTrue("Returned platform shall be JavaSEPlatform.DEFAULT for invalid version "
+ assertTrue("Returned platform shall be JavaSEPlatform.LATEST for invalid version "
+ "number ["+Integer.toString(major)+","+Integer.toString(minor)+"]",
LATEST.getMajor() == platform.getMajor() && LATEST.getMinor() == platform.getMinor());
}
@@ -156,7 +155,7 @@
int major = version[0];
int minor = version[1];
JavaSEPlatform platform = JavaSEPlatform.toValue(major, minor);
- assertTrue("Returned platform shall be JavaSEPlatform.DEFAULT for invalid version "
+ assertTrue("Returned platform shall be JavaSEPlatform.LATEST for invalid version "
+ "number ["+Integer.toString(major)+","+Integer.toString(minor)+"]",
LATEST.getMajor() == platform.getMajor() && LATEST.getMinor() == platform.getMinor());
}
diff --git a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaVersionTest.java b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaVersionTest.java
index 0de71cc..ecf8472 100644
--- a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaVersionTest.java
+++ b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/helper/JavaVersionTest.java
@@ -13,6 +13,10 @@
******************************************************************************/
package org.eclipse.persistence.testing.tests.junit.helper;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.lang.reflect.Method;
import org.eclipse.persistence.internal.helper.JavaSEPlatform;
@@ -20,9 +24,7 @@
import org.eclipse.persistence.testing.framework.ReflectionHelper;
import org.junit.Test;
-import junit.framework.TestCase;
-
-public class JavaVersionTest extends TestCase {
+public class JavaVersionTest {
/**
* Check whether current Java has {@code Runtime.Version} class.
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/JavaSEPlatform.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/JavaSEPlatform.java
index 1caf95e..b75a643 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/JavaSEPlatform.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/JavaSEPlatform.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2017 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -41,10 +41,8 @@
v9_0(9,0, new Version(1,9)),
/** Java SE 10. */
v10_0(10,0),
- /** Java SE 18.3. */
- v18_3(18,3),
- /** Java SE 18.9. */
- v18_9(18,9);
+ /** Java SE 11. */
+ v11_0(11,0);
public static final class Version {
/**
@@ -124,15 +122,15 @@
/** GlassFish Java SE platform enumeration length. */
public static final int LENGTH = JavaSEPlatform.values().length;
- /** Current Java SE platform. */
- public static final JavaSEPlatform CURRENT
- = JavaVersion.vmVersion().toPlatform();
-
/** Lowest supported Java SE platform. Currently it's Java SE 1.8. */
public static final JavaSEPlatform MIN_SUPPORTED = v1_8;
/** Latest Java SE platform. This value is used when Java SE platform detection fails. */
- static final JavaSEPlatform LATEST = JavaSEPlatform.v18_9;
+ static final JavaSEPlatform LATEST = JavaSEPlatform.v11_0;
+
+ /** Current Java SE platform. */
+ public static final JavaSEPlatform CURRENT
+ = JavaVersion.vmVersion().toPlatform();
/**
* Check whether current Java SE is exactly matching provided platform.
@@ -198,16 +196,9 @@
case 9: return v9_0;
default: return LATEST;
}
- case 9:
- return v9_0;
- case 10:
- return v10_0;
- case 18:
- switch (minor) {
- case 3: return v18_3;
- case 9: return v18_9;
- default: return LATEST;
- }
+ case 9: return v9_0;
+ case 10: return v10_0;
+ case 11: return v11_0;
default: return LATEST;
}
}