aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/testcases/org/apache
diff options
context:
space:
mode:
authorVladislav Galas <gallon@apache.org>2019-01-04 09:17:48 +0000
committerVladislav Galas <gallon@apache.org>2019-01-04 09:17:48 +0000
commit8600f648904ed6ef5e21c1009f48955d8ada89f3 (patch)
treecc9ecf6afbe6176847c3d0b8c39f78b2f8d5fd89 /src/ooxml/testcases/org/apache
parent3b8055baa0a26e48c8e5cfecbe6120a147da7777 (diff)
downloadpoi-8600f648904ed6ef5e21c1009f48955d8ada89f3.tar.gz
poi-8600f648904ed6ef5e21c1009f48955d8ada89f3.zip
Improved test coverage for *Cell classes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1850338 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases/org/apache')
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java69
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java5
2 files changed, 71 insertions, 3 deletions
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();
}
}