aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-12-26 02:17:34 +0000
committerJosh Micich <josh@apache.org>2009-12-26 02:17:34 +0000
commitfeafcb8f48e24a6b1967e4cbf9e50d8f1b3224fd (patch)
tree9895a650914dded40eefb3f018702376de7301db /src/testcases/org
parent136e09be840acfdf69f77b42725d2c2a6ce1b2f6 (diff)
downloadpoi-feafcb8f48e24a6b1967e4cbf9e50d8f1b3224fd.tar.gz
poi-feafcb8f48e24a6b1967e4cbf9e50d8f1b3224fd.zip
Replaced getInstance methods with field for instances of ITestDataProvider. Some simplification in hierarchy of related tests.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@893929 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
-rw-r--r--src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java3
-rw-r--r--src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java96
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java15
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java25
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java31
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java15
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFont.java5
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java21
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java19
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java5
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java7
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java31
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java2
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java55
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java62
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java42
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java22
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java26
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java17
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java106
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java11
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java57
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java73
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java63
24 files changed, 400 insertions, 409 deletions
diff --git a/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java b/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java
index b4d1b9d86e..668b73b9d6 100644
--- a/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java
+++ b/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java
@@ -32,9 +32,6 @@ public final class HSSFITestDataProvider implements ITestDataProvider {
private HSSFITestDataProvider(){
// enforce singleton
}
- public static HSSFITestDataProvider getInstance(){
- return instance;
- }
public HSSFWorkbook openSampleWorkbook(String sampleFileName) {
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
}
diff --git a/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java b/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java
index 1a1253e343..12097aa3c7 100644
--- a/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java
+++ b/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java
@@ -14,9 +14,11 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hssf.eventmodel;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import junit.framework.TestCase;
@@ -29,69 +31,77 @@ import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-public class TestAbortableListener extends TestCase {
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
- }
-
+/**
+ * Tests for {@link AbortableHSSFListener}
+ */
+public final class TestAbortableListener extends TestCase {
+
+ private POIFSFileSystem openSample() {
+ ByteArrayInputStream is = new ByteArrayInputStream(HSSFITestDataProvider.instance
+ .getTestDataFileContent("SimpleWithColours.xls"));
+ try {
+ return new POIFSFileSystem(is);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
public void testAbortingBasics() throws Exception {
AbortableCountingListener l = new AbortableCountingListener(1000);
-
+
HSSFRequest req = new HSSFRequest();
req.addListenerForAllRecords(l);
-
+
HSSFEventFactory f = new HSSFEventFactory();
-
- assertEquals(0, l.seen);
- assertEquals(null, l.lastseen);
-
- POIFSFileSystem fs = new POIFSFileSystem(new ByteArrayInputStream(
- getTestDataProvider().getTestDataFileContent("SimpleWithColours.xls")
- ));
+
+ assertEquals(0, l.countSeen);
+ assertEquals(null, l.lastRecordSeen);
+
+ POIFSFileSystem fs = openSample();
short res = f.abortableProcessWorkbookEvents(req, fs);
-
+
assertEquals(0, res);
- assertEquals(175, l.seen);
- assertEquals(EOFRecord.sid, l.lastseen.getSid());
+ assertEquals(175, l.countSeen);
+ assertEquals(EOFRecord.sid, l.lastRecordSeen.getSid());
}
-
+
+
public void testAbortStops() throws Exception {
AbortableCountingListener l = new AbortableCountingListener(1);
-
+
HSSFRequest req = new HSSFRequest();
req.addListenerForAllRecords(l);
-
+
HSSFEventFactory f = new HSSFEventFactory();
-
- assertEquals(0, l.seen);
- assertEquals(null, l.lastseen);
-
- POIFSFileSystem fs = new POIFSFileSystem(new ByteArrayInputStream(
- getTestDataProvider().getTestDataFileContent("SimpleWithColours.xls")
- ));
+
+ assertEquals(0, l.countSeen);
+ assertEquals(null, l.lastRecordSeen);
+
+ POIFSFileSystem fs = openSample();
short res = f.abortableProcessWorkbookEvents(req, fs);
-
+
assertEquals(1234, res);
- assertEquals(1, l.seen);
- assertEquals(BOFRecord.sid, l.lastseen.getSid());
+ assertEquals(1, l.countSeen);
+ assertEquals(BOFRecord.sid, l.lastRecordSeen.getSid());
}
-
- public static class AbortableCountingListener extends AbortableHSSFListener {
- private int abortAfter;
- private int seen;
- private Record lastseen;
-
+
+ private static final class AbortableCountingListener extends AbortableHSSFListener {
+ private int abortAfterIndex;
+ public int countSeen;
+ public Record lastRecordSeen;
+
public AbortableCountingListener(int abortAfter) {
- this.abortAfter = abortAfter;
- this.seen = 0;
- this.lastseen = null;
+ abortAfterIndex = abortAfter;
+ countSeen = 0;
+ lastRecordSeen = null;
}
public short abortableProcessRecord(Record record) {
- seen++;
- lastseen = record;
-
- if(seen == abortAfter)
+ countSeen++;
+ lastRecordSeen = record;
+
+ if(countSeen == abortAfterIndex) {
return 1234;
+ }
return 0;
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index c0f639d412..740cd8e599 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -53,17 +53,16 @@ import org.apache.poi.util.TempFile;
*/
public final class TestBugs extends BaseTestBugzillaIssues {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestBugs() {
+ super(HSSFITestDataProvider.instance);
}
- private HSSFWorkbook openSample(String sampleFileName) {
- return getTestDataProvider().openSampleWorkbook(sampleFileName);
+ private static HSSFWorkbook openSample(String sampleFileName) {
+ return HSSFITestDataProvider.instance.openSampleWorkbook(sampleFileName);
}
- private HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
- return getTestDataProvider().writeOutAndReadBack(original);
+ private static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
+ return HSSFITestDataProvider.instance.writeOutAndReadBack(original);
}
private static void writeTestOutputFileForViewing(HSSFWorkbook wb, String simpleFileName) {
@@ -1520,7 +1519,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
assertEquals("test ", cell1.getStringCellValue().toString());
HSSFCell cell2 = s.getRow(0).getCell(1);
- assertEquals(1.0, cell2.getNumericCellValue());
+ assertEquals(1.0, cell2.getNumericCellValue(), 0.0);
}
/**
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
index da22747fc3..77e95c622a 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
@@ -23,6 +23,7 @@ import java.util.GregorianCalendar;
import junit.framework.AssertionFailedError;
import org.apache.poi.hssf.HSSFITestDataProvider;
+import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.InternalSheet;
import org.apache.poi.hssf.record.DBCellRecord;
import org.apache.poi.hssf.record.FormulaRecord;
@@ -41,10 +42,8 @@ import org.apache.poi.ss.usermodel.ErrorConstants;
*/
public final class TestHSSFCell extends BaseTestCell {
- private static final HSSFITestDataProvider _hssfDP = HSSFITestDataProvider.getInstance();
-
public TestHSSFCell() {
- super(HSSFITestDataProvider.getInstance());
+ super(HSSFITestDataProvider.instance);
}
/**
* Checks that the recognition of files using 1904 date windowing
@@ -56,7 +55,7 @@ public final class TestHSSFCell extends BaseTestCell {
Date date = cal.getTime();
// first check a file with 1900 Date Windowing
- HSSFWorkbook workbook = _hssfDP.openSampleWorkbook("1900DateWindowing.xls");
+ HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("1900DateWindowing.xls");
HSSFSheet sheet = workbook.getSheetAt(0);
assertEquals("Date from file using 1900 Date Windowing",
@@ -64,7 +63,7 @@ public final class TestHSSFCell extends BaseTestCell {
sheet.getRow(0).getCell(0).getDateCellValue().getTime());
// now check a file with 1904 Date Windowing
- workbook = _hssfDP.openSampleWorkbook("1904DateWindowing.xls");
+ workbook = HSSFTestDataSamples.openSampleWorkbook("1904DateWindowing.xls");
sheet = workbook.getSheetAt(0);
assertEquals("Date from file using 1904 Date Windowing",
@@ -86,19 +85,19 @@ public final class TestHSSFCell extends BaseTestCell {
// first check a file with 1900 Date Windowing
HSSFWorkbook wb;
- wb = _hssfDP.openSampleWorkbook("1900DateWindowing.xls");
+ wb = HSSFTestDataSamples.openSampleWorkbook("1900DateWindowing.xls");
setCell(wb, 0, 1, date);
- wb = _hssfDP.writeOutAndReadBack(wb);
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
assertEquals("Date from file using 1900 Date Windowing",
date.getTime(),
readCell(wb, 0, 1).getTime());
// now check a file with 1904 Date Windowing
- wb = _hssfDP.openSampleWorkbook("1904DateWindowing.xls");
+ wb = HSSFTestDataSamples.openSampleWorkbook("1904DateWindowing.xls");
setCell(wb, 0, 1, date);
- wb = _hssfDP.writeOutAndReadBack(wb);
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
assertEquals("Date from file using 1900 Date Windowing",
date.getTime(),
readCell(wb, 0, 1).getTime());
@@ -127,7 +126,7 @@ public final class TestHSSFCell extends BaseTestCell {
*/
public void testActiveCell() {
//read in sample
- HSSFWorkbook book = _hssfDP.openSampleWorkbook("Simple.xls");
+ HSSFWorkbook book = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");
//check initial position
HSSFSheet umSheet = book.getSheetAt(0);
@@ -146,7 +145,7 @@ public final class TestHSSFCell extends BaseTestCell {
3, s.getActiveCellRow());
//write book to temp file; read and verify that position is serialized
- book = _hssfDP.writeOutAndReadBack(book);
+ book = HSSFTestDataSamples.writeOutAndReadBack(book);
umSheet = book.getSheetAt(0);
s = umSheet.getSheet();
@@ -162,7 +161,7 @@ public final class TestHSSFCell extends BaseTestCell {
*/
public void testWithHyperlink() {
- HSSFWorkbook wb = _hssfDP.openSampleWorkbook("WithHyperlink.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithHyperlink.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFCell cell = sheet.getRow(4).getCell(0);
@@ -180,7 +179,7 @@ public final class TestHSSFCell extends BaseTestCell {
*/
public void testWithTwoHyperlinks() {
- HSSFWorkbook wb = _hssfDP.openSampleWorkbook("WithTwoHyperLinks.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithTwoHyperLinks.xls");
HSSFSheet sheet = wb.getSheetAt(0);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
index 0130f9471d..7d04110b12 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
@@ -16,10 +16,8 @@
==================================================================== */
package org.apache.poi.hssf.usermodel;
-import java.io.IOException;
-
-import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.HSSFITestDataProvider;
+import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BaseTestCellComment;
/**
@@ -29,39 +27,20 @@ import org.apache.poi.ss.usermodel.BaseTestCellComment;
*/
public final class TestHSSFComment extends BaseTestCellComment {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFComment() {
+ super(HSSFITestDataProvider.instance);
}
- public static void testDefaultShapeType() throws Exception {
+ public void testDefaultShapeType() {
HSSFComment comment = new HSSFComment((HSSFShape)null, (HSSFAnchor)null);
assertEquals(HSSFSimpleShape.OBJECT_TYPE_COMMENT, comment.getShapeType());
}
/**
- * test that we can read cell comments from an existing workbook.
- */
- public void testReadComments() {
- readComments("SimpleWithComments.xls");
- }
-
- /**
- * test that we can modify existing cell comments
- */
- public void testModifyComments() throws IOException {
- modifyComments("SimpleWithComments.xls");
- }
-
- public void testDeleteComments() throws Exception {
- deleteComments("SimpleWithComments.xls");
- }
-
- /**
* HSSFCell#findCellComment should NOT rely on the order of records
* when matching cells and their cell comments. The correct algorithm is to map
*/
- public static void test47924() {
+ public void test47924() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("47924.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFCell cell;
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
index 8bbbc06d50..c04f162205 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
@@ -18,23 +18,14 @@
package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.HSSFITestDataProvider;
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.ss.usermodel.BaseTestDataFormat;
/**
* Tests for {@link HSSFDataFormat}
- *
*/
public final class TestHSSFDataFormat extends BaseTestDataFormat {
- @Override
- protected ITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
- }
- /**
- * Test setting and getting boolean values.
- */
- public void testBuiltinFormats() {
- baseBuiltinFormats();
+ public TestHSSFDataFormat() {
+ super(HSSFITestDataProvider.instance);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFont.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFont.java
index 8350654494..7f0aa7048a 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFont.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFont.java
@@ -28,9 +28,8 @@ import org.apache.poi.ss.usermodel.Font;
*/
public final class TestHSSFFont extends BaseTestFont {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFFont() {
+ super(HSSFITestDataProvider.instance);
}
public void testDefaultFont() {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
index f863dd980d..8a5d601369 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
@@ -28,16 +28,15 @@ import org.apache.poi.ss.usermodel.BaseTestHyperlink;
*/
public final class TestHSSFHyperlink extends BaseTestHyperlink {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFHyperlink() {
+ super(HSSFITestDataProvider.instance);
}
/**
* Test that we can read hyperlinks.
*/
public void testRead() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("HyperlinksOnManySheets.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("HyperlinksOnManySheets.xls");
HSSFSheet sheet;
HSSFCell cell;
@@ -77,7 +76,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
}
public void testModify() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("HyperlinksOnManySheets.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("HyperlinksOnManySheets.xls");
HSSFSheet sheet;
HSSFCell cell;
@@ -89,7 +88,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
//modify the link
link.setAddress("www.apache.org");
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
sheet = wb.getSheet("WebLinks");
cell = sheet.getRow(4).getCell(0);
link = cell.getHyperlink();
@@ -106,7 +105,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
* link.setAddress("'Target Sheet-1'!A1"); //common between XSSF and HSSF
*/
public void testCreateDocumentLink() {
- HSSFWorkbook wb = getTestDataProvider().createWorkbook();
+ HSSFWorkbook wb = new HSSFWorkbook();
//link to a place in this workbook
HSSFHyperlink link;
@@ -131,7 +130,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
link.setAddress("'Hyperlinks'!A1");
cell.setHyperlink(link);
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
sheet = wb.getSheet("Hyperlinks");
cell = sheet.getRow(0).getCell(0);
@@ -167,7 +166,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
}
public void testCreate() {
- HSSFWorkbook wb = getTestDataProvider().createWorkbook();
+ HSSFWorkbook wb = new HSSFWorkbook();
HSSFHyperlink link;
HSSFCell cell;
@@ -179,7 +178,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
link.setAddress("testfolder\\test.PDF");
cell.setHyperlink(link);
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
sheet = wb.getSheet("Hyperlinks");
cell = sheet.getRow(1).getCell(0);
@@ -193,7 +192,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
* see bugs #46445 and #29957
*/
public void testShiftRows(){
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("46445.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("46445.xls");
HSSFSheet sheet = wb.getSheetAt(0);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
index 88a2c0cf16..6d45cde4f0 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
@@ -45,7 +45,7 @@ public final class TestHSSFName extends BaseTestNamedRange {
* For manipulating the internals of {@link HSSFName} during testing.<br/>
* Some tests need a {@link NameRecord} with unusual state, not normally producible by POI.
* This method achieves the aims at low cost without augmenting the POI usermodel api.
- * @return a reference to the wrapped {@link NameRecord}
+ * @return a reference to the wrapped {@link NameRecord}
*/
public static NameRecord getNameRecord(HSSFName definedName) {
@@ -63,11 +63,10 @@ public final class TestHSSFName extends BaseTestNamedRange {
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
- }
+ }
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFName() {
+ super(HSSFITestDataProvider.instance);
}
public void testRepeatingRowsAndColumsNames() {
@@ -128,7 +127,7 @@ public final class TestHSSFName extends BaseTestNamedRange {
}
public void testNamedRange() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("Simple.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");
//Creating new Named Range
HSSFName newNamedRange = wb.createName();
@@ -162,7 +161,7 @@ public final class TestHSSFName extends BaseTestNamedRange {
* Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=9632" target="_bug">#9632</a>
*/
public void testNamedRead() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("namedinput.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("namedinput.xls");
//Get index of the named range with the name = "NamedRangeName" , which was defined in input.xls as A1:D10
int NamedRangeIndex = wb.getNameIndex("NamedRangeName");
@@ -188,7 +187,7 @@ public final class TestHSSFName extends BaseTestNamedRange {
* Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=16411" target="_bug">#16411</a>
*/
public void testNamedReadModify() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("namedinput.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("namedinput.xls");
HSSFName name = wb.getNameAt(0);
String sheetName = wb.getSheetName(0);
@@ -206,7 +205,7 @@ public final class TestHSSFName extends BaseTestNamedRange {
* Test to see if the print area can be retrieved from an excel created file
*/
public void testPrintAreaFileRead() {
- HSSFWorkbook workbook = getTestDataProvider().openSampleWorkbook("SimpleWithPrintArea.xls");
+ HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPrintArea.xls");
String sheetName = workbook.getSheetName(0);
String reference = sheetName+"!$A$1:$C$5";
@@ -252,4 +251,4 @@ public final class TestHSSFName extends BaseTestNamedRange {
}
}
-} \ No newline at end of file
+}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
index 8f39857694..9e51917a5f 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
@@ -28,9 +28,8 @@ import org.apache.poi.ss.usermodel.BaseTestPicture;
*/
public final class TestHSSFPicture extends BaseTestPicture {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFPicture() {
+ super(HSSFITestDataProvider.instance);
}
public void testResize() {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
index 31173bba2a..55ee037042 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
@@ -32,9 +32,8 @@ import org.apache.poi.ss.SpreadsheetVersion;
*/
public final class TestHSSFRow extends BaseTestRow {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFRow() {
+ super(HSSFITestDataProvider.instance);
}
public void testRowBounds() {
@@ -56,7 +55,7 @@ public final class TestHSSFRow extends BaseTestRow {
BlankRecord br = new BlankRecord();
br.setRow(ROW_IX);
- br.setColumn((short)COL_IX);
+ br.setColumn((short)COL_IX);
sheet.getSheet().addValueRecord(ROW_IX, br);
HSSFRow row = new HSSFRow(workbook, sheet, rowRec);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
index 1dc6e1ac18..09fdc73b8e 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
@@ -20,7 +20,6 @@ package org.apache.poi.hssf.usermodel;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.util.Arrays;
import junit.framework.AssertionFailedError;
@@ -43,9 +42,6 @@ import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
import org.apache.poi.ss.usermodel.BaseTestSheet;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.TempFile;
@@ -59,9 +55,8 @@ import org.apache.poi.util.TempFile;
*/
public final class TestHSSFSheet extends BaseTestSheet {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFSheet() {
+ super(HSSFITestDataProvider.instance);
}
public void testTestGetSetMargin() {
@@ -161,7 +156,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
* Setting landscape and portrait stuff on existing sheets
*/
public void testPrintSetupLandscapeExisting() {
- HSSFWorkbook workbook = getTestDataProvider().openSampleWorkbook("SimpleWithPageBreaks.xls");
+ HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls");
assertEquals(3, workbook.getNumberOfSheets());
@@ -242,7 +237,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
}
public void testGroupRowsExisting() {
- HSSFWorkbook workbook = getTestDataProvider().openSampleWorkbook("NoGutsRecords.xls");
+ HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("NoGutsRecords.xls");
HSSFSheet s = workbook.getSheetAt(0);
HSSFRow r1 = s.getRow(0);
@@ -293,8 +288,8 @@ public final class TestHSSFSheet extends BaseTestSheet {
}
public void testGetDrawings() {
- HSSFWorkbook wb1c = getTestDataProvider().openSampleWorkbook("WithChart.xls");
- HSSFWorkbook wb2c = getTestDataProvider().openSampleWorkbook("WithTwoCharts.xls");
+ HSSFWorkbook wb1c = HSSFTestDataSamples.openSampleWorkbook("WithChart.xls");
+ HSSFWorkbook wb2c = HSSFTestDataSamples.openSampleWorkbook("WithTwoCharts.xls");
// 1 chart sheet -> data on 1st, chart on 2nd
assertNotNull(wb1c.getSheetAt(0).getDrawingPatriarch());
@@ -438,7 +433,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
*
*/
public void testPageBreakFiles() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("SimpleWithPageBreaks.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls");
HSSFSheet sheet = wb.getSheetAt(0);
assertNotNull(sheet);
@@ -466,7 +461,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
}
public void testDBCSName () {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("DBCSSheetName.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DBCSSheetName.xls");
wb.getSheetAt(1);
assertEquals ("DBCS Sheet Name 2", wb.getSheetName(1),"\u090f\u0915" );
assertEquals("DBCS Sheet Name 1", wb.getSheetName(0),"\u091c\u093e");
@@ -478,7 +473,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
* of the sheet when it is first opened.
*/
public void testTopRow() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("SimpleWithPageBreaks.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls");
HSSFSheet sheet = wb.getSheetAt(0);
assertNotNull(sheet);
@@ -519,7 +514,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
//try adding empty rows in an existing worksheet
- workbook = getTestDataProvider().openSampleWorkbook("Simple.xls");
+ workbook = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");
sheet = workbook.getSheetAt(0);
for (int i = 3; i < 10; i++) sheet.createRow(i);
@@ -528,7 +523,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
}
public void testAutoSizeColumn() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("43902.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("43902.xls");
String sheetName = "my sheet";
HSSFSheet sheet = wb.getSheet(sheetName);
@@ -572,7 +567,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
* Setting ForceFormulaRecalculation on sheets
*/
public void testForceRecalculation() throws Exception {
- HSSFWorkbook workbook = getTestDataProvider().openSampleWorkbook("UncalcedRecord.xls");
+ HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("UncalcedRecord.xls");
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFSheet sheet2 = workbook.getSheetAt(0);
@@ -640,7 +635,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
public void testColumnWidth() {
//check we can correctly read column widths from a reference workbook
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("colwidth.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("colwidth.xls");
//reference values
int[] ref = {365, 548, 731, 914, 1097, 1280, 1462, 1645, 1828, 2011, 2194, 2377, 2560, 2742, 2925, 3108, 3291, 3474, 3657};
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java
index 625ffdb694..eff7157eb6 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java
@@ -40,7 +40,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
public final class TestHSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateArrayFormulas {
public TestHSSFSheetUpdateArrayFormulas() {
- super(HSSFITestDataProvider.getInstance());
+ super(HSSFITestDataProvider.instance);
}
// Test methods common with XSSF are in superclass
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
index 43fc595ff2..6493eef47f 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
@@ -44,16 +44,15 @@ import org.apache.poi.hpsf.ClassID;
* Tests for {@link HSSFWorkbook}
*/
public final class TestHSSFWorkbook extends BaseTestWorkbook {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFWorkbook() {
+ super(HSSFITestDataProvider.instance);
}
/**
* gives test code access to the {@link InternalWorkbook} within {@link HSSFWorkbook}
*/
public static InternalWorkbook getInternalWorkbook(HSSFWorkbook wb) {
- return wb.getWorkbook();
+ return wb.getWorkbook();
}
public void testSetRepeatingRowsAndColumns() {
@@ -81,28 +80,28 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
* Tests for {@link HSSFWorkbook#isHidden()} etc
*/
public void testHidden() {
- HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFWorkbook wb = new HSSFWorkbook();
- WindowOneRecord w1 = wb.getWorkbook().getWindowOne();
+ WindowOneRecord w1 = wb.getWorkbook().getWindowOne();
- assertEquals(false, wb.isHidden());
- assertEquals(false, w1.getHidden());
+ assertEquals(false, wb.isHidden());
+ assertEquals(false, w1.getHidden());
- wb.setHidden(true);
- assertEquals(true, wb.isHidden());
- assertEquals(true, w1.getHidden());
+ wb.setHidden(true);
+ assertEquals(true, wb.isHidden());
+ assertEquals(true, w1.getHidden());
- wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
- w1 = wb.getWorkbook().getWindowOne();
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ w1 = wb.getWorkbook().getWindowOne();
- wb.setHidden(true);
- assertEquals(true, wb.isHidden());
- assertEquals(true, w1.getHidden());
+ wb.setHidden(true);
+ assertEquals(true, wb.isHidden());
+ assertEquals(true, w1.getHidden());
- wb.setHidden(false);
- assertEquals(false, wb.isHidden());
- assertEquals(false, w1.getHidden());
- }
+ wb.setHidden(false);
+ assertEquals(false, wb.isHidden());
+ assertEquals(false, w1.getHidden());
+ }
public void testSheetClone() {
// First up, try a simple file
@@ -116,7 +115,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertEquals(3, b.getNumberOfSheets());
// Now try a problem one with drawing records in it
- b = getTestDataProvider().openSampleWorkbook("SheetWithDrawing.xls");
+ b = HSSFTestDataSamples.openSampleWorkbook("SheetWithDrawing.xls");
assertEquals(1, b.getNumberOfSheets());
b.cloneSheet(0);
assertEquals(2, b.getNumberOfSheets());
@@ -127,7 +126,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
HSSFSheet s;
// Single chart, two sheets
- b = getTestDataProvider().openSampleWorkbook("44010-SingleChart.xls");
+ b = HSSFTestDataSamples.openSampleWorkbook("44010-SingleChart.xls");
assertEquals(2, b.getNumberOfSheets());
assertEquals("Graph2", b.getSheetName(1));
s = b.getSheetAt(1);
@@ -143,9 +142,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
// We've now called getDrawingPatriarch() so
// everything will be all screwy
// So, start again
- b = getTestDataProvider().openSampleWorkbook("44010-SingleChart.xls");
+ b = HSSFTestDataSamples.openSampleWorkbook("44010-SingleChart.xls");
- b = getTestDataProvider().writeOutAndReadBack(b);
+ b = HSSFTestDataSamples.writeOutAndReadBack(b);
assertEquals(2, b.getNumberOfSheets());
s = b.getSheetAt(1);
assertEquals(0, s.getFirstRowNum());
@@ -153,7 +152,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
// Two charts, three sheets
- b = getTestDataProvider().openSampleWorkbook("44010-TwoCharts.xls");
+ b = HSSFTestDataSamples.openSampleWorkbook("44010-TwoCharts.xls");
assertEquals(3, b.getNumberOfSheets());
s = b.getSheetAt(1);
@@ -173,9 +172,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
// We've now called getDrawingPatriarch() so
// everything will be all screwy
// So, start again
- b = getTestDataProvider().openSampleWorkbook("44010-TwoCharts.xls");
+ b = HSSFTestDataSamples.openSampleWorkbook("44010-TwoCharts.xls");
- b = getTestDataProvider().writeOutAndReadBack(b);
+ b = HSSFTestDataSamples.writeOutAndReadBack(b);
assertEquals(3, b.getNumberOfSheets());
s = b.getSheetAt(1);
@@ -375,7 +374,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
* that point to deleted sheets
*/
public void testNamesToDeleteSheets() {
- HSSFWorkbook b = getTestDataProvider().openSampleWorkbook("30978-deleted.xls");
+ HSSFWorkbook b = HSSFTestDataSamples.openSampleWorkbook("30978-deleted.xls");
assertEquals(3, b.getNumberOfNames());
// Sheet 2 is deleted
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
index b81be5b405..5636f918e3 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
@@ -18,6 +18,7 @@
package org.apache.poi.ss.usermodel;
import junit.framework.TestCase;
+
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellRangeAddress;
@@ -29,23 +30,26 @@ import org.apache.poi.ss.util.CellRangeAddress;
*/
public abstract class BaseTestBugzillaIssues extends TestCase {
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
+
+ protected BaseTestBugzillaIssues(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
/**
- *
* Test writing a hyperlink
* Open resulting sheet in Excel and check that A1 contains a hyperlink
*
* Also tests bug 15353 (problems with hyperlinks to Google)
*/
- public void test23094() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void test23094() {
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet();
Row r = s.createRow(0);
r.createCell(0).setCellFormula("HYPERLINK(\"http://jakarta.apache.org\",\"Jakarta\")");
r.createCell(1).setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
r = wb.getSheetAt(0).getRow(0);
Cell cell_0 = r.getCell(0);
@@ -60,7 +64,7 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
* @param num the number of strings to generate
*/
public void baseTest15375(int num) {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
CreationHelper factory = wb.getCreationHelper();
@@ -82,7 +86,7 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
cell = row.createCell(2);
cell.setCellValue(factory.createRichTextString(tmp3));
}
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
for (int i = 0; i < num; i++) {
tmp1 = "Test1" + i;
tmp2 = "Test2" + i;
@@ -99,8 +103,8 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
/**
* Merged regions were being removed from the parent in cloned sheets
*/
- public void test22720() {
- Workbook workBook = getTestDataProvider().createWorkbook();
+ public final void test22720() {
+ Workbook workBook = _testDataProvider.createWorkbook();
workBook.createSheet("TEST");
Sheet template = workBook.getSheetAt(0);
@@ -126,8 +130,8 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
}
- public void test28031() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void test28031() {
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
wb.setSheetName(0, "Sheet1");
@@ -138,7 +142,7 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
cell.setCellFormula(formulaText);
assertEquals(formulaText, cell.getCellFormula());
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
cell = wb.getSheetAt(0).getRow(0).getCell(0);
assertEquals("IF(ROUND(A2*B2*C2,2)>ROUND(B2*D2,2),ROUND(A2*B2*C2,2),ROUND(B2*D2,2))", cell.getCellFormula());
}
@@ -148,24 +152,24 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
* that contains macros and this formula:
* {=SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""))>0,1))}
*/
- public void test21334() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void test21334() {
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sh = wb.createSheet();
Cell cell = sh.createRow(0).createCell(0);
String formula = "SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"))>0,1))";
cell.setCellFormula(formula);
- Workbook wb_sv = getTestDataProvider().writeOutAndReadBack(wb);
+ Workbook wb_sv = _testDataProvider.writeOutAndReadBack(wb);
Cell cell_sv = wb_sv.getSheetAt(0).getRow(0).getCell(0);
assertEquals(formula, cell_sv.getCellFormula());
}
/** another test for the number of unique strings issue
*test opening the resulting file in Excel*/
- public void test22568() {
+ public final void test22568() {
int r=2000;int c=3;
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet("ExcelTest") ;
int col_cnt=0, rw_cnt=0 ;
@@ -191,7 +195,7 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
sheet.setDefaultColumnWidth(18) ;
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
rw = sheet.getRow(0);
//Header row
@@ -211,21 +215,21 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
/**
* Bug 42448: Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69
*/
- public void test42448(){
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void test42448(){
+ Workbook wb = _testDataProvider.createWorkbook();
Cell cell = wb.createSheet().createRow(0).createCell(0);
cell.setCellFormula("SUMPRODUCT(A!C7:A!C67, B8:B68) / B69");
assertTrue("no errors parsing formula", true);
}
- public void test18800() {
- Workbook book = getTestDataProvider().createWorkbook();
+ public final void test18800() {
+ Workbook book = _testDataProvider.createWorkbook();
book.createSheet("TEST");
Sheet sheet = book.cloneSheet(0);
book.setSheetName(1,"CLONE");
sheet.createRow(0).createCell(0).setCellValue("Test");
- book = getTestDataProvider().writeOutAndReadBack(book);
+ book = _testDataProvider.writeOutAndReadBack(book);
sheet = book.getSheet("CLONE");
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
@@ -246,8 +250,8 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
}
}
- public void testBug43093() {
- Workbook xlw = getTestDataProvider().createWorkbook();
+ public final void testBug43093() {
+ Workbook xlw = _testDataProvider.createWorkbook();
addNewSheetWithCellsA1toD4(xlw, 1);
addNewSheetWithCellsA1toD4(xlw, 2);
@@ -265,11 +269,11 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
assertEquals(d, (311+312+321+322), 0.0000001);
}
- public void testMaxFunctionArguments_bug46729(){
+ public final void testMaxFunctionArguments_bug46729(){
String[] func = {"COUNT", "AVERAGE", "MAX", "MIN", "OR", "SUBTOTAL", "SKEW"};
- SpreadsheetVersion ssVersion = getTestDataProvider().getSpreadsheetVersion();
- Workbook wb = getTestDataProvider().createWorkbook();
+ SpreadsheetVersion ssVersion = _testDataProvider.getSpreadsheetVersion();
+ Workbook wb = _testDataProvider.createWorkbook();
Cell cell = wb.createSheet().createRow(0).createCell(0);
String fmla;
@@ -291,7 +295,7 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
}
}
- private String createFunction(String name, int maxArgs){
+ private static String createFunction(String name, int maxArgs){
StringBuffer fmla = new StringBuffer();
fmla.append(name);
fmla.append("(");
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java
index f55767115d..7289cef635 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java
@@ -22,15 +22,19 @@ import junit.framework.TestCase;
import org.apache.poi.ss.ITestDataProvider;
/**
- * Common superclass for testing implementatiosn of
+ * Common superclass for testing implementations of
* {@link Comment}
*/
public abstract class BaseTestCellComment extends TestCase {
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
+
+ protected BaseTestCellComment(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
public final void testFind() {
- Workbook book = getTestDataProvider().createWorkbook();
+ Workbook book = _testDataProvider.createWorkbook();
Sheet sheet = book.createSheet();
assertNull(sheet.getCellComment(0, 0));
@@ -40,14 +44,14 @@ public abstract class BaseTestCellComment extends TestCase {
assertNull(cell.getCellComment());
}
- public final void testCreate() throws Exception {
+ public final void testCreate() {
String cellText = "Hello, World";
String commentText = "We can set comments in POI";
String commentAuthor = "Apache Software Foundation";
int cellRow = 3;
int cellColumn = 1;
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
CreationHelper factory = wb.getCreationHelper();
Sheet sheet = wb.createSheet();
@@ -81,7 +85,7 @@ public abstract class BaseTestCellComment extends TestCase {
assertEquals(cellRow, comment.getRow());
assertEquals(cellColumn, comment.getColumn());
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
cell = sheet.getRow(cellRow).getCell(cellColumn);
comment = cell.getCellComment();
@@ -97,7 +101,7 @@ public abstract class BaseTestCellComment extends TestCase {
comment.setString(factory.createRichTextString("New Comment Text"));
comment.setVisible(false);
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
cell = sheet.getRow(cellRow).getCell(cellColumn);
@@ -114,9 +118,9 @@ public abstract class BaseTestCellComment extends TestCase {
/**
* test that we can read cell comments from an existing workbook.
*/
- public void readComments(String sampleFile) {
+ public final void testReadComments() {
- Workbook wb = getTestDataProvider().openSampleWorkbook(sampleFile);
+ Workbook wb = _testDataProvider.openSampleWorkbook("SimpleWithComments." + _testDataProvider.getStandardFileNameExtension());
Sheet sheet = wb.getSheetAt(0);
@@ -150,9 +154,9 @@ public abstract class BaseTestCellComment extends TestCase {
/**
* test that we can modify existing cell comments
*/
- public void modifyComments(String sampleFile) {
+ public final void testModifyComments() {
- Workbook wb = getTestDataProvider().openSampleWorkbook(sampleFile);
+ Workbook wb = _testDataProvider.openSampleWorkbook("SimpleWithComments." + _testDataProvider.getStandardFileNameExtension());
CreationHelper factory = wb.getCreationHelper();
Sheet sheet = wb.getSheetAt(0);
@@ -169,7 +173,7 @@ public abstract class BaseTestCellComment extends TestCase {
comment.setString(factory.createRichTextString("Modified comment at row " + rownum));
}
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
for (int rownum = 0; rownum < 3; rownum++) {
@@ -180,11 +184,10 @@ public abstract class BaseTestCellComment extends TestCase {
assertEquals("Mofified[" + rownum + "] by Yegor", comment.getAuthor());
assertEquals("Modified comment at row " + rownum, comment.getString().getString());
}
-
}
- public void deleteComments(String sampleFile) throws Exception {
- Workbook wb = getTestDataProvider().openSampleWorkbook(sampleFile);
+ public final void testDeleteComments() {
+ Workbook wb = _testDataProvider.openSampleWorkbook("SimpleWithComments." + _testDataProvider.getStandardFileNameExtension());
Sheet sheet = wb.getSheetAt(0);
// Zap from rows 1 and 3
@@ -201,20 +204,19 @@ public abstract class BaseTestCellComment extends TestCase {
assertNull(sheet.getRow(2).getCell(1).getCellComment());
// Save and re-load
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
// Check
assertNull(sheet.getRow(0).getCell(1).getCellComment());
assertNotNull(sheet.getRow(1).getCell(1).getCellComment());
assertNull(sheet.getRow(2).getCell(1).getCellComment());
-
}
/**
* code from the quick guide
*/
public void testQuickGuide(){
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
CreationHelper factory = wb.getCreationHelper();
@@ -233,7 +235,7 @@ public abstract class BaseTestCellComment extends TestCase {
//assign the comment to the cell
cell.setCellComment(comment);
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
cell = sheet.getRow(3).getCell(5);
comment = cell.getCellComment();
@@ -243,4 +245,4 @@ public abstract class BaseTestCellComment extends TestCase {
assertEquals(3, comment.getRow());
assertEquals(5, comment.getColumn());
}
-} \ No newline at end of file
+}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java
index b1c21dd373..46f8204f11 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java
@@ -17,9 +17,8 @@
package org.apache.poi.ss.usermodel;
-import java.util.Map;
-
import junit.framework.TestCase;
+
import org.apache.poi.ss.ITestDataProvider;
/**
@@ -28,19 +27,20 @@ import org.apache.poi.ss.ITestDataProvider;
*/
public abstract class BaseTestDataFormat extends TestCase {
- /**
- * @return an object that provides test data in HSSF / XSSF specific way
- */
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
+
+ protected BaseTestDataFormat(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
- public void baseBuiltinFormats() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testBuiltinFormats() {
+ Workbook wb = _testDataProvider.createWorkbook();
DataFormat df = wb.createDataFormat();
- Map<Integer, String> formats = BuiltinFormats.getBuiltinFormats();
- for (int idx : formats.keySet()) {
- String fmt = formats.get(Integer.valueOf(idx));
+ String[] formats = BuiltinFormats.getAll();
+ for (int idx = 0; idx < formats.length; idx++) {
+ String fmt = formats[idx];
assertEquals(idx, df.getFormat(fmt));
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java
index d5c8e21683..187599e314 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java
@@ -26,11 +26,15 @@ import org.apache.poi.ss.ITestDataProvider;
*/
public abstract class BaseTestFont extends TestCase {
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
- public void baseTestDefaultFont(String defaultName, short defaultSize, short defaultColor){
+ protected BaseTestFont(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
+
+ protected final void baseTestDefaultFont(String defaultName, short defaultSize, short defaultColor){
//get default font and check against default value
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Font fontFind=workbook.findFont(Font.BOLDWEIGHT_NORMAL, defaultColor, defaultSize, defaultName, false, false, Font.SS_NONE, Font.U_NONE);
assertNotNull(fontFind);
@@ -47,8 +51,8 @@ public abstract class BaseTestFont extends TestCase {
assertNotNull(fontFind);
}
- public void testGetNumberOfFonts(){
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testGetNumberOfFonts(){
+ Workbook wb = _testDataProvider.createWorkbook();
int num0 = wb.getNumberOfFonts();
Font f1=wb.createFont();
@@ -76,8 +80,8 @@ public abstract class BaseTestFont extends TestCase {
* Tests that we can define fonts to a new
* file, save, load, and still see them
*/
- public void testCreateSave() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testCreateSave() {
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet s1 = wb.createSheet();
Row r1 = s1.createRow(0);
Cell r1c1 = r1.createCell(0);
@@ -99,7 +103,7 @@ public abstract class BaseTestFont extends TestCase {
r1c1.setCellStyle(cellStyleTitle);
// Save and re-load
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
s1 = wb.getSheetAt(0);
assertEquals(num0 + 1, wb.getNumberOfFonts());
@@ -118,7 +122,7 @@ public abstract class BaseTestFont extends TestCase {
assertEquals(num0 + 2, wb.getNumberOfFonts());
// Save and re-load
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
s1 = wb.getSheetAt(0);
assertEquals(num0 + 2, wb.getNumberOfFonts());
@@ -134,8 +138,8 @@ public abstract class BaseTestFont extends TestCase {
*
* @see org.apache.poi.hssf.usermodel.TestBugs#test45338()
*/
- public void test45338() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void test45338() {
+ Workbook wb = _testDataProvider.createWorkbook();
int num0 = wb.getNumberOfFonts();
Sheet s = wb.createSheet();
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java
index ae71841f71..833e5aab9a 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java
@@ -19,6 +19,7 @@ package org.apache.poi.ss.usermodel;
import junit.framework.TestCase;
+import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.ss.ITestDataProvider;
/**
@@ -28,10 +29,14 @@ import org.apache.poi.ss.ITestDataProvider;
*/
public abstract class BaseTestHyperlink extends TestCase {
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
- public void testBasicTypes(){
- Workbook wb = getTestDataProvider().createWorkbook();
+ protected BaseTestHyperlink(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
+
+ public final void testBasicTypes(){
+ Workbook wb = _testDataProvider.createWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Cell cell;
@@ -72,7 +77,7 @@ public abstract class BaseTestHyperlink extends TestCase {
link.setAddress("'Target Sheet'!A1");
cell.setHyperlink(link);
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
link = sheet.getRow(0).getCell(0).getHyperlink();
@@ -84,5 +89,5 @@ public abstract class BaseTestHyperlink extends TestCase {
assertEquals("mailto:poi@apache.org?subject=Hyperlinks", link.getAddress());
link = sheet.getRow(3).getCell(0).getHyperlink();
assertEquals("'Target Sheet'!A1", link.getAddress());
- }
-} \ No newline at end of file
+ }
+}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
index 08ce49b97d..a8b3760626 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
@@ -32,14 +32,15 @@ import org.apache.poi.ss.util.CellReference;
*/
public abstract class BaseTestNamedRange extends TestCase {
- /**
- * @return an object that provides test data in HSSF / XSSF specific way
- */
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
+
+ protected BaseTestNamedRange(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
- public void testCreate(){
+ public final void testCreate(){
// Create a new workbook
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet1 = wb.createSheet("Test1");
Sheet sheet2 = wb.createSheet("Testing Named Ranges");
@@ -99,28 +100,27 @@ public abstract class BaseTestNamedRange extends TestCase {
fail("should have thrown exceptiuon due to invalid name: " + name);
} catch (IllegalArgumentException e) {
// expected during successful test
- ;
}
}
}
- public void testUnicodeNamedRange() {
- Workbook workBook = getTestDataProvider().createWorkbook();
+ public final void testUnicodeNamedRange() {
+ Workbook workBook = _testDataProvider.createWorkbook();
workBook.createSheet("Test");
Name name = workBook.createName();
name.setNameName("\u03B1");
name.setRefersToFormula("Test!$D$3:$E$8");
- Workbook workBook2 = getTestDataProvider().writeOutAndReadBack(workBook);
+ Workbook workBook2 = _testDataProvider.writeOutAndReadBack(workBook);
Name name2 = workBook2.getNameAt(0);
assertEquals("\u03B1", name2.getNameName());
assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
}
- public void testAddRemove() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testAddRemove() {
+ Workbook wb = _testDataProvider.createWorkbook();
assertEquals(0, wb.getNumberOfNames());
Name name1 = wb.createName();
name1.setNameName("name1");
@@ -141,8 +141,8 @@ public abstract class BaseTestNamedRange extends TestCase {
assertEquals(1, wb.getNumberOfNames());
}
- public void testScope() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testScope() {
+ Workbook wb = _testDataProvider.createWorkbook();
wb.createSheet();
wb.createSheet();
@@ -194,10 +194,10 @@ public abstract class BaseTestNamedRange extends TestCase {
* <p>
* Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=13775" target="_bug">#13775</a>
*/
- public void testMultiNamedRange() {
+ public final void testMultiNamedRange() {
// Create a new workbook
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
// Create a worksheet 'sheet1' in the new workbook
wb.createSheet ();
@@ -227,7 +227,7 @@ public abstract class BaseTestNamedRange extends TestCase {
// Write the workbook to a file
// Read the Excel file and verify its content
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
Name nm1 =wb.getNameAt(wb.getNameIndex("RangeTest1"));
assertTrue("Name is "+nm1.getNameName(),"RangeTest1".equals(nm1.getNameName()));
assertTrue("Reference is "+nm1.getRefersToFormula(),(wb.getSheetName(0)+"!$A$1:$L$41").equals(nm1.getRefersToFormula()));
@@ -240,8 +240,8 @@ public abstract class BaseTestNamedRange extends TestCase {
/**
* Test to see if the print areas can be retrieved/created in memory
*/
- public void testSinglePrintArea() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testSinglePrintArea() {
+ Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
String sheetName = workbook.getSheetName(0);
@@ -257,9 +257,9 @@ public abstract class BaseTestNamedRange extends TestCase {
/**
* For Convenience, don't force sheet names to be used
*/
- public void testSinglePrintAreaWOSheet()
+ public final void testSinglePrintAreaWOSheet()
{
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
String sheetName = workbook.getSheetName(0);
@@ -275,8 +275,8 @@ public abstract class BaseTestNamedRange extends TestCase {
/**
* Test to see if the print area made it to the file
*/
- public void testPrintAreaFile() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testPrintAreaFile() {
+ Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
String sheetName = workbook.getSheetName(0);
@@ -284,7 +284,7 @@ public abstract class BaseTestNamedRange extends TestCase {
String reference = "$A$1:$B$1";
workbook.setPrintArea(0, reference);
- workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+ workbook = _testDataProvider.writeOutAndReadBack(workbook);
String retrievedPrintArea = workbook.getPrintArea(0);
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
@@ -294,8 +294,8 @@ public abstract class BaseTestNamedRange extends TestCase {
/**
* Test to see if multiple print areas made it to the file
*/
- public void testMultiplePrintAreaFile() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testMultiplePrintAreaFile() {
+ Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Sheet1");
workbook.createSheet("Sheet2");
@@ -324,7 +324,7 @@ public abstract class BaseTestNamedRange extends TestCase {
assertEquals("Sheet3!" + reference3, retrievedPrintArea);
// Check print areas after re-reading workbook
- workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+ workbook = _testDataProvider.writeOutAndReadBack(workbook);
retrievedPrintArea = workbook.getPrintArea(0);
assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
@@ -343,8 +343,8 @@ public abstract class BaseTestNamedRange extends TestCase {
* Tests the setting of print areas with coordinates (Row/Column designations)
*
*/
- public void testPrintAreaCoords(){
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testPrintAreaCoords(){
+ Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
String sheetName = workbook.getSheetName(0);
@@ -361,8 +361,8 @@ public abstract class BaseTestNamedRange extends TestCase {
* Tests the parsing of union area expressions, and re-display in the presence of sheet names
* with special characters.
*/
- public void testPrintAreaUnion(){
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testPrintAreaUnion(){
+ Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
String reference = "$A$1:$B$1,$D$1:$F$2";
@@ -376,8 +376,8 @@ public abstract class BaseTestNamedRange extends TestCase {
* Verifies an existing print area is deleted
*
*/
- public void testPrintAreaRemove() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testPrintAreaRemove() {
+ Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
workbook.getSheetName(0);
@@ -394,8 +394,8 @@ public abstract class BaseTestNamedRange extends TestCase {
/**
* Test that multiple named ranges can be added written and read
*/
- public void testMultipleNamedWrite() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testMultipleNamedWrite() {
+ Workbook wb = _testDataProvider.createWorkbook();
wb.createSheet("testSheet1");
@@ -417,7 +417,7 @@ public abstract class BaseTestNamedRange extends TestCase {
wb.getNameAt(0);
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
Name nm =wb.getNameAt(wb.getNameIndex("RangeTest"));
assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
assertTrue("Reference is "+nm.getRefersToFormula(),(wb.getSheetName(0)+"!$D$4:$E$8").equals(nm.getRefersToFormula()));
@@ -429,13 +429,13 @@ public abstract class BaseTestNamedRange extends TestCase {
/**
* Verifies correct functioning for "single cell named range" (aka "named cell")
*/
- public void testNamedCell_1() {
+ public final void testNamedCell_1() {
// setup for this testcase
String sheetName = "Test Named Cell";
String cellName = "named_cell";
String cellValue = "TEST Value";
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet(sheetName);
CreationHelper factory = wb.getCreationHelper();
sheet.createRow(0).createCell(0).setCellValue(factory.createRichTextString(cellValue));
@@ -468,11 +468,11 @@ public abstract class BaseTestNamedRange extends TestCase {
/**
* Verifies correct functioning for "single cell named range" (aka "named cell")
*/
- public void testNamedCell_2() {
+ public final void testNamedCell_2() {
// setup for this testcase
String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
CreationHelper factory = wb.getCreationHelper();
Sheet sheet = wb.createSheet(sname);
sheet.createRow(0).createCell(0).setCellValue(factory.createRichTextString(cvalue));
@@ -498,25 +498,25 @@ public abstract class BaseTestNamedRange extends TestCase {
assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
}
-
+
/**
- * Bugzilla attachment 23444 (from bug 46973) has a NAME record with the following encoding:
+ * Bugzilla attachment 23444 (from bug 46973) has a NAME record with the following encoding:
* <pre>
* 00000000 | 18 00 17 00 00 00 00 08 00 00 00 00 00 00 00 00 | ................
* 00000010 | 00 00 00 55 50 53 53 74 61 74 65 | ...UPSState
- * </pre>
- *
+ * </pre>
+ *
* This caused trouble for anything that requires {@link HSSFName#getRefersToFormula()}
* It is easy enough to re-create the the same data (by not setting the formula). Excel
* seems to gracefully remove this uninitialized name record. It would be nice if POI
- * could do the same, but that would involve adjusting subsequent name indexes across
+ * could do the same, but that would involve adjusting subsequent name indexes across
* all formulas. <p/>
- *
- * For the moment, POI has been made to behave more sensibly with uninitialised name
+ *
+ * For the moment, POI has been made to behave more sensibly with uninitialised name
* records.
*/
public final void testUninitialisedNameGetRefersToFormula_bug46973() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Name n = wb.createName();
n.setNameName("UPSState");
String formula;
@@ -532,8 +532,8 @@ public abstract class BaseTestNamedRange extends TestCase {
assertFalse(n.isDeleted()); // according to exact definition of isDeleted()
}
- public void testDeletedCell() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testDeletedCell() {
+ Workbook wb = _testDataProvider.createWorkbook();
Name n = wb.createName();
n.setNameName("MyName");
// contrived example to expose bug:
@@ -545,8 +545,8 @@ public abstract class BaseTestNamedRange extends TestCase {
}
- public void testFunctionNames() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testFunctionNames() {
+ Workbook wb = _testDataProvider.createWorkbook();
Name n = wb.createName();
assertFalse(n.isFunctionName());
@@ -559,4 +559,4 @@ public abstract class BaseTestNamedRange extends TestCase {
n.setFunction(false);
assertFalse(n.isFunctionName());
}
-} \ No newline at end of file
+}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
index 27f949d89c..b19513759d 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
@@ -18,6 +18,7 @@
package org.apache.poi.ss.usermodel;
import junit.framework.TestCase;
+
import org.apache.poi.ss.ITestDataProvider;
/**
@@ -25,15 +26,19 @@ import org.apache.poi.ss.ITestDataProvider;
*/
public abstract class BaseTestPicture extends TestCase {
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
+
+ protected BaseTestPicture(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
public void baseTestResize(ClientAnchor referenceAnchor) {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sh1 = wb.createSheet();
Drawing p1 = sh1.createDrawingPatriarch();
CreationHelper factory = wb.getCreationHelper();
- byte[] pictureData = getTestDataProvider().getTestDataFileContent("logoKarmokar4.png");
+ byte[] pictureData = _testDataProvider.getTestDataFileContent("logoKarmokar4.png");
int idx1 = wb.addPicture( pictureData, Workbook.PICTURE_TYPE_PNG );
Picture picture = p1.createPicture(factory.createClientAnchor(), idx1);
picture.resize();
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
index aa37dcc2a7..a229804a09 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
@@ -17,10 +17,11 @@
package org.apache.poi.ss.usermodel;
+import java.util.Iterator;
+
import junit.framework.TestCase;
-import org.apache.poi.ss.ITestDataProvider;
-import java.util.Iterator;
+import org.apache.poi.ss.ITestDataProvider;
/**
* A base class for testing implementations of
@@ -28,14 +29,14 @@ import java.util.Iterator;
*/
public abstract class BaseTestRow extends TestCase {
- /**
- * @return an object that provides test data in / XSSF specific way
- */
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
+ protected BaseTestRow(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
- public void testLastAndFirstColumns() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testLastAndFirstColumns() {
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);
assertEquals(-1, row.getFirstCellNum());
@@ -62,8 +63,8 @@ public abstract class BaseTestRow extends TestCase {
* Make sure that there is no cross-talk between rows especially with getFirstCellNum and getLastCellNum
* This test was added in response to bug report 44987.
*/
- public void testBoundsInMultipleRows() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testBoundsInMultipleRows() {
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
Row rowA = sheet.createRow(0);
@@ -86,8 +87,8 @@ public abstract class BaseTestRow extends TestCase {
assertEquals(31, rowB.getLastCellNum());
}
- public void testRemoveCell() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testRemoveCell() {
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);
@@ -112,7 +113,7 @@ public abstract class BaseTestRow extends TestCase {
assertEquals(-1, row.getFirstCellNum());
assertEquals(0, row.getPhysicalNumberOfCells());
- workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+ workbook = _testDataProvider.writeOutAndReadBack(workbook);
sheet = workbook.getSheetAt(0);
row = sheet.getRow(0);
assertEquals(-1, row.getLastCellNum());
@@ -121,7 +122,7 @@ public abstract class BaseTestRow extends TestCase {
}
public void baseTestRowBounds(int maxRowNum) {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
//Test low row bound
sheet.createRow(0);
@@ -147,13 +148,13 @@ public abstract class BaseTestRow extends TestCase {
}
public void baseTestCellBounds(int maxCellNum) {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);
//Test low cell bound
try {
- Cell cell = row.createCell(-1);
+ row.createCell(-1);
fail("expected exception");
} catch (IllegalArgumentException e) {
// expected during successful test
@@ -162,17 +163,17 @@ public abstract class BaseTestRow extends TestCase {
//Test high cell bound
try {
- Cell cell = row.createCell(maxCellNum + 1);
+ row.createCell(maxCellNum + 1);
fail("expected exception");
} catch (IllegalArgumentException e) {
// expected during successful test
assertTrue(e.getMessage().startsWith("Invalid column index ("+(maxCellNum+1)+")"));
}
for(int i=0; i < maxCellNum; i++){
- Cell cell = row.createCell(i);
+ row.createCell(i);
}
assertEquals(maxCellNum, row.getPhysicalNumberOfCells());
- workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+ workbook = _testDataProvider.writeOutAndReadBack(workbook);
sheet = workbook.getSheetAt(0);
row = sheet.getRow(0);
assertEquals(maxCellNum, row.getPhysicalNumberOfCells());
@@ -187,8 +188,8 @@ public abstract class BaseTestRow extends TestCase {
* Prior to patch 43901, POI was producing files with the wrong last-column
* number on the row
*/
- public void testLastCellNumIsCorrectAfterAddCell_bug43901(){
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testLastCellNumIsCorrectAfterAddCell_bug43901(){
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet("test");
Row row = sheet.createRow(0);
@@ -209,8 +210,8 @@ public abstract class BaseTestRow extends TestCase {
/**
* Tests for the missing/blank cell policy stuff
*/
- public void testGetCellPolicy() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testGetCellPolicy() {
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet("test");
Row row = sheet.createRow(0);
@@ -278,8 +279,8 @@ public abstract class BaseTestRow extends TestCase {
assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5).getCellType());
}
- public void testRowHeight() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testRowHeight() {
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
Row row1 = sheet.createRow(0);
@@ -305,7 +306,7 @@ public abstract class BaseTestRow extends TestCase {
row4.setZeroHeight(true);
assertTrue(row4.getZeroHeight());
- workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+ workbook = _testDataProvider.writeOutAndReadBack(workbook);
sheet = workbook.getSheetAt(0);
row1 = sheet.getRow(0);
@@ -330,8 +331,8 @@ public abstract class BaseTestRow extends TestCase {
/**
* Test adding cells to a row in various places and see if we can find them again.
*/
- public void testCellIterator() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testCellIterator() {
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
index 2a81023ed5..7613da4d87 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
@@ -17,26 +17,28 @@
package org.apache.poi.ss.usermodel;
+import java.util.Iterator;
+
import junit.framework.TestCase;
+
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellRangeAddress;
-import java.util.Iterator;
-
/**
* Common superclass for testing {@link org.apache.poi.xssf.usermodel.XSSFCell} and
* {@link org.apache.poi.hssf.usermodel.HSSFCell}
*/
public abstract class BaseTestSheet extends TestCase {
- /**
- * @return an object that provides test data in HSSF / XSSF specific way
- */
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
+
+ protected BaseTestSheet(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
public void testCreateRow() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
assertEquals(0, sheet.getPhysicalNumberOfRows());
@@ -76,7 +78,7 @@ public abstract class BaseTestSheet extends TestCase {
public void testRemoveRow() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet1 = workbook.createSheet();
assertEquals(0, sheet1.getPhysicalNumberOfRows());
assertEquals(0, sheet1.getFirstRowNum());
@@ -117,7 +119,7 @@ public abstract class BaseTestSheet extends TestCase {
}
public void testCloneSheet() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
CreationHelper factory = workbook.getCreationHelper();
Sheet sheet = workbook.createSheet("Test Clone");
Row row = sheet.createRow(0);
@@ -149,7 +151,7 @@ public abstract class BaseTestSheet extends TestCase {
* BUG 37416
*/
public void testCloneSheetMultipleTimes() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
CreationHelper factory = workbook.getCreationHelper();
Sheet sheet = workbook.createSheet("Test Clone");
Row row = sheet.createRow(0);
@@ -176,7 +178,7 @@ public abstract class BaseTestSheet extends TestCase {
* Setting landscape and portrait stuff on new sheets
*/
public void testPrintSetupLandscapeNew() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheetL = workbook.createSheet("LandscapeS");
Sheet sheetP = workbook.createSheet("LandscapeP");
@@ -197,7 +199,7 @@ public abstract class BaseTestSheet extends TestCase {
assertEquals(3, sheetP.getPrintSetup().getCopies());
// Save and re-load, and check still there
- workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+ workbook = _testDataProvider.writeOutAndReadBack(workbook);
sheetL = workbook.getSheet("LandscapeS");
sheetP = workbook.getSheet("LandscapeP");
@@ -213,10 +215,10 @@ public abstract class BaseTestSheet extends TestCase {
*
*/
public void testAddMerged() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
assertEquals(0, sheet.getNumMergedRegions());
- SpreadsheetVersion ssVersion = getTestDataProvider().getSpreadsheetVersion();
+ SpreadsheetVersion ssVersion = _testDataProvider.getSpreadsheetVersion();
CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1);
sheet.addMergedRegion(region);
@@ -227,24 +229,23 @@ public abstract class BaseTestSheet extends TestCase {
sheet.addMergedRegion(region);
fail("Expected exception");
} catch (IllegalArgumentException e){
- ;
+// TODO assertEquals("Minimum row number is 0.", e.getMessage());
}
try {
region = new CellRangeAddress(0, 0, 0, ssVersion.getLastColumnIndex() + 1);
sheet.addMergedRegion(region);
fail("Expected exception");
} catch (IllegalArgumentException e){
- ;
+ assertEquals("Maximum column number is " + ssVersion.getLastColumnIndex(), e.getMessage());
}
try {
region = new CellRangeAddress(0, ssVersion.getLastRowIndex() + 1, 0, 1);
sheet.addMergedRegion(region);
fail("Expected exception");
} catch (IllegalArgumentException e){
- ;
+ assertEquals("Maximum row number is " + ssVersion.getLastRowIndex(), e.getMessage());
}
assertEquals(1, sheet.getNumMergedRegions());
-
}
/**
@@ -252,7 +253,7 @@ public abstract class BaseTestSheet extends TestCase {
*
*/
public void testRemoveMerged() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1);
sheet.addMergedRegion(region);
@@ -286,7 +287,7 @@ public abstract class BaseTestSheet extends TestCase {
}
public void testShiftMerged() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
CreationHelper factory = wb.getCreationHelper();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
@@ -311,7 +312,7 @@ public abstract class BaseTestSheet extends TestCase {
* @author Shawn Laubach (slaubach at apache dot org)
*/
public void testDisplayOptions() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
assertEquals(sheet.isDisplayGridlines(), true);
@@ -324,7 +325,7 @@ public abstract class BaseTestSheet extends TestCase {
sheet.setDisplayFormulas(true);
sheet.setDisplayZeros(false);
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
assertEquals(sheet.isDisplayGridlines(), false);
@@ -334,7 +335,7 @@ public abstract class BaseTestSheet extends TestCase {
}
public void testColumnWidth() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
//default column width measured in characters
@@ -376,7 +377,7 @@ public abstract class BaseTestSheet extends TestCase {
}
//serialize and read again
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
assertEquals(20, sheet.getDefaultColumnWidth());
@@ -393,7 +394,7 @@ public abstract class BaseTestSheet extends TestCase {
}
public void testDefaultRowHeight() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
sheet.setDefaultRowHeightInPoints(15);
assertEquals((short) 300, sheet.getDefaultRowHeight());
@@ -417,7 +418,7 @@ public abstract class BaseTestSheet extends TestCase {
/** cell with formula becomes null on cloning a sheet*/
public void test35084() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet("Sheet1");
Row r = s.createRow(0);
r.createCell(0).setCellValue(1);
@@ -431,7 +432,7 @@ public abstract class BaseTestSheet extends TestCase {
/** test that new default column styles get applied */
public void testDefaultColumnStyle() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
CellStyle style = wb.createCellStyle();
Sheet sheet = wb.createSheet();
sheet.setDefaultColumnStyle(0, style);
@@ -446,7 +447,7 @@ public abstract class BaseTestSheet extends TestCase {
}
public void testOutlineProperties() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
@@ -466,7 +467,7 @@ public abstract class BaseTestSheet extends TestCase {
assertTrue(sheet.getRowSumsBelow());
assertTrue(sheet.getRowSumsRight());
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
assertTrue(sheet.getRowSumsBelow());
assertTrue(sheet.getRowSumsRight());
@@ -476,7 +477,7 @@ public abstract class BaseTestSheet extends TestCase {
* Test basic display properties
*/
public void testSheetProperties() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
assertFalse(sheet.getHorizontallyCenter());
@@ -535,7 +536,7 @@ public abstract class BaseTestSheet extends TestCase {
double marginHeader = defaultMargins[4];
double marginFooter = defaultMargins[5];
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet("Sheet 1");
assertEquals(marginLeft, sheet.getMargin(Sheet.LeftMargin), 0.0);
sheet.setMargin(Sheet.LeftMargin, 10.0);
@@ -561,7 +562,7 @@ public abstract class BaseTestSheet extends TestCase {
}
public void testRowBreaks() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
//Sheet#getRowBreaks() returns an empty array if no row breaks are defined
assertNotNull(sheet.getRowBreaks());
@@ -589,7 +590,7 @@ public abstract class BaseTestSheet extends TestCase {
}
public void testColumnBreaks() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
assertNotNull(sheet.getColumnBreaks());
assertEquals(0, sheet.getColumnBreaks().length);
@@ -616,7 +617,7 @@ public abstract class BaseTestSheet extends TestCase {
}
public void testGetFirstLastRowNum() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet("Sheet 1");
sheet.createRow(9);
sheet.createRow(0);
@@ -626,7 +627,7 @@ public abstract class BaseTestSheet extends TestCase {
}
public void testGetFooter() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet("Sheet 1");
assertNotNull(sheet.getFooter());
sheet.getFooter().setCenter("test center footer");
@@ -634,7 +635,7 @@ public abstract class BaseTestSheet extends TestCase {
}
public void testGetSetColumnHidden() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet("Sheet 1");
sheet.setColumnHidden(2, true);
assertTrue(sheet.isColumnHidden(2));
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
index 1c99f96748..c963f6eccc 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
@@ -17,8 +17,9 @@
package org.apache.poi.ss.usermodel;
-import junit.framework.TestCase;
import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellRangeAddress;
@@ -27,10 +28,14 @@ import org.apache.poi.ss.util.CellRangeAddress;
*/
public abstract class BaseTestWorkbook extends TestCase {
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
- public void testCreateSheet() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ protected BaseTestWorkbook(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
+
+ public final void testCreateSheet() {
+ Workbook wb = _testDataProvider.createWorkbook();
assertEquals(0, wb.getNumberOfSheets());
//getting a sheet by invalid index or non-existing name
@@ -87,7 +92,7 @@ public abstract class BaseTestWorkbook extends TestCase {
wb.setSheetName(1, "[I'm invalid]");
fail("should have thrown exceptiuon due to invalid sheet name");
} catch (IllegalArgumentException e) {
- ; // expected during successful test
+ // expected during successful test
}
//check
@@ -101,15 +106,15 @@ public abstract class BaseTestWorkbook extends TestCase {
assertNull(wb.getSheet("unknown"));
//serialize and read again
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
assertEquals(3, wb.getNumberOfSheets());
assertEquals(0, wb.getSheetIndex("sheet0"));
assertEquals(1, wb.getSheetIndex("sheet1"));
assertEquals(2, wb.getSheetIndex("I changed!"));
}
- public void testRemoveSheetAt() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testRemoveSheetAt() {
+ Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("sheet1");
workbook.createSheet("sheet2");
workbook.createSheet("sheet3");
@@ -130,16 +135,16 @@ public abstract class BaseTestWorkbook extends TestCase {
assertEquals(3, workbook.getNumberOfSheets());
}
- public void testDefaultValues() {
- Workbook b = getTestDataProvider().createWorkbook();
+ public final void testDefaultValues() {
+ Workbook b = _testDataProvider.createWorkbook();
assertEquals(0, b.getActiveSheetIndex());
assertEquals(0, b.getFirstVisibleTab());
assertEquals(0, b.getNumberOfNames());
assertEquals(0, b.getNumberOfSheets());
}
- public void testSheetSelection() {
- Workbook b = getTestDataProvider().createWorkbook();
+ public final void testSheetSelection() {
+ Workbook b = _testDataProvider.createWorkbook();
b.createSheet("Sheet One");
b.createSheet("Sheet Two");
b.setActiveSheet(1);
@@ -149,8 +154,8 @@ public abstract class BaseTestWorkbook extends TestCase {
assertEquals(1, b.getFirstVisibleTab());
}
- public void testPrintArea() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testPrintArea() {
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet1 = workbook.createSheet("Test Print Area");
String sheetName1 = sheet1.getSheetName();
@@ -168,8 +173,8 @@ public abstract class BaseTestWorkbook extends TestCase {
assertNull(workbook.getPrintArea(0));
}
- public void testGetSetActiveSheet(){
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testGetSetActiveSheet(){
+ Workbook workbook = _testDataProvider.createWorkbook();
assertEquals(0, workbook.getActiveSheetIndex());
workbook.createSheet("sheet1");
@@ -185,8 +190,8 @@ public abstract class BaseTestWorkbook extends TestCase {
assertEquals(0, workbook.getActiveSheetIndex());
}
- public void testSetSheetOrder() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testSetSheetOrder() {
+ Workbook wb = _testDataProvider.createWorkbook();
for (int i=0; i < 10; i++) {
wb.createSheet("Sheet " + i);
@@ -221,7 +226,7 @@ public abstract class BaseTestWorkbook extends TestCase {
assertEquals(8, wb.getSheetIndex("Sheet 9"));
assertEquals(9, wb.getSheetIndex("Sheet 1"));
- Workbook wbr = getTestDataProvider().writeOutAndReadBack(wb);
+ Workbook wbr = _testDataProvider.writeOutAndReadBack(wb);
assertEquals(0, wbr.getSheetIndex("Sheet 6"));
assertEquals(1, wbr.getSheetIndex("Sheet 0"));
@@ -241,8 +246,8 @@ public abstract class BaseTestWorkbook extends TestCase {
}
}
- public void testCloneSheet() {
- Workbook book = getTestDataProvider().createWorkbook();
+ public final void testCloneSheet() {
+ Workbook book = _testDataProvider.createWorkbook();
Sheet sheet = book.createSheet("TEST");
sheet.createRow(0).createCell(0).setCellValue("Test");
sheet.createRow(1).createCell(0).setCellValue(36.6);
@@ -269,8 +274,8 @@ public abstract class BaseTestWorkbook extends TestCase {
}
- public void testParentReferences(){
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testParentReferences(){
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
assertSame(workbook, sheet.getWorkbook());
@@ -281,7 +286,7 @@ public abstract class BaseTestWorkbook extends TestCase {
assertSame(sheet, cell.getSheet());
assertSame(row, cell.getRow());
- workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+ workbook = _testDataProvider.writeOutAndReadBack(workbook);
sheet = workbook.getSheetAt(0);
assertSame(workbook, sheet.getWorkbook());
@@ -293,8 +298,8 @@ public abstract class BaseTestWorkbook extends TestCase {
assertSame(row, cell.getRow());
}
- public void testSetRepeatingRowsAnsColumns(){
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testSetRepeatingRowsAnsColumns(){
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet1 = wb.createSheet();
wb.setRepeatingRowsAndColumns(wb.getSheetIndex(sheet1), 0, 0, 0, 3);
@@ -306,8 +311,8 @@ public abstract class BaseTestWorkbook extends TestCase {
/**
* Tests that all of the unicode capable string fields can be set, written and then read back
*/
- public void testUnicodeInAll() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testUnicodeInAll() {
+ Workbook wb = _testDataProvider.createWorkbook();
CreationHelper factory = wb.getCreationHelper();
//Create a unicode dataformat (contains euro symbol)
DataFormat df = wb.createDataFormat();
@@ -341,7 +346,7 @@ public abstract class BaseTestWorkbook extends TestCase {
String formulaString = "TEXT(12.34,\"\u20ac###,##\")";
c3.setCellFormula(formulaString);
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
//Test the sheetname
s = wb.getSheet("\u20ac");