* Addresses Bug #13775 */ - 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: *
* 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 - *- * + * + * * 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. - * - * For the moment, POI has been made to behave more sensibly with uninitialised name + * + * For the moment, POI has been made to behave more sensibly with uninitialised name * records. */ public final void testUninitialisedNameGetRefersToFormula_bug46973() { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); Name n = wb.createName(); n.setNameName("UPSState"); String formula; @@ -532,8 +532,8 @@ public abstract class BaseTestNamedRange extends TestCase { assertFalse(n.isDeleted()); // according to exact definition of isDeleted() } - public void testDeletedCell() { - Workbook wb = getTestDataProvider().createWorkbook(); + public final void testDeletedCell() { + Workbook wb = _testDataProvider.createWorkbook(); Name n = wb.createName(); n.setNameName("MyName"); // contrived example to expose bug: @@ -545,8 +545,8 @@ public abstract class BaseTestNamedRange extends TestCase { } - public void testFunctionNames() { - Workbook wb = getTestDataProvider().createWorkbook(); + public final void testFunctionNames() { + Workbook wb = _testDataProvider.createWorkbook(); Name n = wb.createName(); assertFalse(n.isFunctionName()); @@ -559,4 +559,4 @@ public abstract class BaseTestNamedRange extends TestCase { n.setFunction(false); assertFalse(n.isFunctionName()); } -} \ No newline at end of file +} diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java index 27f949d89..b19513759 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java @@ -18,6 +18,7 @@ package org.apache.poi.ss.usermodel; import junit.framework.TestCase; + import org.apache.poi.ss.ITestDataProvider; /** @@ -25,15 +26,19 @@ import org.apache.poi.ss.ITestDataProvider; */ public abstract class BaseTestPicture extends TestCase { - protected abstract ITestDataProvider getTestDataProvider(); + private final ITestDataProvider _testDataProvider; + + protected BaseTestPicture(ITestDataProvider testDataProvider) { + _testDataProvider = testDataProvider; + } public void baseTestResize(ClientAnchor referenceAnchor) { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); Sheet sh1 = wb.createSheet(); Drawing p1 = sh1.createDrawingPatriarch(); CreationHelper factory = wb.getCreationHelper(); - byte[] pictureData = getTestDataProvider().getTestDataFileContent("logoKarmokar4.png"); + byte[] pictureData = _testDataProvider.getTestDataFileContent("logoKarmokar4.png"); int idx1 = wb.addPicture( pictureData, Workbook.PICTURE_TYPE_PNG ); Picture picture = p1.createPicture(factory.createClientAnchor(), idx1); picture.resize(); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java index aa37dcc2a..a229804a0 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java @@ -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); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java index 2a81023ed..7613da4d8 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java @@ -17,26 +17,28 @@ package org.apache.poi.ss.usermodel; +import java.util.Iterator; + import junit.framework.TestCase; + import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.util.CellRangeAddress; -import java.util.Iterator; - /** * Common superclass for testing {@link org.apache.poi.xssf.usermodel.XSSFCell} and * {@link org.apache.poi.hssf.usermodel.HSSFCell} */ public abstract class BaseTestSheet extends TestCase { - /** - * @return an object that provides test data in HSSF / XSSF specific way - */ - protected abstract ITestDataProvider getTestDataProvider(); + private final ITestDataProvider _testDataProvider; + + protected BaseTestSheet(ITestDataProvider testDataProvider) { + _testDataProvider = testDataProvider; + } public void testCreateRow() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet(); assertEquals(0, sheet.getPhysicalNumberOfRows()); @@ -76,7 +78,7 @@ public abstract class BaseTestSheet extends TestCase { public void testRemoveRow() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet1 = workbook.createSheet(); assertEquals(0, sheet1.getPhysicalNumberOfRows()); assertEquals(0, sheet1.getFirstRowNum()); @@ -117,7 +119,7 @@ public abstract class BaseTestSheet extends TestCase { } public void testCloneSheet() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); CreationHelper factory = workbook.getCreationHelper(); Sheet sheet = workbook.createSheet("Test Clone"); Row row = sheet.createRow(0); @@ -149,7 +151,7 @@ public abstract class BaseTestSheet extends TestCase { * BUG 37416 */ public void testCloneSheetMultipleTimes() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); CreationHelper factory = workbook.getCreationHelper(); Sheet sheet = workbook.createSheet("Test Clone"); Row row = sheet.createRow(0); @@ -176,7 +178,7 @@ public abstract class BaseTestSheet extends TestCase { * Setting landscape and portrait stuff on new sheets */ public void testPrintSetupLandscapeNew() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheetL = workbook.createSheet("LandscapeS"); Sheet sheetP = workbook.createSheet("LandscapeP"); @@ -197,7 +199,7 @@ public abstract class BaseTestSheet extends TestCase { assertEquals(3, sheetP.getPrintSetup().getCopies()); // Save and re-load, and check still there - workbook = getTestDataProvider().writeOutAndReadBack(workbook); + workbook = _testDataProvider.writeOutAndReadBack(workbook); sheetL = workbook.getSheet("LandscapeS"); sheetP = workbook.getSheet("LandscapeP"); @@ -213,10 +215,10 @@ public abstract class BaseTestSheet extends TestCase { * */ public void testAddMerged() { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); Sheet sheet = wb.createSheet(); assertEquals(0, sheet.getNumMergedRegions()); - SpreadsheetVersion ssVersion = getTestDataProvider().getSpreadsheetVersion(); + SpreadsheetVersion ssVersion = _testDataProvider.getSpreadsheetVersion(); CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1); sheet.addMergedRegion(region); @@ -227,24 +229,23 @@ public abstract class BaseTestSheet extends TestCase { sheet.addMergedRegion(region); fail("Expected exception"); } catch (IllegalArgumentException e){ - ; +// TODO assertEquals("Minimum row number is 0.", e.getMessage()); } try { region = new CellRangeAddress(0, 0, 0, ssVersion.getLastColumnIndex() + 1); sheet.addMergedRegion(region); fail("Expected exception"); } catch (IllegalArgumentException e){ - ; + assertEquals("Maximum column number is " + ssVersion.getLastColumnIndex(), e.getMessage()); } try { region = new CellRangeAddress(0, ssVersion.getLastRowIndex() + 1, 0, 1); sheet.addMergedRegion(region); fail("Expected exception"); } catch (IllegalArgumentException e){ - ; + assertEquals("Maximum row number is " + ssVersion.getLastRowIndex(), e.getMessage()); } assertEquals(1, sheet.getNumMergedRegions()); - } /** @@ -252,7 +253,7 @@ public abstract class BaseTestSheet extends TestCase { * */ public void testRemoveMerged() { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); Sheet sheet = wb.createSheet(); CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1); sheet.addMergedRegion(region); @@ -286,7 +287,7 @@ public abstract class BaseTestSheet extends TestCase { } public void testShiftMerged() { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); CreationHelper factory = wb.getCreationHelper(); Sheet sheet = wb.createSheet(); Row row = sheet.createRow(0); @@ -311,7 +312,7 @@ public abstract class BaseTestSheet extends TestCase { * @author Shawn Laubach (slaubach at apache dot org) */ public void testDisplayOptions() { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); Sheet sheet = wb.createSheet(); assertEquals(sheet.isDisplayGridlines(), true); @@ -324,7 +325,7 @@ public abstract class BaseTestSheet extends TestCase { sheet.setDisplayFormulas(true); sheet.setDisplayZeros(false); - wb = getTestDataProvider().writeOutAndReadBack(wb); + wb = _testDataProvider.writeOutAndReadBack(wb); sheet = wb.getSheetAt(0); assertEquals(sheet.isDisplayGridlines(), false); @@ -334,7 +335,7 @@ public abstract class BaseTestSheet extends TestCase { } public void testColumnWidth() { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); Sheet sheet = wb.createSheet(); //default column width measured in characters @@ -376,7 +377,7 @@ public abstract class BaseTestSheet extends TestCase { } //serialize and read again - wb = getTestDataProvider().writeOutAndReadBack(wb); + wb = _testDataProvider.writeOutAndReadBack(wb); sheet = wb.getSheetAt(0); assertEquals(20, sheet.getDefaultColumnWidth()); @@ -393,7 +394,7 @@ public abstract class BaseTestSheet extends TestCase { } public void testDefaultRowHeight() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet(); sheet.setDefaultRowHeightInPoints(15); assertEquals((short) 300, sheet.getDefaultRowHeight()); @@ -417,7 +418,7 @@ public abstract class BaseTestSheet extends TestCase { /** cell with formula becomes null on cloning a sheet*/ public void test35084() { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); Sheet s = wb.createSheet("Sheet1"); Row r = s.createRow(0); r.createCell(0).setCellValue(1); @@ -431,7 +432,7 @@ public abstract class BaseTestSheet extends TestCase { /** test that new default column styles get applied */ public void testDefaultColumnStyle() { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); CellStyle style = wb.createCellStyle(); Sheet sheet = wb.createSheet(); sheet.setDefaultColumnStyle(0, style); @@ -446,7 +447,7 @@ public abstract class BaseTestSheet extends TestCase { } public void testOutlineProperties() { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); Sheet sheet = wb.createSheet(); @@ -466,7 +467,7 @@ public abstract class BaseTestSheet extends TestCase { assertTrue(sheet.getRowSumsBelow()); assertTrue(sheet.getRowSumsRight()); - wb = getTestDataProvider().writeOutAndReadBack(wb); + wb = _testDataProvider.writeOutAndReadBack(wb); sheet = wb.getSheetAt(0); assertTrue(sheet.getRowSumsBelow()); assertTrue(sheet.getRowSumsRight()); @@ -476,7 +477,7 @@ public abstract class BaseTestSheet extends TestCase { * Test basic display properties */ public void testSheetProperties() { - Workbook wb = getTestDataProvider().createWorkbook(); + Workbook wb = _testDataProvider.createWorkbook(); Sheet sheet = wb.createSheet(); assertFalse(sheet.getHorizontallyCenter()); @@ -535,7 +536,7 @@ public abstract class BaseTestSheet extends TestCase { double marginHeader = defaultMargins[4]; double marginFooter = defaultMargins[5]; - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet("Sheet 1"); assertEquals(marginLeft, sheet.getMargin(Sheet.LeftMargin), 0.0); sheet.setMargin(Sheet.LeftMargin, 10.0); @@ -561,7 +562,7 @@ public abstract class BaseTestSheet extends TestCase { } public void testRowBreaks() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet(); //Sheet#getRowBreaks() returns an empty array if no row breaks are defined assertNotNull(sheet.getRowBreaks()); @@ -589,7 +590,7 @@ public abstract class BaseTestSheet extends TestCase { } public void testColumnBreaks() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet(); assertNotNull(sheet.getColumnBreaks()); assertEquals(0, sheet.getColumnBreaks().length); @@ -616,7 +617,7 @@ public abstract class BaseTestSheet extends TestCase { } public void testGetFirstLastRowNum() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet("Sheet 1"); sheet.createRow(9); sheet.createRow(0); @@ -626,7 +627,7 @@ public abstract class BaseTestSheet extends TestCase { } public void testGetFooter() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet("Sheet 1"); assertNotNull(sheet.getFooter()); sheet.getFooter().setCenter("test center footer"); @@ -634,7 +635,7 @@ public abstract class BaseTestSheet extends TestCase { } public void testGetSetColumnHidden() { - Workbook workbook = getTestDataProvider().createWorkbook(); + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet("Sheet 1"); sheet.setColumnHidden(2, true); assertTrue(sheet.isColumnHidden(2)); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java index 1c99f9674..c963f6ecc 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java @@ -17,8 +17,9 @@ package org.apache.poi.ss.usermodel; -import junit.framework.TestCase; import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.util.CellRangeAddress; @@ -27,10 +28,14 @@ import org.apache.poi.ss.util.CellRangeAddress; */ public abstract class BaseTestWorkbook extends TestCase { - protected abstract ITestDataProvider getTestDataProvider(); + private final ITestDataProvider _testDataProvider; - public void testCreateSheet() { - Workbook wb = getTestDataProvider().createWorkbook(); + protected BaseTestWorkbook(ITestDataProvider testDataProvider) { + _testDataProvider = testDataProvider; + } + + public final void testCreateSheet() { + Workbook wb = _testDataProvider.createWorkbook(); assertEquals(0, wb.getNumberOfSheets()); //getting a sheet by invalid index or non-existing name @@ -87,7 +92,7 @@ public abstract class BaseTestWorkbook extends TestCase { wb.setSheetName(1, "[I'm invalid]"); fail("should have thrown exceptiuon due to invalid sheet name"); } catch (IllegalArgumentException e) { - ; // expected during successful test + // expected during successful test } //check @@ -101,15 +106,15 @@ public abstract class BaseTestWorkbook extends TestCase { assertNull(wb.getSheet("unknown")); //serialize and read again - wb = getTestDataProvider().writeOutAndReadBack(wb); + wb = _testDataProvider.writeOutAndReadBack(wb); assertEquals(3, wb.getNumberOfSheets()); assertEquals(0, wb.getSheetIndex("sheet0")); assertEquals(1, wb.getSheetIndex("sheet1")); assertEquals(2, wb.getSheetIndex("I changed!")); } - public void testRemoveSheetAt() { - Workbook workbook = getTestDataProvider().createWorkbook(); + public final void testRemoveSheetAt() { + Workbook workbook = _testDataProvider.createWorkbook(); workbook.createSheet("sheet1"); workbook.createSheet("sheet2"); workbook.createSheet("sheet3"); @@ -130,16 +135,16 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals(3, workbook.getNumberOfSheets()); } - public void testDefaultValues() { - Workbook b = getTestDataProvider().createWorkbook(); + public final void testDefaultValues() { + Workbook b = _testDataProvider.createWorkbook(); assertEquals(0, b.getActiveSheetIndex()); assertEquals(0, b.getFirstVisibleTab()); assertEquals(0, b.getNumberOfNames()); assertEquals(0, b.getNumberOfSheets()); } - public void testSheetSelection() { - Workbook b = getTestDataProvider().createWorkbook(); + public final void testSheetSelection() { + Workbook b = _testDataProvider.createWorkbook(); b.createSheet("Sheet One"); b.createSheet("Sheet Two"); b.setActiveSheet(1); @@ -149,8 +154,8 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals(1, b.getFirstVisibleTab()); } - public void testPrintArea() { - Workbook workbook = getTestDataProvider().createWorkbook(); + public final void testPrintArea() { + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet1 = workbook.createSheet("Test Print Area"); String sheetName1 = sheet1.getSheetName(); @@ -168,8 +173,8 @@ public abstract class BaseTestWorkbook extends TestCase { assertNull(workbook.getPrintArea(0)); } - public void testGetSetActiveSheet(){ - Workbook workbook = getTestDataProvider().createWorkbook(); + public final void testGetSetActiveSheet(){ + Workbook workbook = _testDataProvider.createWorkbook(); assertEquals(0, workbook.getActiveSheetIndex()); workbook.createSheet("sheet1"); @@ -185,8 +190,8 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals(0, workbook.getActiveSheetIndex()); } - public void testSetSheetOrder() { - Workbook wb = getTestDataProvider().createWorkbook(); + public final void testSetSheetOrder() { + Workbook wb = _testDataProvider.createWorkbook(); for (int i=0; i < 10; i++) { wb.createSheet("Sheet " + i); @@ -221,7 +226,7 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals(8, wb.getSheetIndex("Sheet 9")); assertEquals(9, wb.getSheetIndex("Sheet 1")); - Workbook wbr = getTestDataProvider().writeOutAndReadBack(wb); + Workbook wbr = _testDataProvider.writeOutAndReadBack(wb); assertEquals(0, wbr.getSheetIndex("Sheet 6")); assertEquals(1, wbr.getSheetIndex("Sheet 0")); @@ -241,8 +246,8 @@ public abstract class BaseTestWorkbook extends TestCase { } } - public void testCloneSheet() { - Workbook book = getTestDataProvider().createWorkbook(); + public final void testCloneSheet() { + Workbook book = _testDataProvider.createWorkbook(); Sheet sheet = book.createSheet("TEST"); sheet.createRow(0).createCell(0).setCellValue("Test"); sheet.createRow(1).createCell(0).setCellValue(36.6); @@ -269,8 +274,8 @@ public abstract class BaseTestWorkbook extends TestCase { } - public void testParentReferences(){ - Workbook workbook = getTestDataProvider().createWorkbook(); + public final void testParentReferences(){ + Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet(); assertSame(workbook, sheet.getWorkbook()); @@ -281,7 +286,7 @@ public abstract class BaseTestWorkbook extends TestCase { assertSame(sheet, cell.getSheet()); assertSame(row, cell.getRow()); - workbook = getTestDataProvider().writeOutAndReadBack(workbook); + workbook = _testDataProvider.writeOutAndReadBack(workbook); sheet = workbook.getSheetAt(0); assertSame(workbook, sheet.getWorkbook()); @@ -293,8 +298,8 @@ public abstract class BaseTestWorkbook extends TestCase { assertSame(row, cell.getRow()); } - public void testSetRepeatingRowsAnsColumns(){ - Workbook wb = getTestDataProvider().createWorkbook(); + public final void testSetRepeatingRowsAnsColumns(){ + Workbook wb = _testDataProvider.createWorkbook(); Sheet sheet1 = wb.createSheet(); wb.setRepeatingRowsAndColumns(wb.getSheetIndex(sheet1), 0, 0, 0, 3); @@ -306,8 +311,8 @@ public abstract class BaseTestWorkbook extends TestCase { /** * Tests that all of the unicode capable string fields can be set, written and then read back */ - public void testUnicodeInAll() { - Workbook wb = getTestDataProvider().createWorkbook(); + public final void testUnicodeInAll() { + Workbook wb = _testDataProvider.createWorkbook(); CreationHelper factory = wb.getCreationHelper(); //Create a unicode dataformat (contains euro symbol) DataFormat df = wb.createDataFormat(); @@ -341,7 +346,7 @@ public abstract class BaseTestWorkbook extends TestCase { String formulaString = "TEXT(12.34,\"\u20ac###,##\")"; c3.setCellFormula(formulaString); - wb = getTestDataProvider().writeOutAndReadBack(wb); + wb = _testDataProvider.writeOutAndReadBack(wb); //Test the sheetname s = wb.getSheet("\u20ac");