Adjust test for JDK 9, 10 and 11
fix some IDE/Javadoc warnings git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1839195 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
876a783aee
commit
71002b2491
@ -231,13 +231,10 @@ public abstract class POIDocument implements Closeable {
|
||||
|
||||
// Find the entry, and get an input stream for it
|
||||
step = "getting";
|
||||
DocumentInputStream dis = dirNode.createDocumentInputStream( dirNode.getEntry(setName) );
|
||||
try {
|
||||
try (DocumentInputStream dis = dirNode.createDocumentInputStream(dirNode.getEntry(setName))) {
|
||||
// Create the Property Set
|
||||
step = "creating";
|
||||
return PropertySetFactory.create(dis);
|
||||
} finally {
|
||||
dis.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
@ -424,7 +421,7 @@ public abstract class POIDocument implements Closeable {
|
||||
* Closes the underlying {@link NPOIFSFileSystem} from which
|
||||
* the document was read, if any. Has no effect on documents
|
||||
* opened from an InputStream, or newly created ones.
|
||||
* <p>Once {@link #close()} has been called, no further operations
|
||||
* <p>Once close() has been called, no further operations
|
||||
* should be called on the document.
|
||||
*/
|
||||
@Override
|
||||
|
@ -130,7 +130,7 @@ public interface SlideShow<
|
||||
/**
|
||||
* @return the instance which handles the persisting of the slideshow,
|
||||
* which is either a subclass of {@link org.apache.poi.POIDocument}
|
||||
* or {@link org.apache.poi.POIXMLDocument}
|
||||
* or {@link org.apache.poi.ooxml.POIXMLDocument}
|
||||
*
|
||||
* @since POI 4.0.0
|
||||
*/
|
||||
|
@ -55,7 +55,7 @@ public class TestCellFormatPart extends CellFormatTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneralFormat() throws Exception {
|
||||
public void testGeneralFormat() {
|
||||
runFormatTests("GeneralFormatTests.xlsx", new CellValue() {
|
||||
@Override
|
||||
public Object getValue(Cell cell) {
|
||||
@ -71,7 +71,8 @@ public class TestCellFormatPart extends CellFormatTestBase {
|
||||
});
|
||||
}
|
||||
|
||||
public void testNumberFormat() throws Exception {
|
||||
@Test
|
||||
public void testNumberFormat() {
|
||||
runFormatTests("NumberFormatTests.xlsx", new CellValue() {
|
||||
@Override
|
||||
public Object getValue(Cell cell) {
|
||||
@ -81,7 +82,7 @@ public class TestCellFormatPart extends CellFormatTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumberApproxFormat() throws Exception {
|
||||
public void testNumberApproxFormat() {
|
||||
runFormatTests("NumberFormatApproxTests.xlsx", new CellValue() {
|
||||
@Override
|
||||
public Object getValue(Cell cell) {
|
||||
@ -102,7 +103,7 @@ public class TestCellFormatPart extends CellFormatTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateFormat() throws Exception {
|
||||
public void testDateFormat() {
|
||||
TimeZone tz = LocaleUtil.getUserTimeZone();
|
||||
LocaleUtil.setUserTimeZone(TimeZone.getTimeZone("CET"));
|
||||
try {
|
||||
@ -118,7 +119,7 @@ public class TestCellFormatPart extends CellFormatTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testElapsedFormat() throws Exception {
|
||||
public void testElapsedFormat() {
|
||||
runFormatTests("ElapsedFormatTests.xlsx", new CellValue() {
|
||||
@Override
|
||||
public Object getValue(Cell cell) {
|
||||
@ -128,7 +129,7 @@ public class TestCellFormatPart extends CellFormatTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextFormat() throws Exception {
|
||||
public void testTextFormat() {
|
||||
runFormatTests("TextFormatTests.xlsx", new CellValue() {
|
||||
@Override
|
||||
public Object getValue(Cell cell) {
|
||||
@ -143,7 +144,7 @@ public class TestCellFormatPart extends CellFormatTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConditions() throws Exception {
|
||||
public void testConditions() {
|
||||
runFormatTests("FormatConditionTests.xlsx", new CellValue() {
|
||||
@Override
|
||||
Object getValue(Cell cell) {
|
||||
|
@ -96,8 +96,7 @@ public class CellFormatTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
protected void runFormatTests(String workbookName, CellValue valueGetter)
|
||||
throws IOException {
|
||||
protected void runFormatTests(String workbookName, CellValue valueGetter) {
|
||||
|
||||
openWorkbook(workbookName);
|
||||
|
||||
@ -136,11 +135,8 @@ public class CellFormatTestBase {
|
||||
* @param workbookName The workbook name. This is presumed to live in the
|
||||
* "spreadsheets" directory under the directory named in
|
||||
* the Java property "POI.testdata.path".
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void openWorkbook(String workbookName)
|
||||
throws IOException {
|
||||
protected void openWorkbook(String workbookName) {
|
||||
workbook = _testDataProvider.openSampleWorkbook(workbookName);
|
||||
workbook.setMissingCellPolicy(MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
||||
testFile = workbookName;
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.text.FieldPosition;
|
||||
@ -42,6 +41,41 @@ public class TestExcelStyleDateFormatter {
|
||||
*/
|
||||
@Test
|
||||
public void test60369() throws ParseException {
|
||||
Map<Locale, List<String>> testMap = initializeLocales();
|
||||
|
||||
// We have to set up dates as well.
|
||||
SimpleDateFormat testDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
|
||||
List<Date> testDates = Arrays.asList(
|
||||
testDateFormat.parse("12.01.1980"),
|
||||
testDateFormat.parse("11.02.1995"),
|
||||
testDateFormat.parse("10.03.2045"),
|
||||
testDateFormat.parse("09.04.2016"),
|
||||
testDateFormat.parse("08.05.2017"),
|
||||
testDateFormat.parse("07.06.1945"),
|
||||
testDateFormat.parse("06.07.1998"),
|
||||
testDateFormat.parse("05.08.2099"),
|
||||
testDateFormat.parse("04.09.1988"),
|
||||
testDateFormat.parse("03.10.2023"),
|
||||
testDateFormat.parse("02.11.1978"),
|
||||
testDateFormat.parse("01.12.1890"));
|
||||
|
||||
// Let's iterate over the test setup.
|
||||
for (Locale locale : testMap.keySet()) {
|
||||
ExcelStyleDateFormatter formatter = new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT, new DateFormatSymbols(locale));
|
||||
for (int i = 0; i < testDates.size(); i++) {
|
||||
// Call the method to be tested!
|
||||
String result =
|
||||
formatter.format(testDates.get(i),
|
||||
new StringBuffer(),
|
||||
new FieldPosition(java.text.DateFormat.MONTH_FIELD)).toString();
|
||||
//System.err.println(result + " - " + getUnicode(result.charAt(0)));
|
||||
assertEquals("Failed for locale " + locale + " and date " + testDates.get(i) + ", having: " + result,
|
||||
getUnicode(testMap.get(locale).get(i).charAt(0)), getUnicode(result.charAt(0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Locale, List<String>> initializeLocales() {
|
||||
// Setting up the locale to be tested together with a list of asserted unicode-formatted results and put them in a map.
|
||||
Locale germanLocale = Locale.GERMAN;
|
||||
List<String> germanResultList = Arrays.asList("\u004a", "\u0046", "\u004d", "\u0041", "\u004d",
|
||||
@ -96,37 +130,7 @@ public class TestExcelStyleDateFormatter {
|
||||
testMap.put(indianLocale, indianResultList);
|
||||
testMap.put(indonesianLocale, indonesianResultList);
|
||||
|
||||
// We have to set up dates as well.
|
||||
SimpleDateFormat testDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
|
||||
List<Date> testDates = Arrays.asList(
|
||||
testDateFormat.parse("12.01.1980"),
|
||||
testDateFormat.parse("11.02.1995"),
|
||||
testDateFormat.parse("10.03.2045"),
|
||||
testDateFormat.parse("09.04.2016"),
|
||||
testDateFormat.parse("08.05.2017"),
|
||||
testDateFormat.parse("07.06.1945"),
|
||||
testDateFormat.parse("06.07.1998"),
|
||||
testDateFormat.parse("05.08.2099"),
|
||||
testDateFormat.parse("04.09.1988"),
|
||||
testDateFormat.parse("03.10.2023"),
|
||||
testDateFormat.parse("02.11.1978"),
|
||||
testDateFormat.parse("01.12.1890"));
|
||||
|
||||
// Let's iterate over the test setup.
|
||||
for (Locale locale : testMap.keySet()) {
|
||||
//System.err.println("Locale: " + locale);
|
||||
ExcelStyleDateFormatter formatter = new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT, new DateFormatSymbols(locale));
|
||||
for (int i = 0; i < 12; i++) {
|
||||
// Call the method to be tested!
|
||||
String result =
|
||||
formatter.format(testDates.get(i),
|
||||
new StringBuffer(),
|
||||
new FieldPosition(java.text.DateFormat.MONTH_FIELD)).toString();
|
||||
//System.err.println(result + " - " + getUnicode(result.charAt(0)));
|
||||
assertEquals("testing locale " + locale,
|
||||
getUnicode(testMap.get(locale).get(i).charAt(0)), getUnicode(result.charAt(0)));
|
||||
}
|
||||
}
|
||||
return testMap;
|
||||
}
|
||||
|
||||
private String getUnicode(char c) {
|
||||
@ -135,8 +139,8 @@ public class TestExcelStyleDateFormatter {
|
||||
|
||||
@Test
|
||||
public void testConstruct() {
|
||||
assertNotNull(new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT, LocaleUtil.getUserLocale()));
|
||||
assertNotNull(new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT));
|
||||
new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT, LocaleUtil.getUserLocale());
|
||||
new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user