mirror of https://github.com/apache/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
This commit is contained in:
parent
3b8055baa0
commit
8600f64890
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue