try to fix windows path issues in exception messages

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1887346 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2021-03-08 23:14:11 +00:00
parent afbef57d35
commit cee9eb7e2b

View File

@ -88,10 +88,12 @@ public abstract class AbstractFileHandler implements FileHandler {
POITextExtractor extractor = null; POITextExtractor extractor = null;
String fileAndParentName = file.getParentFile().getName() + "/" + file.getName(); String fileAndParentName = file.getParentFile().getName() + "/" + file.getName();
try { try {
// fix windows absolute paths for exception message tracking
String relPath = file.getPath().replace(".*test-data", "test-data").replace('\\', '/');
extractor = ExtractorFactory.createExtractor(file); extractor = ExtractorFactory.createExtractor(file);
assertNotNull(extractor, "Should get a POITextExtractor but had none for file " + 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 " + file); assertNotNull(extractor.getText(), "Should get some text but had none for file " + relPath);
// also try metadata // also try metadata
@SuppressWarnings("resource") @SuppressWarnings("resource")
@ -99,7 +101,7 @@ public abstract class AbstractFileHandler implements FileHandler {
assertNotNull(metadataExtractor.getText()); assertNotNull(metadataExtractor.getText());
assertFalse(EXPECTED_EXTRACTOR_FAILURES.contains(fileAndParentName), assertFalse(EXPECTED_EXTRACTOR_FAILURES.contains(fileAndParentName),
"Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!"); "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(length, file.length(), "File should not be modified by extractor");
assertEquals(modified, file.lastModified(), "File should not be modified by extractor"); assertEquals(modified, file.lastModified(), "File should not be modified by extractor");