]> source.dussan.org Git - poi.git/commitdiff
break testBoolErr into 2 unit tests. The test shouldn't be aware of the underlying...
authorJaven O'Neal <onealj@apache.org>
Mon, 30 Nov 2015 04:38:04 +0000 (04:38 +0000)
committerJaven O'Neal <onealj@apache.org>
Mon, 30 Nov 2015 04:38:04 +0000 (04:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1717163 13f79535-47bb-0310-9956-ffa450edef68

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

index ebefb4358c344de989e7c7914cccd8baad59ca2c..3fc7fd669a0a00a8f4247fef2ea5bb31dba770cb 100644 (file)
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
 
 import java.io.IOException;
 import java.util.Calendar;
@@ -140,46 +141,92 @@ public abstract class BaseTestCell {
        }
 
        /**
-        * test that Boolean and Error types (BoolErrRecord) are supported properly.
+        * test that Boolean (BoolErrRecord) are supported properly.
+        * @see testErr
         */
        @Test
-       public void testBoolErr() throws Exception {
+       public void testBool() throws IOException {
 
                Workbook wb1 = _testDataProvider.createWorkbook();
                Sheet s = wb1.createSheet("testSheet1");
                Row r;
                Cell c;
+               // B1
                r = s.createRow(0);
                c=r.createCell(1);
-               //c.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
+               assumeTrue(0 == c.getRowIndex());
+               assumeTrue(1 == c.getColumnIndex());
                c.setCellValue(true);
 
+               // C1
                c=r.createCell(2);
-               //c.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
+               assumeTrue(0 == c.getRowIndex());
+               assumeTrue(2 == c.getColumnIndex());
                c.setCellValue(false);
 
+               Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+               wb1.close();
+               
+               s = wb2.getSheet("testSheet1");
+               r = s.getRow(0);
+               assumeTrue("Row 1 should have 2 cells", 2 == r.getPhysicalNumberOfCells());
+               
+               c = r.getCell(1);
+               assumeTrue(0 == c.getRowIndex());
+        assumeTrue(1 == c.getColumnIndex());
+               assertEquals(Cell.CELL_TYPE_BOOLEAN, c.getCellType());
+               assertEquals("B1 value", true, c.getBooleanCellValue());
+               
+               c = r.getCell(2);
+               assumeTrue(0 == c.getRowIndex());
+               assumeTrue(2 == c.getColumnIndex());
+               assertEquals(Cell.CELL_TYPE_BOOLEAN, c.getCellType());
+               assertEquals("C1 value", false, c.getBooleanCellValue());
+               
+               wb2.close();
+       }
+       
+       /**
+        * test that Error types (BoolErrRecord) are supported properly.
+        * @see testBool
+        */
+       @Test
+       public void testErr() throws IOException {
+
+               Workbook wb1 = _testDataProvider.createWorkbook();
+               Sheet s = wb1.createSheet("testSheet1");
+               Row r;
+               Cell c;
+
+               // B1
                r = s.createRow(1);
                c=r.createCell(1);
-               //c.setCellType(HSSFCell.CELL_TYPE_ERROR);
-               c.setCellErrorValue((byte)0);
+               assumeTrue(0 == c.getRowIndex());
+               assumeTrue(1 == c.getColumnIndex());
+               c.setCellErrorValue(FormulaError.NULL.getCode());
 
+               // C1
                c=r.createCell(2);
-               //c.setCellType(HSSFCell.CELL_TYPE_ERROR);
-               c.setCellErrorValue((byte)7);
+               assumeTrue(0 == c.getRowIndex());
+               assumeTrue(2 == c.getColumnIndex());
+               c.setCellErrorValue(FormulaError.DIV0.getCode());
 
                Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
                wb1.close();
-               s = wb2.getSheetAt(0);
+
+               s = wb2.getSheet("testSheet1");
+
                r = s.getRow(0);
+               assumeTrue("Row 1 should have 2 cells", 2 == r.getPhysicalNumberOfCells());
+
                c = r.getCell(1);
-               assertTrue("boolean value 0,1 = true",c.getBooleanCellValue());
-               c = r.getCell(2);
-               assertTrue("boolean value 0,2 = false",c.getBooleanCellValue()==false);
-               r = s.getRow(1);
-               c = r.getCell(1);
-               assertTrue("boolean value 0,1 = 0",c.getErrorCellValue() == 0);
+               assertEquals(Cell.CELL_TYPE_ERROR, c.getCellType());
+               assertEquals("B2 value == #NULL!", FormulaError.NULL.getCode(), c.getErrorCellValue());
+
                c = r.getCell(2);
-               assertTrue("boolean value 0,2 = 7",c.getErrorCellValue() == 7);
+               assertEquals(Cell.CELL_TYPE_ERROR, c.getCellType());
+               assertEquals("C2 value == #DIV/0!", FormulaError.DIV0.getCode(), c.getErrorCellValue());
+
                wb2.close();
        }