bug 52949: parameterize fromNPOIFS also

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1738439 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-04-10 14:46:42 +00:00
parent 9f36d6c876
commit f49897de27

View File

@ -24,8 +24,11 @@ import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.Map; import java.util.Map;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
@ -67,16 +70,12 @@ public class TestVBAMacroReader {
} }
@Test @Test
public void fromNPOIFS() throws Exception { public void HSSFfromNPOIFS() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem( fromNPOIFS(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xls");
HSSFTestDataSamples.getSampleFile("SimpleMacro.xls"));
VBAMacroReader r = new VBAMacroReader(fs);
assertMacroContents(r);
r.close();
} }
protected void fromFile(POIDataSamples poiDataSamples, String filename) { protected void fromFile(POIDataSamples poiDataSamples, String filename) throws IOException {
File f = poiDataSamples.getSampleFile(filename); File f = poiDataSamples.getFile(filename);
VBAMacroReader r = new VBAMacroReader(f); VBAMacroReader r = new VBAMacroReader(f);
try { try {
assertMacroContents(r); assertMacroContents(r);
@ -85,8 +84,8 @@ public class TestVBAMacroReader {
} }
} }
protected void fromStream(POIDataSamples poiDataSamples, String filename) { protected void fromStream(POIDataSamples poiDataSamples, String filename) throws IOException {
InputStream fis = poiDataSamples.openSampleFileStream(filename); InputStream fis = poiDataSamples.openResourceAsStream(filename);
try { try {
VBAMacroReader r = new VBAMacroReader(fis); VBAMacroReader r = new VBAMacroReader(fis);
try { try {
@ -94,10 +93,27 @@ public class TestVBAMacroReader {
} finally { } finally {
r.close(); 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<String,String> contents = r.readMacros(); Map<String,String> contents = r.readMacros();
assertFalse(contents.isEmpty()); assertFalse(contents.isEmpty());