add test coverage for TestSXSSFCell.toString() on blank and date cells

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1737923 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-04-06 06:01:26 +00:00
parent f9c74888e3
commit 7fd89e0e39

View File

@ -294,12 +294,28 @@ public abstract class BaseTestCell {
r.createCell(2).setCellValue(factory.createRichTextString("Astring")); r.createCell(2).setCellValue(factory.createRichTextString("Astring"));
r.createCell(3).setCellErrorValue(FormulaError.DIV0.getCode()); r.createCell(3).setCellErrorValue(FormulaError.DIV0.getCode());
r.createCell(4).setCellFormula("A1+B1"); r.createCell(4).setCellFormula("A1+B1");
r.createCell(5); // blank
// create date-formatted cell
Calendar c = LocaleUtil.getLocaleCalendar();
c.set(2010, 01, 02, 00, 00, 00);
r.createCell(6).setCellValue(c);
CellStyle dateStyle = wb1.createCellStyle();
short formatId = wb1.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm"); // any date format will do
dateStyle.setDataFormat(formatId);
r.getCell(6).setCellStyle(dateStyle);
assertEquals("Boolean", "TRUE", r.getCell(0).toString()); assertEquals("Boolean", "TRUE", r.getCell(0).toString());
assertEquals("Numeric", "1.5", r.getCell(1).toString()); assertEquals("Numeric", "1.5", r.getCell(1).toString());
assertEquals("String", "Astring", r.getCell(2).toString()); assertEquals("String", "Astring", r.getCell(2).toString());
assertEquals("Error", "#DIV/0!", r.getCell(3).toString()); assertEquals("Error", "#DIV/0!", r.getCell(3).toString());
assertEquals("Formula", "A1+B1", r.getCell(4).toString()); assertEquals("Formula", "A1+B1", r.getCell(4).toString());
assertEquals("Blank", "", r.getCell(5).toString());
// toString on a date-formatted cell displays dates as dd-MMM-yyyy, which has locale problems with the month
String dateCell1 = r.getCell(6).toString();
assertTrue("Date (Day)", dateCell1.startsWith("02-"));
assertTrue("Date (Year)", dateCell1.endsWith("-2010"));
//Write out the file, read it in, and then check cell values //Write out the file, read it in, and then check cell values
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
@ -311,6 +327,9 @@ public abstract class BaseTestCell {
assertEquals("String", "Astring", r.getCell(2).toString()); assertEquals("String", "Astring", r.getCell(2).toString());
assertEquals("Error", "#DIV/0!", r.getCell(3).toString()); assertEquals("Error", "#DIV/0!", r.getCell(3).toString());
assertEquals("Formula", "A1+B1", r.getCell(4).toString()); assertEquals("Formula", "A1+B1", r.getCell(4).toString());
assertEquals("Blank", "", r.getCell(5).toString());
String dateCell2 = r.getCell(6).toString();
assertEquals("Date", dateCell1, dateCell2);
wb2.close(); wb2.close();
} }