From bf756d96784b527c3cb77d455d9f0c322311d091 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Mon, 7 Apr 2008 03:02:03 +0000 Subject: refactored all hssf junits to get test sample data in the in one place git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@645348 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/eventusermodel/TestHSSFEventFactory.java | 101 ++++++++++----------- .../TestMissingRecordAwareHSSFListener.java | 7 +- 2 files changed, 54 insertions(+), 54 deletions(-) (limited to 'src/testcases/org/apache/poi/hssf/eventusermodel') diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java index 049b43ef93..74e1ceb4a5 100644 --- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java +++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java @@ -16,109 +16,108 @@ ==================================================================== */ package org.apache.poi.hssf.eventusermodel; -import org.apache.poi.hssf.eventusermodel.HSSFEventFactory; -import org.apache.poi.hssf.eventusermodel.HSSFListener; - -import java.io.File; -import java.io.FileInputStream; +import java.io.InputStream; import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; +import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.record.ContinueRecord; import org.apache.poi.hssf.record.DVALRecord; import org.apache.poi.hssf.record.DVRecord; import org.apache.poi.hssf.record.EOFRecord; import org.apache.poi.hssf.record.Record; -import org.apache.poi.hssf.record.ContinueRecord; import org.apache.poi.hssf.record.SelectionRecord; import org.apache.poi.hssf.record.WindowTwoRecord; import org.apache.poi.poifs.filesystem.POIFSFileSystem; - -import junit.framework.TestCase; - -public class TestHSSFEventFactory extends TestCase { - private String dirname; +/** + * + */ +public final class TestHSSFEventFactory extends TestCase { - public TestHSSFEventFactory() { - dirname = System.getProperty("HSSF.testdata.path"); + private static final InputStream openSample(String sampleFileName) { + return HSSFTestDataSamples.openSampleFileStream(sampleFileName); } public void testWithMissingRecords() throws Exception { - File f = new File(dirname + "/SimpleWithSkip.xls"); HSSFRequest req = new HSSFRequest(); MockHSSFListener mockListen = new MockHSSFListener(); req.addListenerForAllRecords(mockListen); - POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(f)); + POIFSFileSystem fs = new POIFSFileSystem(openSample("SimpleWithSkip.xls")); HSSFEventFactory factory = new HSSFEventFactory(); factory.processWorkbookEvents(req, fs); + Record[] recs = mockListen.getRecords(); // Check we got the records - System.out.println("Processed, found " + mockListen.records.size() + " records"); - assertTrue( mockListen.records.size() > 100 ); + assertTrue( recs.length > 100 ); // Check that the last few records are as we expect // (Makes sure we don't accidently skip the end ones) - int numRec = mockListen.records.size(); - assertEquals(WindowTwoRecord.class, mockListen.records.get(numRec-3).getClass()); - assertEquals(SelectionRecord.class, mockListen.records.get(numRec-2).getClass()); - assertEquals(EOFRecord.class, mockListen.records.get(numRec-1).getClass()); + int numRec = recs.length; + assertEquals(WindowTwoRecord.class, recs[numRec-3].getClass()); + assertEquals(SelectionRecord.class, recs[numRec-2].getClass()); + assertEquals(EOFRecord.class, recs[numRec-1].getClass()); } public void testWithCrazyContinueRecords() throws Exception { // Some files have crazy ordering of their continue records // Check that we don't break on them (bug #42844) - - File f = new File(dirname + "/ContinueRecordProblem.xls"); HSSFRequest req = new HSSFRequest(); MockHSSFListener mockListen = new MockHSSFListener(); req.addListenerForAllRecords(mockListen); - POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(f)); + POIFSFileSystem fs = new POIFSFileSystem(openSample("ContinueRecordProblem.xls")); HSSFEventFactory factory = new HSSFEventFactory(); factory.processWorkbookEvents(req, fs); + Record[] recs = mockListen.getRecords(); // Check we got the records - System.out.println("Processed, found " + mockListen.records.size() + " records"); - assertTrue( mockListen.records.size() > 100 ); + assertTrue( recs.length > 100 ); // And none of them are continue ones - Record[] r = (Record[])mockListen.records.toArray( - new Record[mockListen.records.size()] ); - for(int i=0; i