From 86c0db4be114b76266396ec52349da93bae4cbca Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 11 Jan 2025 10:09:01 +0000 Subject: [PATCH] Bug 58805: Adjust reproducer test-case some more Do not write a local temp-file It seems even parsing the resulting document fails git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923063 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hwpf/usermodel/TestBugs.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBugs.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBugs.java index 133dc655dc..e2e6ce89de 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBugs.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBugs.java @@ -23,12 +23,12 @@ import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -37,6 +37,8 @@ import java.util.Collection; import java.util.List; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.poi.extractor.ExtractorFactory; +import org.apache.poi.extractor.POITextExtractor; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFOldDocument; import org.apache.poi.hwpf.HWPFTestDataSamples; @@ -798,9 +800,14 @@ class TestBugs { run.replaceText("_TEST_", "This text is longer than the initial text. It goes on and on without interruption."); } - try (FileOutputStream fos = new FileOutputStream(new File("/tmp/test.doc"))) { - doc.write(fos); - } + ByteArrayOutputStream out = new ByteArrayOutputStream(); + doc.write(out); + out.flush(); + + POITextExtractor extractor = ExtractorFactory.createExtractor(new ByteArrayInputStream(out.toByteArray())); + assertThrows(IllegalArgumentException.class, + () -> /*String text =*/ extractor.getText()); + // assertFalse(text.contains("_TEST_"), "Had: " + text); } } }