From f92495b0a348dcac73199d2bae6ae3eec3585784 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Sun, 10 Apr 2016 14:46:42 +0000 Subject: [PATCH] bug 52949: parameterize fromNPOIFS also git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1738439 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/poifs/macros/TestVBAMacroReader.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java b/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java index f44d249f1d..241e097e2f 100644 --- a/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java +++ b/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java @@ -24,8 +24,11 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileInputStream; +import java.io.InputStream; +import java.io.IOException; import java.util.Map; +import org.apache.poi.POIDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.util.IOUtils; @@ -67,16 +70,12 @@ public class TestVBAMacroReader { } @Test - public void fromNPOIFS() throws Exception { - NPOIFSFileSystem fs = new NPOIFSFileSystem( - HSSFTestDataSamples.getSampleFile("SimpleMacro.xls")); - VBAMacroReader r = new VBAMacroReader(fs); - assertMacroContents(r); - r.close(); + public void HSSFfromNPOIFS() throws Exception { + fromNPOIFS(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xls"); } - protected void fromFile(POIDataSamples poiDataSamples, String filename) { - File f = poiDataSamples.getSampleFile(filename); + protected void fromFile(POIDataSamples poiDataSamples, String filename) throws IOException { + File f = poiDataSamples.getFile(filename); VBAMacroReader r = new VBAMacroReader(f); try { assertMacroContents(r); @@ -85,8 +84,8 @@ public class TestVBAMacroReader { } } - protected void fromStream(POIDataSamples poiDataSamples, String filename) { - InputStream fis = poiDataSamples.openSampleFileStream(filename); + protected void fromStream(POIDataSamples poiDataSamples, String filename) throws IOException { + InputStream fis = poiDataSamples.openResourceAsStream(filename); try { VBAMacroReader r = new VBAMacroReader(fis); try { @@ -94,10 +93,27 @@ public class TestVBAMacroReader { } finally { r.close(); } + } finally { + fis.close(); + } + } + + protected void fromNPOIFS(POIDataSamples poiDataSamples, String filename) throws IOException { + File f = poiDataSamples.getFile(filename); + NPOIFSFileSystem fs = new NPOIFSFileSystem(f); + try { + VBAMacroReader r = new VBAMacroReader(fs); + try { + assertMacroContents(r); + } finally { + r.close(); + } + } finally { + fs.close(); } } - protected void assertMacroContents(VBAMacroReader r) throws Exception { + protected void assertMacroContents(VBAMacroReader r) throws IOException { Map contents = r.readMacros(); assertFalse(contents.isEmpty()); -- 2.39.5