consolidate duplicates between TestXSSF* and TestSXSSF*

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1739552 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-04-17 08:40:27 +00:00
parent 144758da98
commit da6d61f83b
12 changed files with 37 additions and 77 deletions

View File

@ -17,9 +17,12 @@
package org.apache.poi.ss.usermodel; package org.apache.poi.ss.usermodel;
import java.io.IOException;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.xssf.streaming.SXSSFRow; import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.junit.Test;
/** /**
* Class for combined testing of XML-specific functionality of * Class for combined testing of XML-specific functionality of
@ -32,4 +35,14 @@ public abstract class BaseTestXRow extends BaseTestRow {
protected BaseTestXRow(ITestDataProvider testDataProvider) { protected BaseTestXRow(ITestDataProvider testDataProvider) {
super(testDataProvider); super(testDataProvider);
} }
@Test
public void testRowBounds() throws IOException {
baseTestRowBounds(_testDataProvider.getSpreadsheetVersion().getLastRowIndex());
}
@Test
public void testCellBounds() throws IOException {
baseTestCellBounds(_testDataProvider.getSpreadsheetVersion().getLastColumnIndex());
}
} }

View File

@ -19,9 +19,6 @@
package org.apache.poi.xssf.streaming; package org.apache.poi.xssf.streaming;
import java.io.IOException;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.BaseTestXRow; import org.apache.poi.ss.usermodel.BaseTestXRow;
import org.apache.poi.xssf.SXSSFITestDataProvider; import org.apache.poi.xssf.SXSSFITestDataProvider;
import org.junit.After; import org.junit.After;
@ -42,14 +39,4 @@ public final class TestSXSSFRow extends BaseTestXRow {
((SXSSFITestDataProvider) _testDataProvider).cleanup(); ((SXSSFITestDataProvider) _testDataProvider).cleanup();
} }
@Test
public void testRowBounds() throws IOException {
baseTestRowBounds(SpreadsheetVersion.EXCEL2007.getLastRowIndex());
}
@Test
public void testCellBounds() throws IOException {
baseTestCellBounds(SpreadsheetVersion.EXCEL2007.getLastColumnIndex());
}
} }

View File

@ -24,7 +24,6 @@ import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.BaseTestXSheet; import org.apache.poi.ss.usermodel.BaseTestXSheet;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
@ -155,9 +154,4 @@ public final class TestSXSSFSheet extends BaseTestXSheet {
template.close(); template.close();
} }
} }
@Test(expected=IllegalArgumentException.class)
public void createRowAfterLastRow() throws IOException {
createRowAfterLastRow(SpreadsheetVersion.EXCEL2007);
}
} }

View File

@ -33,7 +33,6 @@ import java.io.IOException;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.POITestCase; import org.apache.poi.POITestCase;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.BaseTestXWorkbook; import org.apache.poi.ss.usermodel.BaseTestXWorkbook;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
@ -307,7 +306,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
xwb.close(); xwb.close();
} }
static void assertWorkbookDispose(SXSSFWorkbook wb) protected static void assertWorkbookDispose(SXSSFWorkbook wb)
{ {
int rowNum = 1000; int rowNum = 1000;
int sheetNum = 5; int sheetNum = 5;
@ -455,11 +454,6 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
workBook.close(); workBook.close();
} }
@Test
@Override
public void getSpreadsheetVersion() throws IOException {
verifySpreadsheetVersion(SpreadsheetVersion.EXCEL2007);
}
@Test @Test
public void closeDoesNotModifyWorkbook() throws IOException, InvalidFormatException { public void closeDoesNotModifyWorkbook() throws IOException, InvalidFormatException {

View File

@ -23,7 +23,6 @@ import static org.junit.Assert.assertSame;
import java.io.IOException; import java.io.IOException;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.BaseTestXRow; import org.apache.poi.ss.usermodel.BaseTestXRow;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellCopyPolicy; import org.apache.poi.ss.usermodel.CellCopyPolicy;
@ -42,15 +41,6 @@ public final class TestXSSFRow extends BaseTestXRow {
} }
@Test @Test
public void testRowBounds() throws IOException {
baseTestRowBounds(SpreadsheetVersion.EXCEL2007.getLastRowIndex());
}
@Test
public void testCellBounds() throws IOException {
baseTestCellBounds(SpreadsheetVersion.EXCEL2007.getLastColumnIndex());
}
public void testCopyRowFrom() throws IOException { public void testCopyRowFrom() throws IOException {
final XSSFWorkbook workbook = new XSSFWorkbook(); final XSSFWorkbook workbook = new XSSFWorkbook();
final XSSFSheet sheet = workbook.createSheet("test"); final XSSFSheet sheet = workbook.createSheet("test");
@ -65,6 +55,7 @@ public final class TestXSSFRow extends BaseTestXRow {
workbook.close(); workbook.close();
} }
@Test
public void testCopyRowFromExternalSheet() throws IOException { public void testCopyRowFromExternalSheet() throws IOException {
final XSSFWorkbook workbook = new XSSFWorkbook(); final XSSFWorkbook workbook = new XSSFWorkbook();
final Sheet srcSheet = workbook.createSheet("src"); final Sheet srcSheet = workbook.createSheet("src");
@ -159,6 +150,7 @@ public final class TestXSSFRow extends BaseTestXRow {
workbook.close(); workbook.close();
} }
@Test
public void testCopyRowOverwritesExistingRow() throws IOException { public void testCopyRowOverwritesExistingRow() throws IOException {
final XSSFWorkbook workbook = new XSSFWorkbook(); final XSSFWorkbook workbook = new XSSFWorkbook();
final XSSFSheet sheet1 = workbook.createSheet("Sheet1"); final XSSFSheet sheet1 = workbook.createSheet("Sheet1");

View File

@ -1055,11 +1055,6 @@ public final class TestXSSFSheet extends BaseTestXSheet {
wb2.close(); wb2.close();
} }
@Test(expected=IllegalArgumentException.class)
public void createRowAfterLastRow() throws IOException {
createRowAfterLastRow(SpreadsheetVersion.EXCEL2007);
}
@Test @Test
public void setAutoFilter() throws IOException { public void setAutoFilter() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
@ -1603,7 +1598,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
wb.close(); wb.close();
} }
public void testCopyMultipleRows(String copyRowsTestWorkbook) throws IOException { protected void testCopyMultipleRows(String copyRowsTestWorkbook) throws IOException {
final double FLOAT_PRECISION = 1e-9; final double FLOAT_PRECISION = 1e-9;
final XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(copyRowsTestWorkbook); final XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(copyRowsTestWorkbook);
final XSSFSheet sheet = wb.getSheetAt(0); final XSSFSheet sheet = wb.getSheetAt(0);

View File

@ -773,7 +773,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
} }
} }
public void setPivotData(XSSFWorkbook wb){ protected void setPivotData(XSSFWorkbook wb){
XSSFSheet sheet = wb.createSheet(); XSSFSheet sheet = wb.createSheet();
Row row1 = sheet.createRow(0); Row row1 = sheet.createRow(0);
@ -948,8 +948,6 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
workbook.close(); workbook.close();
} }
@SuppressWarnings("unchecked")
@Test
/** /**
* Iterator<XSSFSheet> XSSFWorkbook.iterator was committed in r700472 on 2008-09-30 * Iterator<XSSFSheet> XSSFWorkbook.iterator was committed in r700472 on 2008-09-30
* and has been replaced with Iterator<Sheet> XSSFWorkbook.iterator * and has been replaced with Iterator<Sheet> XSSFWorkbook.iterator
@ -965,6 +963,8 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
* upgrade their code with either of the following options presented in this test case. * upgrade their code with either of the following options presented in this test case.
* *
*/ */
@SuppressWarnings("unchecked")
@Test
public void bug58245_XSSFSheetIterator() throws IOException { public void bug58245_XSSFSheetIterator() throws IOException {
final XSSFWorkbook wb = new XSSFWorkbook(); final XSSFWorkbook wb = new XSSFWorkbook();
wb.createSheet(); wb.createSheet();
@ -1065,12 +1065,6 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
} }
} }
@Test
@Override
public void getSpreadsheetVersion() throws IOException {
verifySpreadsheetVersion(SpreadsheetVersion.EXCEL2007);
}
@Test @Test
public void closeDoesNotModifyWorkbook() throws IOException, InvalidFormatException { public void closeDoesNotModifyWorkbook() throws IOException, InvalidFormatException {
final String filename = "SampleSS.xlsx"; final String filename = "SampleSS.xlsx";

View File

@ -56,7 +56,6 @@ import org.apache.poi.hssf.record.WSBoolRecord;
import org.apache.poi.hssf.record.WindowTwoRecord; import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock; import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector; import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.ptg.Area3DPtg; import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.usermodel.AutoFilter; import org.apache.poi.ss.usermodel.AutoFilter;
@ -84,11 +83,6 @@ public final class TestHSSFSheet extends BaseTestSheet {
super(HSSFITestDataProvider.instance); super(HSSFITestDataProvider.instance);
} }
@Test(expected=IllegalArgumentException.class)
public void createRowAfterLastRow() throws IOException {
createRowAfterLastRow(SpreadsheetVersion.EXCEL97);
}
/** /**
* Test for Bugzilla #29747. * Test for Bugzilla #29747.
* Moved from TestHSSFWorkbook#testSetRepeatingRowsAndColumns(). * Moved from TestHSSFWorkbook#testSetRepeatingRowsAndColumns().

View File

@ -53,7 +53,6 @@ import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.ptg.Area3DPtg; import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
@ -216,7 +215,6 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
wb.close(); wb.close();
} }
@SuppressWarnings("unused")
@Test @Test
public void selectMultiple() throws IOException { public void selectMultiple() throws IOException {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
@ -1194,12 +1192,6 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
} }
@Test
@Override
public void getSpreadsheetVersion() throws IOException {
verifySpreadsheetVersion(SpreadsheetVersion.EXCEL97);
}
@Test @Test
public void closeDoesNotModifyWorkbook() throws IOException { public void closeDoesNotModifyWorkbook() throws IOException {
final String filename = "SampleSS.xls"; final String filename = "SampleSS.xls";

View File

@ -72,6 +72,7 @@ public abstract class BaseTestRow {
* Make sure that there is no cross-talk between rows especially with getFirstCellNum and getLastCellNum * 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. * This test was added in response to bug report 44987.
*/ */
@Test
public void testBoundsInMultipleRows() throws IOException { public void testBoundsInMultipleRows() throws IOException {
Workbook workbook = _testDataProvider.createWorkbook(); Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet(); Sheet sheet = workbook.createSheet();
@ -97,6 +98,7 @@ public abstract class BaseTestRow {
workbook.close(); workbook.close();
} }
@Test
public void testRemoveCell() throws IOException { public void testRemoveCell() throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
{ {
@ -139,7 +141,7 @@ public abstract class BaseTestRow {
wb2.close(); wb2.close();
} }
public void baseTestRowBounds(int maxRowNum) throws IOException { protected void baseTestRowBounds(int maxRowNum) throws IOException {
Workbook workbook = _testDataProvider.createWorkbook(); Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet(); Sheet sheet = workbook.createSheet();
//Test low row bound //Test low row bound
@ -168,7 +170,7 @@ public abstract class BaseTestRow {
workbook.close(); workbook.close();
} }
public void baseTestCellBounds(int maxCellNum) throws IOException { protected void baseTestCellBounds(int maxCellNum) throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
Sheet sheet = wb1.createSheet(); Sheet sheet = wb1.createSheet();
@ -211,6 +213,7 @@ public abstract class BaseTestRow {
* Prior to patch 43901, POI was producing files with the wrong last-column * Prior to patch 43901, POI was producing files with the wrong last-column
* number on the row * number on the row
*/ */
@Test
public void testLastCellNumIsCorrectAfterAddCell_bug43901() throws IOException { public void testLastCellNumIsCorrectAfterAddCell_bug43901() throws IOException {
Workbook workbook = _testDataProvider.createWorkbook(); Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet("test"); Sheet sheet = workbook.createSheet("test");
@ -234,6 +237,7 @@ public abstract class BaseTestRow {
/** /**
* Tests for the missing/blank cell policy stuff * Tests for the missing/blank cell policy stuff
*/ */
@Test
public void testGetCellPolicy() throws IOException { public void testGetCellPolicy() throws IOException {
Workbook workbook = _testDataProvider.createWorkbook(); Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet("test"); Sheet sheet = workbook.createSheet("test");
@ -305,6 +309,7 @@ public abstract class BaseTestRow {
workbook.close(); workbook.close();
} }
@Test
public void testRowHeight() throws IOException { public void testRowHeight() throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
Sheet sheet = wb1.createSheet(); Sheet sheet = wb1.createSheet();
@ -360,6 +365,7 @@ public abstract class BaseTestRow {
/** /**
* Test adding cells to a row in various places and see if we can find them again. * Test adding cells to a row in various places and see if we can find them again.
*/ */
@Test
public void testCellIterator() throws IOException { public void testCellIterator() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet(); Sheet sheet = wb.createSheet();
@ -417,6 +423,7 @@ public abstract class BaseTestRow {
wb.close(); wb.close();
} }
@Test
public void testRowStyle() throws IOException { public void testRowStyle() throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
Sheet sheet = wb1.createSheet("test"); Sheet sheet = wb1.createSheet("test");

View File

@ -116,7 +116,9 @@ public abstract class BaseTestSheet {
} }
} }
protected void createRowAfterLastRow(SpreadsheetVersion version) throws IOException { @Test(expected=IllegalArgumentException.class)
public void createRowAfterLastRow() throws IOException {
final SpreadsheetVersion version = _testDataProvider.getSpreadsheetVersion();
final Workbook workbook = _testDataProvider.createWorkbook(); final Workbook workbook = _testDataProvider.createWorkbook();
final Sheet sh = workbook.createSheet(); final Sheet sh = workbook.createSheet();
sh.createRow(version.getLastRowIndex()); sh.createRow(version.getLastRowIndex());
@ -128,7 +130,6 @@ public abstract class BaseTestSheet {
} }
} }
@Test @Test
public void removeRow() throws IOException { public void removeRow() throws IOException {
Workbook workbook = _testDataProvider.createWorkbook(); Workbook workbook = _testDataProvider.createWorkbook();

View File

@ -33,7 +33,6 @@ import java.util.Iterator;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.junit.Test; import org.junit.Test;
@ -743,7 +742,7 @@ public abstract class BaseTestWorkbook {
wb2.close(); wb2.close();
} }
public void changeSheetNameWithSharedFormulas(String sampleFile) throws IOException { protected void changeSheetNameWithSharedFormulas(String sampleFile) throws IOException {
Workbook wb = _testDataProvider.openSampleWorkbook(sampleFile); Workbook wb = _testDataProvider.openSampleWorkbook(sampleFile);
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
@ -827,11 +826,9 @@ public abstract class BaseTestWorkbook {
} }
@Test @Test
public abstract void getSpreadsheetVersion() throws IOException; public void getSpreadsheetVersion() throws IOException {
protected void verifySpreadsheetVersion(SpreadsheetVersion expected) throws IOException {
final Workbook wb = _testDataProvider.createWorkbook(); final Workbook wb = _testDataProvider.createWorkbook();
assertEquals(expected, wb.getSpreadsheetVersion()); assertEquals(_testDataProvider.getSpreadsheetVersion(), wb.getSpreadsheetVersion());
wb.close(); wb.close();
} }