aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2008-04-07 03:02:03 +0000
committerJosh Micich <josh@apache.org>2008-04-07 03:02:03 +0000
commitbf756d96784b527c3cb77d455d9f0c322311d091 (patch)
tree08b9b03e4820164076827a8cbd0de2aca09275bf /src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
parentb938b6c97f47f085757b330d1bce90293c863afb (diff)
downloadpoi-bf756d96784b527c3cb77d455d9f0c322311d091.tar.gz
poi-bf756d96784b527c3cb77d455d9f0c322311d091.zip
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
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java')
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java72
1 files changed, 25 insertions, 47 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
index 1be3a90855..3696bb940e 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
@@ -14,28 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.poi.hssf.usermodel;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
+import junit.framework.TestCase;
-import junit.framework.*;
+import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.NameRecord;
+/**
+ *
+ */
+public final class TestHSSFWorkbook extends TestCase {
+ private static HSSFWorkbook openSample(String sampleFileName) {
+ return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
+ }
-public class TestHSSFWorkbook extends TestCase
-{
- HSSFWorkbook hssfWorkbook;
- String filename;
-
- protected void setUp() throws Exception {
- super.setUp();
- filename = System.getProperty("HSSF.testdata.path");
- }
-
- public void testSetRepeatingRowsAndColumns() throws Exception
- {
+ public void testSetRepeatingRowsAndColumns() {
// Test bug 29747
HSSFWorkbook b = new HSSFWorkbook( );
b.createSheet();
@@ -46,9 +40,7 @@ public class TestHSSFWorkbook extends TestCase
assertEquals( 3, nameRecord.getIndexToSheet() );
}
- public void testDuplicateNames()
- throws Exception
- {
+ public void testDuplicateNames() {
HSSFWorkbook b = new HSSFWorkbook( );
b.createSheet("Sheet1");
b.createSheet();
@@ -105,15 +97,15 @@ public class TestHSSFWorkbook extends TestCase
public void testSheetSelection() {
HSSFWorkbook b = new HSSFWorkbook();
b.createSheet("Sheet One");
- HSSFSheet s = b.createSheet("Sheet Two");
+ b.createSheet("Sheet Two");
b.setSelectedTab((short) 1);
b.setDisplayedTab((short) 1);
assertEquals(b.getSelectedTab(), 1);
assertEquals(b.getDisplayedTab(), 1);
}
- public void testSheetClone() throws Exception {
- // First up, try a simple file
+ public void testSheetClone() {
+ // First up, try a simple file
HSSFWorkbook b = new HSSFWorkbook();
assertEquals(0, b.getNumberOfSheets());
b.createSheet("Sheet One");
@@ -122,24 +114,20 @@ public class TestHSSFWorkbook extends TestCase
assertEquals(2, b.getNumberOfSheets());
b.cloneSheet(0);
assertEquals(3, b.getNumberOfSheets());
-
- // Now try a problem one with drawing records in it
- b = new HSSFWorkbook(
- new FileInputStream(new File(filename,"SheetWithDrawing.xls"))
- );
+
+ // Now try a problem one with drawing records in it
+ b = openSample("SheetWithDrawing.xls");
assertEquals(1, b.getNumberOfSheets());
b.cloneSheet(0);
assertEquals(2, b.getNumberOfSheets());
}
- public void testReadWriteWithCharts() throws Exception {
+ public void testReadWriteWithCharts() {
HSSFWorkbook b;
HSSFSheet s;
// Single chart, two sheets
- b = new HSSFWorkbook(
- new FileInputStream(new File(filename,"44010-SingleChart.xls"))
- );
+ b = openSample("44010-SingleChart.xls");
assertEquals(2, b.getNumberOfSheets());
s = b.getSheetAt(1);
assertEquals(0, s.getFirstRowNum());
@@ -154,9 +142,7 @@ public class TestHSSFWorkbook extends TestCase
// We've now called getDrawingPatriarch() so
// everything will be all screwy
// So, start again
- b = new HSSFWorkbook(
- new FileInputStream(new File(filename,"44010-SingleChart.xls"))
- );
+ b = openSample("44010-SingleChart.xls");
b = writeRead(b);
assertEquals(2, b.getNumberOfSheets());
@@ -166,9 +152,7 @@ public class TestHSSFWorkbook extends TestCase
// Two charts, three sheets
- b = new HSSFWorkbook(
- new FileInputStream(new File(filename,"44010-TwoCharts.xls"))
- );
+ b = openSample("44010-TwoCharts.xls");
assertEquals(3, b.getNumberOfSheets());
s = b.getSheetAt(1);
@@ -188,9 +172,7 @@ public class TestHSSFWorkbook extends TestCase
// We've now called getDrawingPatriarch() so
// everything will be all screwy
// So, start again
- b = new HSSFWorkbook(
- new FileInputStream(new File(filename,"44010-TwoCharts.xls"))
- );
+ b = openSample("44010-TwoCharts.xls");
b = writeRead(b);
assertEquals(3, b.getNumberOfSheets());
@@ -203,11 +185,7 @@ public class TestHSSFWorkbook extends TestCase
assertEquals(0, s.getLastRowNum());
}
- private HSSFWorkbook writeRead(HSSFWorkbook b) throws Exception {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- b.write(baos);
- return new HSSFWorkbook(
- new ByteArrayInputStream(baos.toByteArray())
- );
+ private static HSSFWorkbook writeRead(HSSFWorkbook b) {
+ return HSSFTestDataSamples.writeOutAndReadBack(b);
}
} \ No newline at end of file