From: Vladislav Galas Date: Fri, 4 Jan 2019 09:17:48 +0000 (+0000) Subject: Improved test coverage for *Cell classes X-Git-Tag: REL_4_1_0~124 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8600f648904ed6ef5e21c1009f48955d8ada89f3;p=poi.git Improved test coverage for *Cell classes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1850338 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java index c027123a8a..d5f4b243d1 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java @@ -20,24 +20,34 @@ 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); + } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java index 7d78848a29..b044e97c06 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java @@ -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(); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index 7fe5f09224..b4200df087 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -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(); + } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index fb8f81b065..eab4222ba3 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -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); + } }