]> source.dussan.org Git - poi.git/commitdiff
add test coverage for TestSXSSFCell.toString() on blank and date cells
authorJaven O'Neal <onealj@apache.org>
Wed, 6 Apr 2016 06:01:26 +0000 (06:01 +0000)
committerJaven O'Neal <onealj@apache.org>
Wed, 6 Apr 2016 06:01:26 +0000 (06:01 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1737923 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java

index c9c1d55d3f7f5866c56fdc7bbe8e30f55b6c9f68..2b579b3503050dc2e6f82636b00bd9366004500a 100644 (file)
@@ -294,12 +294,28 @@ public abstract class BaseTestCell {
         r.createCell(2).setCellValue(factory.createRichTextString("Astring"));
         r.createCell(3).setCellErrorValue(FormulaError.DIV0.getCode());
         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("Numeric", "1.5", r.getCell(1).toString());
         assertEquals("String", "Astring", r.getCell(2).toString());
         assertEquals("Error", "#DIV/0!", r.getCell(3).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
         Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
@@ -311,6 +327,9 @@ public abstract class BaseTestCell {
         assertEquals("String", "Astring", r.getCell(2).toString());
         assertEquals("Error", "#DIV/0!", r.getCell(3).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();
     }