]> source.dussan.org Git - poi.git/commitdiff
Adjust some tests for Java 19 and Java 20
authorDominik Stadler <centic@apache.org>
Fri, 29 Jul 2022 17:07:19 +0000 (17:07 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 29 Jul 2022 17:07:19 +0000 (17:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903105 13f79535-47bb-0310-9956-ffa450edef68

poi/src/test/java/org/apache/poi/POITestCase.java
poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java
poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java
poi/src/test/java/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java

index 4f43cb216c25a3400f3d01d2d39e467f0ccfa6a4..d4c99bebdb20104269deefcc8cc01748465c33c0 100644 (file)
@@ -157,4 +157,14 @@ public final class POITestCase {
         }
         ImageIO.setCacheDirectory(tmpDir);
     }
+
+    /**
+     * Returns the major version of Java as simple integer, i.e.
+     * "8" for JDK 1.8, "11" for JDK 11, "12" for JDK 12 and so on.
+     *
+     * @return The major version of Java
+     */
+    public static int getJDKVersion() {
+        return Integer.parseInt(System.getProperty("java.version").replaceAll("^(?:1\\.)?(\\d+).*", "$1"));
+    }
 }
index 3a8455e3e0e147e593108f618ace07974835af3a..ad585737645e4994eb12812f53f4fcb6906c4136 100644 (file)
@@ -30,6 +30,7 @@ import java.io.UnsupportedEncodingException;
 import java.security.Permission;
 
 import org.apache.commons.io.output.NullPrintStream;
+import org.apache.poi.POITestCase;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.poifs.filesystem.NotOLE2FileException;
 import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
@@ -168,8 +169,7 @@ public class TestPOIFSDump {
     @Test
     @SuppressForbidden("tests java.security features deprecated in java 17 - no other option though")
     void testMainNoArgs() {
-        final String javaVersion = System.getProperty("java.version");
-        Assumptions.assumeFalse(javaVersion.startsWith("18") || javaVersion.startsWith("19") || javaVersion.startsWith("2"),
+        Assumptions.assumeFalse(POITestCase.getJDKVersion() >= 18,
                 "SecurityManager does not work any more since JDK 18");
 
         SecurityManager sm = System.getSecurityManager();
index 8d420462c13b19c16c8bccf9293c41b39276c414..0d6c1af5b93f474072cce0ce5c0476d003cecbcc 100644 (file)
@@ -35,6 +35,7 @@ import java.util.Locale;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.poi.POITestCase;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
@@ -774,13 +775,14 @@ class TestDataFormatter {
         assertTrue(DateUtil.isADateFormat(-1, "[h]"));
     }
 
-
     @Test
     void testLargeNumbersAndENotation() throws IOException{
         assertFormatsTo("1E+86", 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999d);
         assertFormatsTo("1E-84", 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000001d);
         // Smallest double
-        assertFormatsTo("1E-323", 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001d);
+        // See https://bugs.openjdk.org/browse/JDK-8291240
+        assertFormatsTo(POITestCase.getJDKVersion() >= 19 ? "9.9E-324" : "1E-323",
+                0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001d);
 
         // "up to 11 numeric characters, with the decimal point counting as a numeric character"
         // https://support.microsoft.com/en-us/kb/65903
@@ -821,10 +823,18 @@ class TestDataFormatter {
             DataFormat dataFormat = wb.createDataFormat();
             newStyle.setDataFormat(dataFormat.getFormat("General"));
             String actual = new DataFormatter().formatCellValue(rawValue);
-            assertEquals(expected, actual);
+            assertEquals(expected, actual,
+                    "Failed for input " + input);
         }
     }
 
+    @Test
+    public void testJDK19() {
+        // See https://bugs.openjdk.org/browse/JDK-8291240
+        assertEquals(POITestCase.getJDKVersion() >= 19 ? "9.9E-324" : "1.0E-323",
+                Double.toString(0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001d));
+    }
+
     @Test
     void testFormulaEvaluation() throws IOException {
         try (Workbook wb = HSSFTestDataSamples.openSampleWorkbook("FormulaEvalTestData.xls")) {
index ad86341a260310a471da30d8d345657ee447f081..0588c75a7745fe65ee3bd8ddeebbb8283dafb0c5 100644 (file)
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.stream.Stream;
 
+import org.apache.poi.POITestCase;
 import org.apache.poi.util.LocaleUtil;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -41,8 +42,7 @@ import org.junit.jupiter.params.provider.MethodSource;
 class TestExcelStyleDateFormatter {
     private static final String EXCEL_DATE_FORMAT = "MMMMM";
     private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
-    private static final int jreVersion =
-        Integer.parseInt(System.getProperty("java.version").replaceAll("^(?:1\\.)?(\\d+).*", "$1"));
+    private static final int jreVersion = POITestCase.getJDKVersion();
     private static final String provider = System.getProperty("java.locale.providers");
     private static final FieldPosition fp = new FieldPosition(java.text.DateFormat.MONTH_FIELD);
     private static final ExcelStyleDateFormatter formatter = new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT);