]> source.dussan.org Git - poi.git/commitdiff
Improved test coverage for *Cell classes
authorVladislav Galas <gallon@apache.org>
Fri, 4 Jan 2019 09:17:48 +0000 (09:17 +0000)
committerVladislav Galas <gallon@apache.org>
Fri, 4 Jan 2019 09:17:48 +0000 (09:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1850338 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java

index c027123a8ac8e9adff8822e7311c81a9ef510df9..d5f4b243d1d9a0078ffefaa43c0b63fee044bf10 100644 (file)
 package org.apache.poi.xssf.streaming;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import java.io.IOException;
 
 import javax.xml.namespace.QName;
 
+import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.usermodel.BaseTestXCell;
 import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.FormulaError;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.RichTextString;
 import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.SXSSFITestDataProvider;
 import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.xmlbeans.XmlCursor;
 import org.junit.AfterClass;
 import org.junit.Test;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
 
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
 /**
  * Tests various functionality having to do with {@link SXSSFCell}.  For instance support for
  * particular datatypes, etc.
@@ -49,7 +59,7 @@ public class TestSXSSFCell extends BaseTestXCell {
     }
 
     @AfterClass
-    public static void tearDownClass(){
+    public static void tearDownClass() {
         SXSSFITestDataProvider.instance.cleanup();
     }
 
@@ -69,7 +79,7 @@ public class TestSXSSFCell extends BaseTestXCell {
             assertEquals(sCell.getStringCellValue(), str);
 
             // read back as XSSF and check that xml:spaces="preserve" is set
-            XSSFWorkbook xwb = (XSSFWorkbook)_testDataProvider.writeOutAndReadBack(swb);
+            XSSFWorkbook xwb = (XSSFWorkbook) _testDataProvider.writeOutAndReadBack(swb);
             XSSFCell xCell = xwb.getSheetAt(0).getRow(0).getCell(0);
 
             CTRst is = xCell.getCTCell().getIs();
@@ -83,4 +93,57 @@ public class TestSXSSFCell extends BaseTestXCell {
             swb.close();
         }
     }
+
+    @Test
+    public void getCellTypeEnumDelegatesToGetCellType() {
+        SXSSFCell instance = spy(new SXSSFCell(null, CellType.BLANK));
+        CellType result = instance.getCellTypeEnum();
+        verify(instance).getCellType();
+        assertEquals(CellType.BLANK, result);
+    }
+
+    @Test
+    public void getCachedFormulaResultTypeEnum_delegatesTo_getCachedFormulaResultType() {
+        SXSSFCell instance = spy(new SXSSFCell(null, CellType.BLANK));
+        instance.setCellFormula("");
+        instance.getCachedFormulaResultTypeEnum();
+        verify(instance).getCachedFormulaResultType();
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void getCachedFormulaResultType_throwsISE_whenNotAFormulaCell() {
+        SXSSFCell instance = new SXSSFCell(null, CellType.BLANK);
+        instance.getCachedFormulaResultType();
+    }
+
+
+    @Test(expected = IllegalArgumentException.class)
+    public void setCellValue_withTooLongRichTextString_throwsIAE() {
+        Cell cell = spy(new SXSSFCell(null, CellType.BLANK));
+        RichTextString string = spy(new XSSFRichTextString(""));
+        doReturn(SpreadsheetVersion.EXCEL2007.getMaxTextLength() + 1).when(string).length();
+        cell.setCellValue(string);
+    }
+
+    @Test
+    public void getArrayFormulaRange_returnsNull() {
+        Cell cell = new SXSSFCell(null, CellType.BLANK);
+        CellRangeAddress result = cell.getArrayFormulaRange();
+        assertNull(result);
+    }
+
+    @Test
+    public void isPartOfArrayFormulaGroup_returnsFalse() {
+        Cell cell = new SXSSFCell(null, CellType.BLANK);
+        boolean result = cell.isPartOfArrayFormulaGroup();
+        assertFalse(result);
+    }
+
+    @Test
+    public void getErrorCellValue_returns0_onABlankCell() {
+        Cell cell = new SXSSFCell(null, CellType.BLANK);
+        assertEquals(CellType.BLANK, cell.getCellType());
+        byte result = cell.getErrorCellValue();
+        assertEquals(0, result);
+    }
 }
index 7d78848a29a2f12e59c573e5accb337dae718a95..b044e97c0681d546c559fc34d4262805cb56dfea 100644 (file)
@@ -744,6 +744,11 @@ public final class TestXSSFCell extends BaseTestXCell {
             assertEquals("C13:G13", sheet.getSharedFormula(0).getRef());
 
         }
+    }
 
+    @Test(expected = IllegalStateException.class)
+    public void getErrorCellValue_returns0_onABlankCell() {
+        Cell cell = new XSSFWorkbook().createSheet().createRow(0).createCell(0);
+        cell.getErrorCellValue();
     }
 }
index 7fe5f09224cd2f3c2046f050bd51d4bf3e13e11c..b4200df08771d026a3be4cea40a342e2ee874771 100644 (file)
@@ -472,4 +472,10 @@ public final class TestHSSFCell extends BaseTestCell {
         cell.setCellValue((RichTextString)null);
         wb.close();
     }
+
+       @Test(expected = IllegalStateException.class)
+       public void getErrorCellValue_throwsISE_onABlankCell() {
+               Cell cell = new HSSFWorkbook().createSheet().createRow(0).createCell(0);
+               cell.getErrorCellValue();
+       }
 }
index fb8f81b065486c84ab5bb6df19c505648182f770..eab4222ba38840a0e94e5203c223ba7658f09547 100644 (file)
@@ -1140,4 +1140,20 @@ public abstract class BaseTestCell {
         assertEquals(CellType.BLANK, cell.getCellType());
         assertEquals(0, cell.getNumericCellValue(), 0);
     }
+
+    @Test
+    public void getDateCellValue_returnsNull_onABlankCell() {
+        Cell cell = _testDataProvider.createWorkbook().createSheet().createRow(0).createCell(0);
+        assertEquals(CellType.BLANK, cell.getCellType());
+        Date result = cell.getDateCellValue();
+        assertNull(result);
+    }
+
+    @Test
+    public void getBooleanCellValue_returnsFalse_onABlankCell() {
+        Cell cell = _testDataProvider.createWorkbook().createSheet().createRow(0).createCell(0);
+        assertEquals(CellType.BLANK, cell.getCellType());
+        boolean result = cell.getBooleanCellValue();
+        assertFalse(result);
+    }
 }