}
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"));
+ }
}
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;
@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();
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;
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
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")) {
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;
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);