private XSSFITestDataProvider() {
// enforce singleton
}
- public static XSSFITestDataProvider getInstance(){
- return instance;
- }
public XSSFWorkbook openSampleWorkbook(String sampleFileName) {
return XSSFTestDataSamples.openSampleWorkbook(sampleFileName);
}
import org.apache.poi.xssf.XSSFTestDataSamples;
public final class TestXSSFBugs extends BaseTestBugzillaIssues {
- @Override
- protected XSSFITestDataProvider getTestDataProvider(){
- return XSSFITestDataProvider.getInstance();
+
+ public TestXSSFBugs() {
+ super(XSSFITestDataProvider.instance);
}
/**
* 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());
* 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());
);
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();
rels = drawing.getRelations();
assertEquals(1, rels.size());
assertEquals("Sheet1!A1", rels.get(0).getPackageRelationship().getTargetURI().getFragment());
-
}
-
}
*/
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
//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).
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");
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");
}
assertEquals(0, sheet.getColumnBreaks().length);
assertEquals(true, sheet.getRowSumsBelow());
}
-
- /**
- * YK: disable failing test from the superclass
- */
- @Override
- public void testDefaultColumnStyle() {
-
- }
-}
\ No newline at end of file
+}
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);
}
/**
comment.setString(new HSSFRichTextString(TEST_RICHTEXTSTRING));
fail("expected exception");
} catch (IllegalArgumentException e){
- ;
+ assertEquals("Only XSSFRichTextString argument is supported", e.getMessage());
}
//simple string argument
assertEquals("", comment.getAuthor());
assertEquals(2, sheetComments.getNumberOfAuthors());
}
-
-
}
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);
}
}
public final class TestXSSFFont extends BaseTestFont{
- @Override
- protected XSSFITestDataProvider getTestDataProvider() {
- return XSSFITestDataProvider.getInstance();
+ public TestXSSFFont() {
+ super(XSSFITestDataProvider.instance);
}
public void testDefaultFont() {
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
/**
* 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());
*/
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);
*/
public final class TestXSSFPicture extends BaseTestPicture {
- @Override
- protected XSSFITestDataProvider getTestDataProvider(){
- return XSSFITestDataProvider.getInstance();
+ public TestXSSFPicture() {
+ super(XSSFITestDataProvider.instance);
}
public void testResize() {
*/
public final class TestXSSFRow extends BaseTestRow {
- @Override
- protected XSSFITestDataProvider getTestDataProvider(){
- return XSSFITestDataProvider.getInstance();
+ public TestXSSFRow() {
+ super(XSSFITestDataProvider.instance);
}
public void testRowBounds() {
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
}
public void testGetAllHeadersFooters() {
- XSSFWorkbook workbook = getTestDataProvider().createWorkbook();
+ XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sheet 1");
assertNotNull(sheet.getOddFooter());
assertNotNull(sheet.getEvenFooter());
}
//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());
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));
public final class TestXSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateArrayFormulas {
public TestXSSFSheetUpdateArrayFormulas() {
- super(XSSFITestDataProvider.getInstance());
+ super(XSSFITestDataProvider.instance);
}
// Test methods common with HSSF are in superclass
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
*/
}
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);
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());
-
- 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());
-
- 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));
-
- wb.removeSheetAt(2);
- assertEquals(2, wb.getNumberOfSheets());
- assertNull(wb.getCalculationChain());
-
- wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
- assertEquals(2, wb.getNumberOfSheets());
- assertNull(wb.getCalculationChain());
-
- assertEquals("Numbers", wb.getSheetName(0));
- assertEquals("Chart", wb.getSheetName(1));
- }
+ /**
+ * 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());
+
+ 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));
+
+ wb.removeSheetAt(2);
+ assertEquals(2, wb.getNumberOfSheets());
+ assertNull(wb.getCalculationChain());
+
+ wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+ assertEquals(2, wb.getNumberOfSheets());
+ assertNull(wb.getCalculationChain());
+
+ assertEquals("Numbers", wb.getSheetName(0));
+ assertEquals("Chart", wb.getSheetName(1));
+ }
}
private HSSFITestDataProvider(){
// enforce singleton
}
- public static HSSFITestDataProvider getInstance(){
- return instance;
- }
public HSSFWorkbook openSampleWorkbook(String sampleFileName) {
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
}
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;
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;
}
}
*/
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) {
assertEquals("test ", cell1.getStringCellValue().toString());
HSSFCell cell2 = s.getRow(0).getCell(1);
- assertEquals(1.0, cell2.getNumericCellValue());
+ assertEquals(1.0, cell2.getNumericCellValue(), 0.0);
}
/**
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;
*/
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
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",
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",
// 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());
*/
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);
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();
*/
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);
*/
public void testWithTwoHyperlinks() {
- HSSFWorkbook wb = _hssfDP.openSampleWorkbook("WithTwoHyperLinks.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithTwoHyperLinks.xls");
HSSFSheet sheet = wb.getSheetAt(0);
==================================================================== */
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;
/**
*/
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;
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);
}
}
*/
public final class TestHSSFFont extends BaseTestFont {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFFont() {
+ super(HSSFITestDataProvider.instance);
}
public void testDefaultFont() {
*/
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;
}
public void testModify() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("HyperlinksOnManySheets.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("HyperlinksOnManySheets.xls");
HSSFSheet sheet;
HSSFCell cell;
//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();
* 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;
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);
}
public void testCreate() {
- HSSFWorkbook wb = getTestDataProvider().createWorkbook();
+ HSSFWorkbook wb = new HSSFWorkbook();
HSSFHyperlink link;
HSSFCell cell;
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);
* 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);
* 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) {
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
- }
+ }
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFName() {
+ super(HSSFITestDataProvider.instance);
}
public void testRepeatingRowsAndColumsNames() {
}
public void testNamedRange() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("Simple.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");
//Creating new Named Range
HSSFName newNamedRange = wb.createName();
* 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");
* 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);
* 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";
}
}
-}
\ No newline at end of file
+}
*/
public final class TestHSSFPicture extends BaseTestPicture {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFPicture() {
+ super(HSSFITestDataProvider.instance);
}
public void testResize() {
*/
public final class TestHSSFRow extends BaseTestRow {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFRow() {
+ super(HSSFITestDataProvider.instance);
}
public void testRowBounds() {
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);
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.util.Arrays;
import junit.framework.AssertionFailedError;
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;
*/
public final class TestHSSFSheet extends BaseTestSheet {
- @Override
- protected HSSFITestDataProvider getTestDataProvider(){
- return HSSFITestDataProvider.getInstance();
+ public TestHSSFSheet() {
+ super(HSSFITestDataProvider.instance);
}
public void testTestGetSetMargin() {
* 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());
}
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);
}
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());
*
*/
public void testPageBreakFiles() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("SimpleWithPageBreaks.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls");
HSSFSheet sheet = wb.getSheetAt(0);
assertNotNull(sheet);
}
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");
* 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);
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);
}
public void testAutoSizeColumn() {
- HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("43902.xls");
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("43902.xls");
String sheetName = "my sheet";
HSSFSheet sheet = wb.getSheet(sheetName);
* 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);
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};
public final class TestHSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateArrayFormulas {
public TestHSSFSheetUpdateArrayFormulas() {
- super(HSSFITestDataProvider.getInstance());
+ super(HSSFITestDataProvider.instance);
}
// Test methods common with XSSF are in superclass
* 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() {
* 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
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());
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);
// 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());
// Two charts, three sheets
- b = getTestDataProvider().openSampleWorkbook("44010-TwoCharts.xls");
+ b = HSSFTestDataSamples.openSampleWorkbook("44010-TwoCharts.xls");
assertEquals(3, b.getNumberOfSheets());
s = b.getSheetAt(1);
// 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);
* 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
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;
*/
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);
* @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();
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;
/**
* 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);
}
- public void test28031() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void test28031() {
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
wb.setSheetName(0, "Sheet1");
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());
}
* 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 ;
sheet.setDefaultColumnWidth(18) ;
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
rw = sheet.getRow(0);
//Header row
/**
* 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);
}
}
- public void testBug43093() {
- Workbook xlw = getTestDataProvider().createWorkbook();
+ public final void testBug43093() {
+ Workbook xlw = _testDataProvider.createWorkbook();
addNewSheetWithCellsA1toD4(xlw, 1);
addNewSheetWithCellsA1toD4(xlw, 2);
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;
}
}
- private String createFunction(String name, int maxArgs){
+ private static String createFunction(String name, int maxArgs){
StringBuffer fmla = new StringBuffer();
fmla.append(name);
fmla.append("(");
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));
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();
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();
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);
/**
* 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);
/**
* 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);
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++) {
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
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();
//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();
assertEquals(3, comment.getRow());
assertEquals(5, comment.getColumn());
}
-}
\ No newline at end of file
+}
package org.apache.poi.ss.usermodel;
-import java.util.Map;
-
import junit.framework.TestCase;
+
import org.apache.poi.ss.ITestDataProvider;
/**
*/
public abstract class BaseTestDataFormat extends TestCase {
- /**
- * @return an object that provides test data in HSSF / XSSF specific way
- */
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
+
+ protected BaseTestDataFormat(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
- public void baseBuiltinFormats() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testBuiltinFormats() {
+ Workbook wb = _testDataProvider.createWorkbook();
DataFormat df = wb.createDataFormat();
- Map<Integer, String> formats = BuiltinFormats.getBuiltinFormats();
- for (int idx : formats.keySet()) {
- String fmt = formats.get(Integer.valueOf(idx));
+ String[] formats = BuiltinFormats.getAll();
+ for (int idx = 0; idx < formats.length; idx++) {
+ String fmt = formats[idx];
assertEquals(idx, df.getFormat(fmt));
}
*/
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);
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();
* 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);
r1c1.setCellStyle(cellStyleTitle);
// Save and re-load
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
s1 = wb.getSheetAt(0);
assertEquals(num0 + 1, wb.getNumberOfFonts());
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());
*
* @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();
import junit.framework.TestCase;
+import org.apache.poi.hssf.HSSFITestDataProvider;
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;
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();
assertEquals("mailto:poi@apache.org?subject=Hyperlinks", link.getAddress());
link = sheet.getRow(3).getCell(0).getHyperlink();
assertEquals("'Target Sheet'!A1", link.getAddress());
- }
-}
\ No newline at end of file
+ }
+}
*/
public abstract class BaseTestNamedRange extends TestCase {
- /**
- * @return an object that provides test data in HSSF / XSSF specific way
- */
- protected abstract ITestDataProvider getTestDataProvider();
+ private final ITestDataProvider _testDataProvider;
+
+ protected BaseTestNamedRange(ITestDataProvider testDataProvider) {
+ _testDataProvider = testDataProvider;
+ }
- public void testCreate(){
+ public final void testCreate(){
// Create a new workbook
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet1 = wb.createSheet("Test1");
Sheet sheet2 = wb.createSheet("Testing Named Ranges");
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");
assertEquals(1, wb.getNumberOfNames());
}
- public void testScope() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testScope() {
+ Workbook wb = _testDataProvider.createWorkbook();
wb.createSheet();
wb.createSheet();
* <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 ();
// 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()));
/**
* 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);
/**
* 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);
/**
* 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);
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);
/**
* 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");
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);
* 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);
* 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";
* 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);
/**
* 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");
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()));
/**
* 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));
/**
* 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));
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;
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:
}
- public void testFunctionNames() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ public final void testFunctionNames() {
+ Workbook wb = _testDataProvider.createWorkbook();
Name n = wb.createName();
assertFalse(n.isFunctionName());
n.setFunction(false);
assertFalse(n.isFunctionName());
}
-}
\ No newline at end of file
+}
package org.apache.poi.ss.usermodel;
import junit.framework.TestCase;
+
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();
package org.apache.poi.ss.usermodel;
+import java.util.Iterator;
+
import junit.framework.TestCase;
-import org.apache.poi.ss.ITestDataProvider;
-import java.util.Iterator;
+import org.apache.poi.ss.ITestDataProvider;
/**
* A base class for testing implementations of
*/
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());
* 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);
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);
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());
}
public void baseTestRowBounds(int maxRowNum) {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
//Test low row bound
sheet.createRow(0);
}
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
//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());
* 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);
/**
* 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);
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);
row4.setZeroHeight(true);
assertTrue(row4.getZeroHeight());
- workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+ workbook = _testDataProvider.writeOutAndReadBack(workbook);
sheet = workbook.getSheetAt(0);
row1 = sheet.getRow(0);
/**
* 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);
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());
public void testRemoveRow() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet1 = workbook.createSheet();
assertEquals(0, sheet1.getPhysicalNumberOfRows());
assertEquals(0, sheet1.getFirstRowNum());
}
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);
* 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);
* 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");
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");
*
*/
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);
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());
-
}
/**
*
*/
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);
}
public void testShiftMerged() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
CreationHelper factory = wb.getCreationHelper();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
* @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);
sheet.setDisplayFormulas(true);
sheet.setDisplayZeros(false);
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
assertEquals(sheet.isDisplayGridlines(), false);
}
public void testColumnWidth() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
//default column width measured in characters
}
//serialize and read again
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
assertEquals(20, sheet.getDefaultColumnWidth());
}
public void testDefaultRowHeight() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
sheet.setDefaultRowHeightInPoints(15);
assertEquals((short) 300, sheet.getDefaultRowHeight());
/** 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);
/** 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);
}
public void testOutlineProperties() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
assertTrue(sheet.getRowSumsBelow());
assertTrue(sheet.getRowSumsRight());
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
assertTrue(sheet.getRowSumsBelow());
assertTrue(sheet.getRowSumsRight());
* Test basic display properties
*/
public void testSheetProperties() {
- Workbook wb = getTestDataProvider().createWorkbook();
+ Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
assertFalse(sheet.getHorizontallyCenter());
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);
}
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());
}
public void testColumnBreaks() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
assertNotNull(sheet.getColumnBreaks());
assertEquals(0, sheet.getColumnBreaks().length);
}
public void testGetFirstLastRowNum() {
- Workbook workbook = getTestDataProvider().createWorkbook();
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet("Sheet 1");
sheet.createRow(9);
sheet.createRow(0);
}
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");
}
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));
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;
*/
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
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
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");
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);
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();
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");
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);
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"));
}
}
- 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);
}
- public void testParentReferences(){
- Workbook workbook = getTestDataProvider().createWorkbook();
+ public final void testParentReferences(){
+ Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
assertSame(workbook, sheet.getWorkbook());
assertSame(sheet, cell.getSheet());
assertSame(row, cell.getRow());
- workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+ workbook = _testDataProvider.writeOutAndReadBack(workbook);
sheet = workbook.getSheetAt(0);
assertSame(workbook, sheet.getWorkbook());
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);
/**
* 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();
String formulaString = "TEXT(12.34,\"\u20ac###,##\")";
c3.setCellFormula(formulaString);
- wb = getTestDataProvider().writeOutAndReadBack(wb);
+ wb = _testDataProvider.writeOutAndReadBack(wb);
//Test the sheetname
s = wb.getSheet("\u20ac");