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
This commit is contained in:
Josh Micich 2009-12-26 02:17:34 +00:00
parent a1f9d0827c
commit 88dbbbf1c6
38 changed files with 497 additions and 581 deletions

View File

@ -32,9 +32,6 @@ public final class XSSFITestDataProvider implements ITestDataProvider {
private XSSFITestDataProvider() {
// enforce singleton
}
public static XSSFITestDataProvider getInstance(){
return instance;
}
public XSSFWorkbook openSampleWorkbook(String sampleFileName) {
return XSSFTestDataSamples.openSampleWorkbook(sampleFileName);
}

View File

@ -28,9 +28,9 @@ import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
public final class TestXSSFBugs extends BaseTestBugzillaIssues {
@Override
protected XSSFITestDataProvider getTestDataProvider(){
return XSSFITestDataProvider.getInstance();
public TestXSSFBugs() {
super(XSSFITestDataProvider.instance);
}
/**
@ -46,7 +46,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* the wrong sheet name
*/
public void test45430() {
XSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("45430.xlsx");
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("45430.xlsx");
assertFalse(wb.isMacroEnabled());
assertEquals(3, wb.getNumberOfNames());
@ -75,7 +75,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* We should carry vba macros over after save
*/
public void test45431() throws Exception {
XSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("45431.xlsm");
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("45431.xlsm");
OPCPackage pkg = wb.getPackage();
assertTrue(wb.isMacroEnabled());
@ -119,8 +119,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
);
assertNotNull(drw);
}
public void test47504() {
XSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("47504.xlsx");
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47504.xlsx");
assertEquals(1, wb.getNumberOfSheets());
XSSFSheet sh = wb.getSheetAt(0);
XSSFDrawing drawing = sh.createDrawingPatriarch();
@ -136,7 +137,5 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
rels = drawing.getRelations();
assertEquals(1, rels.size());
assertEquals("Sheet1!A1", rels.get(0).getPackageRelationship().getTargetURI().getFragment());
}
}

View File

@ -28,9 +28,9 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
*/
public final class TestXSSFCell extends BaseTestCell {
public TestXSSFCell() {
super(XSSFITestDataProvider.getInstance());
}
public TestXSSFCell() {
super(XSSFITestDataProvider.instance);
}
/**
* Bug 47026: trouble changing cell type when workbook doesn't contain
@ -166,7 +166,7 @@ public final class TestXSSFCell extends BaseTestCell {
//make sure we return null for that instead of throwing OutOfBounds
assertEquals(null, cell.getCellStyle());
}
/**
* Cell with the formula that returns error must return error code(There was
* an problem that cell could not return error value form formula cell).

View File

@ -17,31 +17,12 @@
package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.BaseTestSheet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Workbook;
import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
public class TestXSSFChartSheet extends BaseTestSheet {
@Override
protected XSSFITestDataProvider getTestDataProvider() {
return XSSFITestDataProvider.getInstance();
}
public final class TestXSSFChartSheet extends TestCase {
public void testXSSFFactory() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("chart_sheet.xlsx");
@ -57,6 +38,7 @@ public class TestXSSFChartSheet extends BaseTestSheet {
public void testGetAccessors() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("chart_sheet.xlsx");
XSSFChartSheet sheet = (XSSFChartSheet)wb.getSheetAt(2);
for(Row row : sheet) {
fail("Row iterator for chart sheets should return zero rows");
}
@ -73,12 +55,4 @@ public class TestXSSFChartSheet extends BaseTestSheet {
assertEquals(0, sheet.getColumnBreaks().length);
assertEquals(true, sheet.getRowSumsBelow());
}
/**
* YK: disable failing test from the superclass
*/
@Override
public void testDefaultColumnStyle() {
}
}
}

View File

@ -18,51 +18,26 @@
package org.apache.poi.xssf.usermodel;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.BaseTestCellComment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
import junit.framework.TestCase;
import junit.framework.AssertionFailedError;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
import schemasMicrosoftComVml.CTShape;
public class TestXSSFComment extends BaseTestCellComment {
/**
* @author Yegor Kozlov
*/
public final class TestXSSFComment extends BaseTestCellComment {
private static final String TEST_RICHTEXTSTRING = "test richtextstring";
@Override
protected XSSFITestDataProvider getTestDataProvider(){
return XSSFITestDataProvider.getInstance();
}
/**
* test that we can read cell comments from an existing workbook.
*/
public void testReadComments() {
readComments("SimpleWithComments.xlsx");
}
/**
* test that we can modify existing cell comments
*/
public void testModifyComments() throws IOException {
modifyComments("SimpleWithComments.xlsx");
}
public void testDeleteComments() throws Exception {
deleteComments("SimpleWithComments.xlsx");
public TestXSSFComment() {
super(XSSFITestDataProvider.instance);
}
/**
@ -132,7 +107,7 @@ public class TestXSSFComment extends BaseTestCellComment {
comment.setString(new HSSFRichTextString(TEST_RICHTEXTSTRING));
fail("expected exception");
} catch (IllegalArgumentException e){
;
assertEquals("Only XSSFRichTextString argument is supported", e.getMessage());
}
//simple string argument
@ -189,6 +164,4 @@ public class TestXSSFComment extends BaseTestCellComment {
assertEquals("", comment.getAuthor());
assertEquals(2, sheetComments.getNumberOfAuthors());
}
}

View File

@ -17,25 +17,15 @@
package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.usermodel.BaseTestDataFormat;
import org.apache.poi.xssf.XSSFITestDataProvider;
/**
* Tests for {@link XSSFDataFormat}
*
*/
public final class TestXSSFDataFormat extends BaseTestDataFormat {
@Override
protected ITestDataProvider getTestDataProvider() {
return XSSFITestDataProvider.getInstance();
}
/**
* Test setting and getting boolean values.
*/
public void testBuiltinFormats() {
baseBuiltinFormats();
public TestXSSFDataFormat() {
super(XSSFITestDataProvider.instance);
}
}

View File

@ -34,9 +34,8 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
public final class TestXSSFFont extends BaseTestFont{
@Override
protected XSSFITestDataProvider getTestDataProvider() {
return XSSFITestDataProvider.getInstance();
public TestXSSFFont() {
super(XSSFITestDataProvider.instance);
}
public void testDefaultFont() {

View File

@ -26,9 +26,8 @@ import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
public final class TestXSSFHyperlink extends BaseTestHyperlink {
@Override
protected XSSFITestDataProvider getTestDataProvider() {
return XSSFITestDataProvider.getInstance();
public TestXSSFHyperlink() {
super(XSSFITestDataProvider.instance);
}
@Override
@ -123,7 +122,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
/**
* Only for WithMoreVariousData.xlsx !
*/
private void doTestHyperlinkContents(XSSFSheet sheet) {
private static void doTestHyperlinkContents(XSSFSheet sheet) {
assertNotNull(sheet.getRow(3).getCell(2).getHyperlink());
assertNotNull(sheet.getRow(14).getCell(2).getHyperlink());
assertNotNull(sheet.getRow(15).getCell(2).getHyperlink());

View File

@ -26,16 +26,15 @@ import org.apache.poi.ss.usermodel.BaseTestNamedRange;
*/
public final class TestXSSFName extends BaseTestNamedRange {
@Override
protected XSSFITestDataProvider getTestDataProvider(){
return XSSFITestDataProvider.getInstance();
public TestXSSFName() {
super(XSSFITestDataProvider.instance);
}
//TODO combine testRepeatingRowsAndColums() for HSSF and XSSF
public void testRepeatingRowsAndColums() {
// First test that setting RR&C for same sheet more than once only creates a
// single Print_Titles built-in record
XSSFWorkbook wb = getTestDataProvider().createWorkbook();
XSSFWorkbook wb = new XSSFWorkbook();
wb.createSheet("First Sheet");
wb.setRepeatingRowsAndColumns(0, -1, -1, -1, -1);

View File

@ -31,9 +31,8 @@ import java.util.Arrays;
*/
public final class TestXSSFPicture extends BaseTestPicture {
@Override
protected XSSFITestDataProvider getTestDataProvider(){
return XSSFITestDataProvider.getInstance();
public TestXSSFPicture() {
super(XSSFITestDataProvider.instance);
}
public void testResize() {

View File

@ -26,9 +26,8 @@ import org.apache.poi.xssf.XSSFITestDataProvider;
*/
public final class TestXSSFRow extends BaseTestRow {
@Override
protected XSSFITestDataProvider getTestDataProvider(){
return XSSFITestDataProvider.getInstance();
public TestXSSFRow() {
super(XSSFITestDataProvider.instance);
}
public void testRowBounds() {

View File

@ -33,11 +33,10 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
public class TestXSSFSheet extends BaseTestSheet {
public final class TestXSSFSheet extends BaseTestSheet {
@Override
protected XSSFITestDataProvider getTestDataProvider() {
return XSSFITestDataProvider.getInstance();
public TestXSSFSheet() {
super(XSSFITestDataProvider.instance);
}
//TODO column styles are not yet supported by XSSF
@ -106,7 +105,7 @@ public class TestXSSFSheet extends BaseTestSheet {
}
public void testGetAllHeadersFooters() {
XSSFWorkbook workbook = getTestDataProvider().createWorkbook();
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sheet 1");
assertNotNull(sheet.getOddFooter());
assertNotNull(sheet.getEvenFooter());
@ -780,7 +779,7 @@ public class TestXSSFSheet extends BaseTestSheet {
}
//serialize and check again
wb = getTestDataProvider().writeOutAndReadBack(wb);
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
cols = sheet.getCTWorksheet().getColsArray(0);
assertEquals(5, cols.sizeOfColArray());
@ -850,7 +849,7 @@ public class TestXSSFSheet extends BaseTestSheet {
assertEquals(7, col.getMax());
//serialize and check again
wb = getTestDataProvider().writeOutAndReadBack(wb);
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
assertTrue(sheet.isColumnHidden(2));
assertTrue(sheet.isColumnHidden(6));

View File

@ -35,7 +35,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
public final class TestXSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateArrayFormulas {
public TestXSSFSheetUpdateArrayFormulas() {
super(XSSFITestDataProvider.getInstance());
super(XSSFITestDataProvider.instance);
}
// Test methods common with HSSF are in superclass

View File

@ -36,12 +36,10 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr;
public final class TestXSSFWorkbook extends BaseTestWorkbook {
@Override
protected XSSFITestDataProvider getTestDataProvider(){
return XSSFITestDataProvider.getInstance();
public TestXSSFWorkbook() {
super(XSSFITestDataProvider.instance);
}
/**
* Tests that we can save, and then re-load a new document
*/
@ -232,14 +230,14 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
}
public void testIncrementSheetId() {
XSSFWorkbook wb = getTestDataProvider().createWorkbook();
XSSFWorkbook wb = new XSSFWorkbook();
int sheetId = (int)wb.createSheet().sheet.getSheetId();
assertEquals(1, sheetId);
sheetId = (int)wb.createSheet().sheet.getSheetId();
assertEquals(2, sheetId);
//test file with gaps in the sheetId sequence
wb = getTestDataProvider().openSampleWorkbook("47089.xlsm");
wb = XSSFTestDataSamples.openSampleWorkbook("47089.xlsm");
int lastSheetId = (int)wb.getSheetAt(wb.getNumberOfSheets() - 1).sheet.getSheetId();
sheetId = (int)wb.createSheet().sheet.getSheetId();
assertEquals(lastSheetId+1, sheetId);
@ -305,55 +303,55 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertEquals(crc0.getValue(), crc1.getValue());
}
/**
* When deleting a sheet make sure that we adjust sheet indices of named ranges
*/
public void testBug47737() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47737.xlsx");
assertEquals(2, wb.getNumberOfNames());
assertNotNull(wb.getCalculationChain());
/**
* When deleting a sheet make sure that we adjust sheet indices of named ranges
*/
public void testBug47737() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47737.xlsx");
assertEquals(2, wb.getNumberOfNames());
assertNotNull(wb.getCalculationChain());
XSSFName nm0 = wb.getNameAt(0);
assertTrue(nm0.getCTName().isSetLocalSheetId());
assertEquals(0, nm0.getCTName().getLocalSheetId());
XSSFName nm1 = wb.getNameAt(1);
assertTrue(nm1.getCTName().isSetLocalSheetId());
assertEquals(1, nm1.getCTName().getLocalSheetId());
XSSFName nm0 = wb.getNameAt(0);
assertTrue(nm0.getCTName().isSetLocalSheetId());
assertEquals(0, nm0.getCTName().getLocalSheetId());
wb.removeSheetAt(0);
assertEquals(1, wb.getNumberOfNames());
XSSFName nm2 = wb.getNameAt(0);
assertTrue(nm2.getCTName().isSetLocalSheetId());
assertEquals(0, nm2.getCTName().getLocalSheetId());
//calculation chain is removed as well
assertNull(wb.getCalculationChain());
XSSFName nm1 = wb.getNameAt(1);
assertTrue(nm1.getCTName().isSetLocalSheetId());
assertEquals(1, nm1.getCTName().getLocalSheetId());
}
wb.removeSheetAt(0);
assertEquals(1, wb.getNumberOfNames());
XSSFName nm2 = wb.getNameAt(0);
assertTrue(nm2.getCTName().isSetLocalSheetId());
assertEquals(0, nm2.getCTName().getLocalSheetId());
//calculation chain is removed as well
assertNull(wb.getCalculationChain());
/**
* Problems with XSSFWorkbook.removeSheetAt when workbook contains chart
*/
public void testBug47813() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47813.xlsx");
assertEquals(3, wb.getNumberOfSheets());
assertNotNull(wb.getCalculationChain());
}
assertEquals("Numbers", wb.getSheetName(0));
//the second sheet is of type 'chartsheet'
assertEquals("Chart", wb.getSheetName(1));
assertTrue(wb.getSheetAt(1) instanceof XSSFChartSheet);
assertEquals("SomeJunk", wb.getSheetName(2));
/**
* Problems with XSSFWorkbook.removeSheetAt when workbook contains chart
*/
public void testBug47813() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47813.xlsx");
assertEquals(3, wb.getNumberOfSheets());
assertNotNull(wb.getCalculationChain());
wb.removeSheetAt(2);
assertEquals(2, wb.getNumberOfSheets());
assertNull(wb.getCalculationChain());
assertEquals("Numbers", wb.getSheetName(0));
//the second sheet is of type 'chartsheet'
assertEquals("Chart", wb.getSheetName(1));
assertTrue(wb.getSheetAt(1) instanceof XSSFChartSheet);
assertEquals("SomeJunk", wb.getSheetName(2));
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
assertEquals(2, wb.getNumberOfSheets());
assertNull(wb.getCalculationChain());
wb.removeSheetAt(2);
assertEquals(2, wb.getNumberOfSheets());
assertNull(wb.getCalculationChain());
assertEquals("Numbers", wb.getSheetName(0));
assertEquals("Chart", wb.getSheetName(1));
}
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
assertEquals(2, wb.getNumberOfSheets());
assertNull(wb.getCalculationChain());
assertEquals("Numbers", wb.getSheetName(0));
assertEquals("Chart", wb.getSheetName(1));
}
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);
}
/**

View File

@ -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);

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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() {

View File

@ -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);

View File

@ -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 {
}
}
}
}

View File

@ -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() {

View File

@ -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);

View File

@ -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};

View File

@ -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

View File

@ -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

View File

@ -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("(");

View File

@ -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());
}
}
}

View File

@ -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;
public void baseBuiltinFormats() {
Workbook wb = getTestDataProvider().createWorkbook();
protected BaseTestDataFormat(ITestDataProvider testDataProvider) {
_testDataProvider = testDataProvider;
}
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));
}

View File

@ -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();

View File

@ -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());
}
}
}
}

View File

@ -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;
public void testCreate(){
protected BaseTestNamedRange(ITestDataProvider testDataProvider) {
_testDataProvider = testDataProvider;
}
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());
}
}
}

View File

@ -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();

View File

@ -17,25 +17,26 @@
package org.apache.poi.ss.usermodel;
import junit.framework.TestCase;
import org.apache.poi.ss.ITestDataProvider;
import java.util.Iterator;
import junit.framework.TestCase;
import org.apache.poi.ss.ITestDataProvider;
/**
* A base class for testing implementations of
* {@link org.apache.poi.ss.usermodel.Row}
*/
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);

View File

@ -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));

View File

@ -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");