mirror of https://github.com/apache/poi.git
Adjust some tests for Java 19 and Java 20
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903105 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4df10cf9dd
commit
af4d1e9f1a
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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")) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue