Author: centic
Date: Tue Oct 3 06:06:03 2023
New Revision: 1912708
URL: http://svn.apache.org/viewvc?rev=1912708&view=rev
Log:
Adjust order of testing and use try-with-resources
Modified:
poi/trunk/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java
Modified:
poi/trunk/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java?rev=1912708&r1=1912707&r2=1912708&view=diff
==============================================================================
---
poi/trunk/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java
(original)
+++
poi/trunk/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java
Tue Oct 3 06:06:03 2023
@@ -37,7 +37,6 @@ import org.apache.poi.hpsf.extractor.HPS
import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.ss.extractor.ExcelExtractor;
-import org.apache.poi.util.IOUtils;
/**
* Base class with things that can be run for any supported file handler
@@ -88,54 +87,53 @@ public abstract class AbstractFileHandle
long length = file.length();
long modified = file.lastModified();
- POITextExtractor extractor = null;
String fileAndParentName = file.getParentFile().getName() + "/" +
file.getName();
try {
+ handleExtractingAsStream(file);
+
// fix windows absolute paths for exception message tracking
String relPath = file.getPath().replaceAll(".*test-data",
"test-data").replace('\\', '/');
- extractor = ExtractorFactory.createExtractor(file);
- assertNotNull(extractor, "Should get a POITextExtractor but had
none for file " + relPath);
+ try (POITextExtractor extractor =
ExtractorFactory.createExtractor(file)) {
+ assertNotNull(extractor, "Should get a POITextExtractor but
had none for file " + relPath);
- assertNotNull(extractor.getText(), "Should get some text but had
none for file " + relPath);
+ assertNotNull(extractor.getText(), "Should get some text but
had none for file " + relPath);
- // also try metadata
- @SuppressWarnings("resource")
- POITextExtractor metadataExtractor =
extractor.getMetadataTextExtractor();
- assertNotNull(metadataExtractor.getText());
+ // also try metadata
+ POITextExtractor metadataExtractor =
extractor.getMetadataTextExtractor();
+ assertNotNull(metadataExtractor.getText());
+
+
assertFalse(EXPECTED_EXTRACTOR_FAILURES.contains(fileAndParentName),
+ "Expected Extraction to fail for file " + relPath + "
and handler " + this + ", but did not fail!");
+
+ assertEquals(length, file.length(), "File should not be
modified by extractor");
+ assertEquals(modified, file.lastModified(), "File should not
be modified by extractor");
+
+ if (extractor instanceof POIOLE2TextExtractor) {
+ try (HPSFPropertiesExtractor hpsfExtractor = new
HPSFPropertiesExtractor((POIOLE2TextExtractor) extractor)) {
+
assertNotNull(hpsfExtractor.getDocumentSummaryInformationText());
+
assertNotNull(hpsfExtractor.getSummaryInformationText());
+ String text = hpsfExtractor.getText();
+ //System.out.println(text);
+ assertNotNull(text);
+ }
+ }
-
assertFalse(EXPECTED_EXTRACTOR_FAILURES.contains(fileAndParentName),
- "Expected Extraction to fail for file " + relPath + " and
handler " + this + ", but did not fail!");
+ // test again with including formulas and cell-comments as
this caused some bugs
+ if (extractor instanceof ExcelExtractor &&
+ // comment-extraction and formula extraction are not
well supported in event based extraction
+ !(extractor instanceof EventBasedExcelExtractor)) {
+ ((ExcelExtractor) extractor).setFormulasNotResults(true);
- assertEquals(length, file.length(), "File should not be modified
by extractor");
- assertEquals(modified, file.lastModified(), "File should not be
modified by extractor");
+ String text = extractor.getText();
+ assertNotNull(text);
+ // */
- handleExtractingAsStream(file);
+ ((ExcelExtractor) extractor).setIncludeCellComments(true);
- if (extractor instanceof POIOLE2TextExtractor) {
- try (HPSFPropertiesExtractor hpsfExtractor = new
HPSFPropertiesExtractor((POIOLE2TextExtractor) extractor)) {
-
assertNotNull(hpsfExtractor.getDocumentSummaryInformationText());
- assertNotNull(hpsfExtractor.getSummaryInformationText());
- String text = hpsfExtractor.getText();
- //System.out.println(text);
+ text = extractor.getText();
assertNotNull(text);
}
}
-
- // test again with including formulas and cell-comments as this
caused some bugs
- if (extractor instanceof ExcelExtractor &&
- // comment-extraction and formula extraction are not well
supported in event based extraction
- !(extractor instanceof EventBasedExcelExtractor)) {
- ((ExcelExtractor) extractor).setFormulasNotResults(true);
-
- String text = extractor.getText();
- assertNotNull(text);
- // */
-
- ((ExcelExtractor) extractor).setIncludeCellComments(true);
-
- text = extractor.getText();
- assertNotNull(text);
- }
} catch (IOException | POIXMLException e) {
Exception prevE = e;
Throwable cause;
@@ -159,8 +157,6 @@ public abstract class AbstractFileHandle
if (!e.getMessage().contains("POI Scratchpad jar missing") ||
!Boolean.getBoolean("scratchpad.ignore")) {
throw e;
}
- } finally {
- IOUtils.closeQuietly(extractor);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]