rearrange unit tests into more, smaller functions

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1722667 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-01-02 21:20:43 +00:00
parent 67d7b4a231
commit d747590977

View File

@ -30,19 +30,24 @@ import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
public class BaseTestSlideShowFactory { public class BaseTestSlideShowFactory {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
public void testFactory(String file, String protectedFile, String password) private static void testFactoryFromFile(String file) throws Exception {
throws Exception {
SlideShow<?,?> ss; SlideShow<?,?> ss;
// from file // from file
ss = SlideShowFactory.create(fromFile(file)); ss = SlideShowFactory.create(fromFile(file));
assertNotNull(ss); assertNotNull(ss);
ss.close(); ss.close();
}
private static void testFactoryFromStream(String file) throws Exception {
SlideShow<?,?> ss;
// from stream // from stream
ss = SlideShowFactory.create(fromStream(file)); ss = SlideShowFactory.create(fromStream(file));
assertNotNull(ss); assertNotNull(ss);
ss.close(); ss.close();
}
private static void testFactoryFromNative(String file) throws Exception {
SlideShow<?,?> ss;
// from NPOIFS // from NPOIFS
if (!file.contains("pptx")) { if (!file.contains("pptx")) {
NPOIFSFileSystem npoifs = new NPOIFSFileSystem(fromFile(file)); NPOIFSFileSystem npoifs = new NPOIFSFileSystem(fromFile(file));
@ -51,17 +56,26 @@ public class BaseTestSlideShowFactory {
npoifs.close(); npoifs.close();
ss.close(); ss.close();
} }
}
private static void testFactoryFromProtectedFile(String protectedFile, String password) throws Exception {
SlideShow<?,?> ss;
// from protected file // from protected file
ss = SlideShowFactory.create(fromFile(protectedFile), password); ss = SlideShowFactory.create(fromFile(protectedFile), password);
assertNotNull(ss); assertNotNull(ss);
ss.close(); ss.close();
}
private static void testFactoryFromProtectedStream(String protectedFile, String password) throws Exception {
SlideShow<?,?> ss;
// from protected stream // from protected stream
ss = SlideShowFactory.create(fromStream(protectedFile), password); ss = SlideShowFactory.create(fromStream(protectedFile), password);
assertNotNull(ss); assertNotNull(ss);
ss.close(); ss.close();
}
private static void testFactoryFromProtectedNative(String protectedFile, String password) throws Exception {
SlideShow<?,?> ss;
// from protected NPOIFS // from protected NPOIFS
NPOIFSFileSystem npoifs = new NPOIFSFileSystem(fromFile(protectedFile)); NPOIFSFileSystem npoifs = new NPOIFSFileSystem(fromFile(protectedFile));
ss = SlideShowFactory.create(npoifs, password); ss = SlideShowFactory.create(npoifs, password);
@ -70,6 +84,17 @@ public class BaseTestSlideShowFactory {
ss.close(); ss.close();
} }
public static void testFactory(String file, String protectedFile, String password)
throws Exception {
testFactoryFromFile(file);
testFactoryFromStream(file);
testFactoryFromNative(file);
testFactoryFromProtectedFile(protectedFile, password);
testFactoryFromProtectedStream(protectedFile, password);
testFactoryFromProtectedNative(protectedFile, password);
}
private static File fromFile(String file) { private static File fromFile(String file) {
return (file.contains("/") || file.contains("\\")) return (file.contains("/") || file.contains("\\"))
? new File(file) ? new File(file)
@ -81,4 +106,5 @@ public class BaseTestSlideShowFactory {
? new FileInputStream(file) ? new FileInputStream(file)
: _slTests.openResourceAsStream(file); : _slTests.openResourceAsStream(file);
} }
} }