diff options
author | Javen O'Neal <onealj@apache.org> | 2016-07-04 09:45:46 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2016-07-04 09:45:46 +0000 |
commit | fb8c79d96c2f0ddffb13f5b96c0f65b66c77ce5f (patch) | |
tree | 969ae610e5625f89327a7c90c8e112db46e769f0 /src/testcases/org | |
parent | 77bf864c07485013123d93d0a152e00906a40742 (diff) | |
download | poi-fb8c79d96c2f0ddffb13f5b96c0f65b66c77ce5f.tar.gz poi-fb8c79d96c2f0ddffb13f5b96c0f65b66c77ce5f.zip |
bug 59791: convert Cell Type to an enum
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751237 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
11 files changed, 269 insertions, 257 deletions
diff --git a/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java index 82fc4d6927..2f6a14b769 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java @@ -17,12 +17,12 @@ package org.apache.poi.hssf.record; -import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.ss.formula.ptg.AttrPtg; import org.apache.poi.ss.formula.ptg.FuncVarPtg; import org.apache.poi.ss.formula.ptg.IntPtg; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.RefPtg; +import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.FormulaError; import junit.framework.AssertionFailedError; @@ -83,7 +83,7 @@ public final class TestFormulaRecord extends TestCase { FormulaRecord record = new FormulaRecord(TestcaseRecordInputStream.create(FormulaRecord.sid, formulaByte)); assertEquals("Row", 0, record.getRow()); assertEquals("Column", 0, record.getColumn()); - assertEquals(HSSFCell.CELL_TYPE_ERROR, record.getCachedResultType()); + assertEquals(CellType.ERROR.getCode(), record.getCachedResultType()); byte[] output = record.serialize(); assertEquals("Output size", 33, output.length); //includes sid+recordlength diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index a65721151b..d588115b65 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -72,6 +72,7 @@ import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.FormulaEvaluator; @@ -173,7 +174,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { cell = row.createCell(3); // Write test - cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(CellType.STRING); setCellText(cell, "a test"); // change existing numeric cell value @@ -468,7 +469,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFRow row = sheet.getRow(i); if (row != null) { HSSFCell cell = row .getCell(0); - assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType()); + assertEquals(CellType.STRING, cell.getCellType()); count++; } } @@ -1111,7 +1112,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { c3.getNumericCellValue(); fail("exception should have been thrown"); } catch (IllegalStateException e) { - assertEquals("Cannot get a numeric value from a text formula cell", e.getMessage()); + assertEquals("Cannot get a NUMERIC value from a STRING formula cell", e.getMessage()); } @@ -1166,13 +1167,13 @@ public final class TestBugs extends BaseTestBugzillaIssues { } private static void confirmCachedValue(double expectedValue, HSSFCell cell) { - assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType()); - assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType()); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType()); assertEquals(expectedValue, cell.getNumericCellValue(), 0.0); } private static void confirmCachedValue(String expectedValue, HSSFCell cell) { - assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType()); - assertEquals(Cell.CELL_TYPE_STRING, cell.getCachedFormulaResultType()); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(CellType.STRING, cell.getCachedFormulaResultType()); assertEquals(expectedValue, cell.getRichStringCellValue().getString()); } @@ -1287,7 +1288,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { s = wb.getSheet("OneVariable Table Completed"); r = s.getRow(3); c = r.getCell(4); - assertEquals(Cell.CELL_TYPE_FORMULA, c.getCellType()); + assertEquals(CellType.FORMULA, c.getCellType()); // TODO - check the formula once tables and // arrays are properly supported @@ -1297,7 +1298,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { s = wb.getSheet("TwoVariable Table Example"); r = s.getRow(3); c = r.getCell(4); - assertEquals(Cell.CELL_TYPE_FORMULA, c.getCellType()); + assertEquals(CellType.FORMULA, c.getCellType()); // TODO - check the formula once tables and // arrays are properly supported @@ -1823,26 +1824,26 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFRow row; row = s.getRow(0); - assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType()); + assertEquals(CellType.NUMERIC, row.getCell(1).getCellType()); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); row = s.getRow(1); - assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType()); + assertEquals(CellType.FORMULA, row.getCell(1).getCellType()); assertEquals("B1", row.getCell(1).getCellFormula()); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); row = s.getRow(2); - assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType()); + assertEquals(CellType.FORMULA, row.getCell(1).getCellType()); assertEquals("Sheet1!B1", row.getCell(1).getCellFormula()); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); row = s.getRow(3); - assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType()); + assertEquals(CellType.FORMULA, row.getCell(1).getCellType()); assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula()); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); row = s.getRow(4); - assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType()); + assertEquals(CellType.FORMULA, row.getCell(1).getCellType()); assertEquals("'[$http://gagravarr.org/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula()); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); @@ -1852,7 +1853,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { // Add 5 row = s.createRow(5); - row.createCell(1, Cell.CELL_TYPE_FORMULA); + row.createCell(1, CellType.FORMULA); row.getCell(1).setCellFormula("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1"); row.getCell(1).setCellValue(234.0); @@ -1863,32 +1864,32 @@ public final class TestBugs extends BaseTestBugzillaIssues { s = wb2.getSheetAt(0); row = s.getRow(0); - assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType()); + assertEquals(CellType.NUMERIC, row.getCell(1).getCellType()); assertEquals(112.0, row.getCell(1).getNumericCellValue(),0); row = s.getRow(1); - assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType()); + assertEquals(CellType.FORMULA, row.getCell(1).getCellType()); assertEquals("B1", row.getCell(1).getCellFormula()); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); row = s.getRow(2); - assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType()); + assertEquals(CellType.FORMULA, row.getCell(1).getCellType()); assertEquals("Sheet1!B1", row.getCell(1).getCellFormula()); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); row = s.getRow(3); - assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType()); + assertEquals(CellType.FORMULA, row.getCell(1).getCellType()); assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula()); assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); // TODO - Fix these so they work... /*row = s.getRow(4); - assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType()); + assertEquals(CellType.FORMULA, row.getCell(1).getCellType()); assertEquals("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2", row.getCell(1).getCellFormula()); assertEquals(123.0, row.getCell(1).getNumericCellValue(), 0); row = s.getRow(5); - assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType()); + assertEquals(CellType.FORMULA, row.getCell(1).getCellType()); assertEquals("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula()); assertEquals(234.0, row.getCell(1).getNumericCellValue(), 0);*/ @@ -2087,13 +2088,13 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFWorkbook workbook = new HSSFWorkbook(); Sheet sheet = workbook.createSheet("Bug50416"); Row row1 = sheet.createRow(0); - Cell cellA_1 = row1.createCell(0,Cell.CELL_TYPE_STRING); + Cell cellA_1 = row1.createCell(0,CellType.STRING); cellA_1.setCellValue("Cell A,1"); Row row2 = sheet.createRow(1); - Cell cellA_2 = row2.createCell(0,Cell.CELL_TYPE_STRING); + Cell cellA_2 = row2.createCell(0,CellType.STRING); cellA_2.setCellValue("Cell A,2"); Row row3 = sheet.createRow(2); - Cell cellA_3 = row3.createCell(0,Cell.CELL_TYPE_STRING); + Cell cellA_3 = row3.createCell(0,CellType.STRING); cellA_3.setCellValue("Cell A,3"); // Test the last Row number it currently correct @@ -2541,7 +2542,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { row.createCell(2).setCellValue(cal); row.createCell(3).setCellValue(String.format(Locale.ROOT, "row:%d/col:%d", r, 3)); row.createCell(4).setCellValue(true); - row.createCell(5).setCellType(Cell.CELL_TYPE_ERROR); + row.createCell(5).setCellType(CellType.ERROR); row.createCell(6).setCellValue("added cells."); } @@ -2754,13 +2755,13 @@ public final class TestBugs extends BaseTestBugzillaIssues { } private void assertFormula(Workbook wb, Cell intF, String expectedFormula, String expectedResultOrNull) { - assertEquals(Cell.CELL_TYPE_FORMULA, intF.getCellType()); + assertEquals(CellType.FORMULA, intF.getCellType()); if (null == expectedResultOrNull) { - assertEquals(Cell.CELL_TYPE_ERROR, intF.getCachedFormulaResultType()); + assertEquals(CellType.ERROR, intF.getCachedFormulaResultType()); expectedResultOrNull = "#VALUE!"; } else { - assertEquals(Cell.CELL_TYPE_NUMERIC, intF.getCachedFormulaResultType()); + assertEquals(CellType.NUMERIC, intF.getCachedFormulaResultType()); } assertEquals(expectedFormula, intF.getCellFormula()); @@ -2986,12 +2987,12 @@ public final class TestBugs extends BaseTestBugzillaIssues { Sheet sheet = wb.getSheetAt(0); Row row = sheet.getRow(0); Cell cell = row.getCell(0); - assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType()); + assertEquals(CellType.FORMULA, cell.getCellType()); assertEquals("IF(TRUE,\"\",\"\")", cell.getCellFormula()); assertEquals("", cell.getStringCellValue()); - cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(CellType.STRING); - assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType()); + assertEquals(CellType.BLANK, cell.getCellType()); try { assertNull(cell.getCellFormula()); fail("Should throw an exception here"); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index 1ac9e5d112..ed27a21f9e 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -36,6 +36,7 @@ import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.StringRecord; import org.apache.poi.ss.usermodel.BaseTestCell; import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.FormulaError; import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.usermodel.Row; @@ -417,14 +418,7 @@ public final class TestHSSFCell extends BaseTestCell { cell.getCachedFormulaResultType(); fail("Should catch exception"); } catch (IllegalStateException e) { - // expected here - } - - try { - assertNotNull(new HSSFCell(wb, sheet, 0, (short)0, Cell.CELL_TYPE_ERROR+1 )); - fail("Should catch exception"); - } catch (RuntimeException e) { - // expected here + // expected here } cell.removeCellComment(); @@ -440,36 +434,36 @@ public final class TestHSSFCell extends BaseTestCell { Row row = sheet.createRow(0); Cell cell = row.createCell(0); - cell.setCellType(Cell.CELL_TYPE_BLANK); + cell.setCellType(CellType.BLANK); assertNull(null, cell.getDateCellValue()); assertFalse(cell.getBooleanCellValue()); assertEquals("", cell.toString()); - cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(CellType.STRING); assertEquals("", cell.toString()); - cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(CellType.STRING); cell.setCellValue(1.2); - cell.setCellType(Cell.CELL_TYPE_NUMERIC); + cell.setCellType(CellType.NUMERIC); assertEquals("1.2", cell.toString()); - cell.setCellType(Cell.CELL_TYPE_BOOLEAN); + cell.setCellType(CellType.BOOLEAN); assertEquals("TRUE", cell.toString()); - cell.setCellType(Cell.CELL_TYPE_BOOLEAN); + cell.setCellType(CellType.BOOLEAN); cell.setCellValue("" + FormulaError.VALUE.name()); - cell.setCellType(Cell.CELL_TYPE_ERROR); + cell.setCellType(CellType.ERROR); assertEquals("#VALUE!", cell.toString()); - cell.setCellType(Cell.CELL_TYPE_ERROR); - cell.setCellType(Cell.CELL_TYPE_BOOLEAN); + cell.setCellType(CellType.ERROR); + cell.setCellType(CellType.BOOLEAN); assertEquals("FALSE", cell.toString()); cell.setCellValue(1.2); - cell.setCellType(Cell.CELL_TYPE_NUMERIC); + cell.setCellType(CellType.NUMERIC); assertEquals("1.2", cell.toString()); - cell.setCellType(Cell.CELL_TYPE_BOOLEAN); - cell.setCellType(Cell.CELL_TYPE_STRING); - cell.setCellType(Cell.CELL_TYPE_ERROR); - cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(CellType.BOOLEAN); + cell.setCellType(CellType.STRING); + cell.setCellType(CellType.ERROR); + cell.setCellType(CellType.STRING); cell.setCellValue(1.2); - cell.setCellType(Cell.CELL_TYPE_NUMERIC); - cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(CellType.NUMERIC); + cell.setCellType(CellType.STRING); assertEquals("1.2", cell.toString()); cell.setCellValue((String)null); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java index 64bfb23701..405347a9bc 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java @@ -30,7 +30,7 @@ import org.apache.poi.hssf.record.BackupRecord; import org.apache.poi.hssf.record.LabelSSTRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor; -import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; @@ -384,16 +384,15 @@ public final class TestWorkbook { * OBJECTIVE: Test that HSSF can read a simple spreadsheet with and RKRecord and correctly * identify the cell as numeric and convert it to a NumberRecord. <P> * SUCCESS: HSSF reads a sheet. HSSF returns that the cell is a numeric type cell. <P> - * FAILURE: HSSF does not read a sheet or excepts. HSSF incorrectly indentifies the cell<P> + * FAILURE: HSSF does not read a sheet or excepts. HSSF incorrectly identifies the cell<P> */ @Test public void testReadSheetWithRK() throws IOException { HSSFWorkbook wb = openSample("rk.xls"); HSSFSheet s = wb.getSheetAt(0); HSSFCell c = s.getRow(0).getCell(0); - int a = c.getCellType(); - assertEquals(a, Cell.CELL_TYPE_NUMERIC); + assertEquals(CellType.NUMERIC, c.getCellType()); wb.close(); } diff --git a/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java b/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java index 6afcc445e3..18f79f1a69 100644 --- a/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java +++ b/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java @@ -42,6 +42,7 @@ import org.apache.poi.ss.formula.ptg.IntPtg; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.RefErrorPtg; import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Name; @@ -200,7 +201,7 @@ public class TestWorkbookEvaluator { } catch (RuntimeException e) { fail("Missing arg result not being handled correctly."); } - assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType()); + assertEquals(CellType.NUMERIC, cv.getCellType()); // adding blank to 1.0 gives 1.0 assertEquals(1.0, cv.getNumberValue(), 0.0); @@ -208,7 +209,7 @@ public class TestWorkbookEvaluator { cell.setCellFormula("\"abc\"&IF(1,,)"); fe.notifySetFormula(cell); cv = fe.evaluate(cell); - assertEquals(HSSFCell.CELL_TYPE_STRING, cv.getCellType()); + assertEquals(CellType.STRING, cv.getCellType()); // adding blank to "abc" gives "abc" assertEquals("abc", cv.getStringValue()); @@ -216,7 +217,7 @@ public class TestWorkbookEvaluator { cell.setCellFormula("\"abc\"&CHOOSE(2,5,,9)"); fe.notifySetFormula(cell); cv = fe.evaluate(cell); - assertEquals(HSSFCell.CELL_TYPE_STRING, cv.getCellType()); + assertEquals(CellType.STRING, cv.getCellType()); // adding blank to "abc" gives "abc" assertEquals("abc", cv.getStringValue()); } @@ -242,14 +243,14 @@ public class TestWorkbookEvaluator { } throw new RuntimeException(e); } - assertEquals(Cell.CELL_TYPE_ERROR, cv.getCellType()); + assertEquals(CellType.ERROR, cv.getCellType()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), cv.getErrorValue()); // verify circular refs are still detected properly fe.clearAllCachedResultValues(); cell.setCellFormula("OFFSET(A1,0,0)"); cv = fe.evaluate(cell); - assertEquals(Cell.CELL_TYPE_ERROR, cv.getCellType()); + assertEquals(CellType.ERROR, cv.getCellType()); assertEquals(ErrorEval.CIRCULAR_REF_ERROR.getErrorCode(), cv.getErrorValue()); } finally { wb.close(); @@ -304,7 +305,7 @@ public class TestWorkbookEvaluator { // Test IF-Equals Formula Evaluation (bug 58591) - private Workbook testIFEqualsFormulaEvaluation_setup(String formula, int a1CellType) { + private Workbook testIFEqualsFormulaEvaluation_setup(String formula, CellType a1CellType) { Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("IFEquals"); Row row = sheet.createRow(0); @@ -314,27 +315,29 @@ public class TestWorkbookEvaluator { Cell D1 = row.createCell(3); switch (a1CellType) { - case Cell.CELL_TYPE_NUMERIC: + case NUMERIC: A1.setCellValue(1.0); // "A1=1" should return true break; - case Cell.CELL_TYPE_STRING: + case STRING: A1.setCellValue("1"); // "A1=1" should return false // "A1=\"1\"" should return true break; - case Cell.CELL_TYPE_BOOLEAN: + case BOOLEAN: A1.setCellValue(true); // "A1=1" should return true break; - case Cell.CELL_TYPE_FORMULA: + case FORMULA: A1.setCellFormula("1"); // "A1=1" should return true break; - case Cell.CELL_TYPE_BLANK: + case BLANK: A1.setCellValue((String) null); // "A1=1" should return false break; + default: + throw new IllegalArgumentException("unexpected cell type: " + a1CellType); } B1.setCellValue(2.0); C1.setCellValue(3.0); @@ -354,7 +357,7 @@ public class TestWorkbookEvaluator { private void testIFEqualsFormulaEvaluation_evaluate( - String formula, int cellType, String expectedFormula, double expectedResult) { + String formula, CellType cellType, String expectedFormula, double expectedResult) { Workbook wb = testIFEqualsFormulaEvaluation_setup(formula, cellType); Cell D1 = wb.getSheet("IFEquals").getRow(0).getCell(3); @@ -362,17 +365,17 @@ public class TestWorkbookEvaluator { CellValue result = eval.evaluate(D1); // Call should not modify the contents - assertEquals(Cell.CELL_TYPE_FORMULA, D1.getCellType()); + assertEquals(CellType.FORMULA, D1.getCellType()); assertEquals(expectedFormula, D1.getCellFormula()); - assertEquals(Cell.CELL_TYPE_NUMERIC, result.getCellType()); + assertEquals(CellType.NUMERIC, result.getCellType()); assertEquals(expectedResult, result.getNumberValue(), EPSILON); testIFEqualsFormulaEvaluation_teardown(wb); } private void testIFEqualsFormulaEvaluation_eval( - final String formula, final int cellType, final String expectedFormula, final double expectedValue) { + final String formula, final CellType cellType, final String expectedFormula, final double expectedValue) { testIFEqualsFormulaEvaluation_evaluate(formula, cellType, expectedFormula, expectedValue); testIFEqualsFormulaEvaluation_evaluateFormulaCell(formula, cellType, expectedFormula, expectedValue); testIFEqualsFormulaEvaluation_evaluateInCell(formula, cellType, expectedFormula, expectedValue); @@ -383,7 +386,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_NumericLiteral() { final String formula = "IF(A1=1, 2, 3)"; - final int cellType = Cell.CELL_TYPE_NUMERIC; + final CellType cellType = CellType.NUMERIC; final String expectedFormula = "IF(A1=1,2,3)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -392,7 +395,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_Numeric() { final String formula = "IF(A1=1, B1, C1)"; - final int cellType = Cell.CELL_TYPE_NUMERIC; + final CellType cellType = CellType.NUMERIC; final String expectedFormula = "IF(A1=1,B1,C1)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -401,7 +404,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_NumericCoerceToString() { final String formula = "IF(A1&\"\"=\"1\", B1, C1)"; - final int cellType = Cell.CELL_TYPE_NUMERIC; + final CellType cellType = CellType.NUMERIC; final String expectedFormula = "IF(A1&\"\"=\"1\",B1,C1)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -410,7 +413,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_String() { final String formula = "IF(A1=1, B1, C1)"; - final int cellType = Cell.CELL_TYPE_STRING; + final CellType cellType = CellType.STRING; final String expectedFormula = "IF(A1=1,B1,C1)"; final double expectedValue = 3.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -419,7 +422,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_StringCompareToString() { final String formula = "IF(A1=\"1\", B1, C1)"; - final int cellType = Cell.CELL_TYPE_STRING; + final CellType cellType = CellType.STRING; final String expectedFormula = "IF(A1=\"1\",B1,C1)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -428,7 +431,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_StringCoerceToNumeric() { final String formula = "IF(A1+0=1, B1, C1)"; - final int cellType = Cell.CELL_TYPE_STRING; + final CellType cellType = CellType.STRING; final String expectedFormula = "IF(A1+0=1,B1,C1)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -438,7 +441,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_Boolean() { final String formula = "IF(A1=1, B1, C1)"; - final int cellType = Cell.CELL_TYPE_BOOLEAN; + final CellType cellType = CellType.BOOLEAN; final String expectedFormula = "IF(A1=1,B1,C1)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -448,7 +451,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_BooleanSimple() { final String formula = "3-(A1=1)"; - final int cellType = Cell.CELL_TYPE_BOOLEAN; + final CellType cellType = CellType.BOOLEAN; final String expectedFormula = "3-(A1=1)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -457,7 +460,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_Formula() { final String formula = "IF(A1=1, B1, C1)"; - final int cellType = Cell.CELL_TYPE_FORMULA; + final CellType cellType = CellType.FORMULA; final String expectedFormula = "IF(A1=1,B1,C1)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -466,7 +469,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_Blank() { final String formula = "IF(A1=1, B1, C1)"; - final int cellType = Cell.CELL_TYPE_BLANK; + final CellType cellType = CellType.BLANK; final String expectedFormula = "IF(A1=1,B1,C1)"; final double expectedValue = 3.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -475,7 +478,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_BlankCompareToZero() { final String formula = "IF(A1=0, B1, C1)"; - final int cellType = Cell.CELL_TYPE_BLANK; + final CellType cellType = CellType.BLANK; final String expectedFormula = "IF(A1=0,B1,C1)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -485,7 +488,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_BlankInverted() { final String formula = "IF(NOT(A1)=1, B1, C1)"; - final int cellType = Cell.CELL_TYPE_BLANK; + final CellType cellType = CellType.BLANK; final String expectedFormula = "IF(NOT(A1)=1,B1,C1)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -495,7 +498,7 @@ public class TestWorkbookEvaluator { @Test public void testIFEqualsFormulaEvaluation_BlankInvertedSimple() { final String formula = "3-(NOT(A1)=1)"; - final int cellType = Cell.CELL_TYPE_BLANK; + final CellType cellType = CellType.BLANK; final String expectedFormula = "3-(NOT(A1)=1)"; final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); @@ -503,25 +506,25 @@ public class TestWorkbookEvaluator { private void testIFEqualsFormulaEvaluation_evaluateFormulaCell( - String formula, int cellType, String expectedFormula, double expectedResult) { + String formula, CellType cellType, String expectedFormula, double expectedResult) { Workbook wb = testIFEqualsFormulaEvaluation_setup(formula, cellType); Cell D1 = wb.getSheet("IFEquals").getRow(0).getCell(3); FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator(); - int resultCellType = eval.evaluateFormulaCell(D1); + CellType resultCellType = eval.evaluateFormulaCell(D1); // Call should modify the contents, but leave the formula intact - assertEquals(Cell.CELL_TYPE_FORMULA, D1.getCellType()); + assertEquals(CellType.FORMULA, D1.getCellType()); assertEquals(expectedFormula, D1.getCellFormula()); - assertEquals(Cell.CELL_TYPE_NUMERIC, resultCellType); - assertEquals(Cell.CELL_TYPE_NUMERIC, D1.getCachedFormulaResultType()); + assertEquals(CellType.NUMERIC, resultCellType); + assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultType()); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); testIFEqualsFormulaEvaluation_teardown(wb); } private void testIFEqualsFormulaEvaluation_evaluateInCell( - String formula, int cellType, String expectedFormula, double expectedResult) { + String formula, CellType cellType, String expectedFormula, double expectedResult) { Workbook wb = testIFEqualsFormulaEvaluation_setup(formula, cellType); Cell D1 = wb.getSheet("IFEquals").getRow(0).getCell(3); @@ -534,14 +537,14 @@ public class TestWorkbookEvaluator { D1.getCellFormula(); fail("cell formula should be overwritten with formula result"); } catch (final IllegalStateException expected) { } - assertEquals(Cell.CELL_TYPE_NUMERIC, D1.getCellType()); + assertEquals(CellType.NUMERIC, D1.getCellType()); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); testIFEqualsFormulaEvaluation_teardown(wb); } private void testIFEqualsFormulaEvaluation_evaluateAll( - String formula, int cellType, String expectedFormula, double expectedResult) { + String formula, CellType cellType, String expectedFormula, double expectedResult) { Workbook wb = testIFEqualsFormulaEvaluation_setup(formula, cellType); Cell D1 = wb.getSheet("IFEquals").getRow(0).getCell(3); @@ -549,28 +552,28 @@ public class TestWorkbookEvaluator { eval.evaluateAll(); // Call should modify the contents - assertEquals(Cell.CELL_TYPE_FORMULA, D1.getCellType()); + assertEquals(CellType.FORMULA, D1.getCellType()); assertEquals(expectedFormula, D1.getCellFormula()); - assertEquals(Cell.CELL_TYPE_NUMERIC, D1.getCachedFormulaResultType()); + assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultType()); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); testIFEqualsFormulaEvaluation_teardown(wb); } private void testIFEqualsFormulaEvaluation_evaluateAllFormulaCells( - String formula, int cellType, String expectedFormula, double expectedResult) { + String formula, CellType cellType, String expectedFormula, double expectedResult) { Workbook wb = testIFEqualsFormulaEvaluation_setup(formula, cellType); Cell D1 = wb.getSheet("IFEquals").getRow(0).getCell(3); HSSFFormulaEvaluator.evaluateAllFormulaCells(wb); // Call should modify the contents - assertEquals(Cell.CELL_TYPE_FORMULA, D1.getCellType()); + assertEquals(CellType.FORMULA, D1.getCellType()); // whitespace gets deleted because formula is parsed and re-rendered assertEquals(expectedFormula, D1.getCellFormula()); - assertEquals(Cell.CELL_TYPE_NUMERIC, D1.getCachedFormulaResultType()); + assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultType()); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); testIFEqualsFormulaEvaluation_teardown(wb); diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java index 85ddfe01c3..8457a07d94 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java @@ -31,6 +31,7 @@ import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.functions.TestMathX; import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -173,7 +174,7 @@ public final class TestFormulasFromSpreadsheet { // iterate across the row for all the evaluation cases for (int colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) { Cell c = formulasRow.getCell(colnum); - if (c == null || c.getCellType() != Cell.CELL_TYPE_FORMULA) { + if (c == null || c.getCellType() != CellType.FORMULA) { continue; } @@ -186,28 +187,31 @@ public final class TestFormulasFromSpreadsheet { assertNotNull(msg + " - Bad setup data expected value is null", expValue); assertNotNull(msg + " - actual value was null", actValue); - switch (expValue.getCellType()) { - case Cell.CELL_TYPE_BLANK: - assertEquals(msg, Cell.CELL_TYPE_BLANK, actValue.getCellType()); + final CellType cellType = expValue.getCellType(); + switch (cellType) { + case BLANK: + assertEquals(msg, CellType.BLANK, actValue.getCellType()); break; - case Cell.CELL_TYPE_BOOLEAN: - assertEquals(msg, Cell.CELL_TYPE_BOOLEAN, actValue.getCellType()); + case BOOLEAN: + assertEquals(msg, CellType.BOOLEAN, actValue.getCellType()); assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue()); break; - case Cell.CELL_TYPE_ERROR: - assertEquals(msg, Cell.CELL_TYPE_ERROR, actValue.getCellType()); + case ERROR: + assertEquals(msg, CellType.ERROR, actValue.getCellType()); assertEquals(msg, ErrorEval.getText(expValue.getErrorCellValue()), ErrorEval.getText(actValue.getErrorValue())); break; - case Cell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation + case FORMULA: // will never be used, since we will call method after formula evaluation fail("Cannot expect formula as result of formula evaluation: " + msg); - case Cell.CELL_TYPE_NUMERIC: - assertEquals(msg, Cell.CELL_TYPE_NUMERIC, actValue.getCellType()); + case NUMERIC: + assertEquals(msg, CellType.NUMERIC, actValue.getCellType()); TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); break; - case Cell.CELL_TYPE_STRING: - assertEquals(msg, Cell.CELL_TYPE_STRING, actValue.getCellType()); + case STRING: + assertEquals(msg, CellType.STRING, actValue.getCellType()); assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue()); break; + default: + fail("Unexpected cell type: " + cellType); } } } @@ -224,10 +228,10 @@ public final class TestFormulasFromSpreadsheet { System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name"); return null; } - if(cell.getCellType() == Cell.CELL_TYPE_BLANK) { + if(cell.getCellType() == CellType.BLANK) { return null; } - if(cell.getCellType() == Cell.CELL_TYPE_STRING) { + if(cell.getCellType() == CellType.STRING) { return cell.getRichStringCellValue().getString(); } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java index 9e52a4efd7..bb9b6a85ba 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java @@ -30,6 +30,7 @@ import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.functions.TestMathX; import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -104,29 +105,33 @@ public final class TestMultiSheetEval extends TestCase { if(actual == null) { throw new AssertionFailedError(msg + " - actual value was null"); } + + final CellType cellType = expected.getCellType(); - switch (expected.getCellType()) { - case Cell.CELL_TYPE_BLANK: - assertEquals(msg, Cell.CELL_TYPE_BLANK, actual.getCellType()); + switch (cellType) { + case BLANK: + assertEquals(msg, CellType.BLANK, actual.getCellType()); break; - case Cell.CELL_TYPE_BOOLEAN: - assertEquals(msg, Cell.CELL_TYPE_BOOLEAN, actual.getCellType()); + case BOOLEAN: + assertEquals(msg, CellType.BOOLEAN, actual.getCellType()); assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue()); break; - case Cell.CELL_TYPE_ERROR: - assertEquals(msg, Cell.CELL_TYPE_ERROR, actual.getCellType()); + case ERROR: + assertEquals(msg, CellType.ERROR, actual.getCellType()); assertEquals(msg, ErrorEval.getText(expected.getErrorCellValue()), ErrorEval.getText(actual.getErrorValue())); break; - case Cell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation + case FORMULA: // will never be used, since we will call method after formula evaluation throw new AssertionFailedError("Cannot expect formula as result of formula evaluation: " + msg); - case Cell.CELL_TYPE_NUMERIC: - assertEquals(msg, Cell.CELL_TYPE_NUMERIC, actual.getCellType()); + case NUMERIC: + assertEquals(msg, CellType.NUMERIC, actual.getCellType()); TestMathX.assertEquals(msg, expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); break; - case Cell.CELL_TYPE_STRING: - assertEquals(msg, Cell.CELL_TYPE_STRING, actual.getCellType()); + case STRING: + assertEquals(msg, CellType.STRING, actual.getCellType()); assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue()); break; + default: + throw new AssertionFailedError("Unexpected cell type: " + cellType); } } @@ -226,7 +231,7 @@ public final class TestMultiSheetEval extends TestCase { int result = Result.NO_EVALUATIONS_FOUND; // so far Cell c = formulasRow.getCell(SS.COLUMN_INDEX_ACTUAL_VALUE); - if (c == null || c.getCellType() != Cell.CELL_TYPE_FORMULA) { + if (c == null || c.getCellType() != CellType.FORMULA) { return result; } @@ -295,10 +300,10 @@ public final class TestMultiSheetEval extends TestCase { System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name"); return null; } - if(cell.getCellType() == Cell.CELL_TYPE_BLANK) { + if(cell.getCellType() == CellType.BLANK) { return null; } - if(cell.getCellType() == Cell.CELL_TYPE_STRING) { + if(cell.getCellType() == CellType.STRING) { return cell.getRichStringCellValue().getString(); } @@ -318,10 +323,10 @@ public final class TestMultiSheetEval extends TestCase { System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_TEST_NAME + ", can't figure out test name"); return null; } - if(cell.getCellType() == Cell.CELL_TYPE_BLANK) { + if(cell.getCellType() == CellType.BLANK) { return null; } - if(cell.getCellType() == Cell.CELL_TYPE_STRING) { + if(cell.getCellType() == CellType.STRING) { return cell.getRichStringCellValue().getString(); } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java index e222220cef..4fed4d48f9 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java @@ -36,6 +36,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -122,7 +123,7 @@ public abstract class BaseTestFunctionsFromSpreadsheet { currentGroupComment = newMarkerValue;
}
HSSFCell evalCell = r.getCell(SS.COLUMN_INDEX_EVALUATION);
- if (evalCell == null || evalCell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
+ if (evalCell == null || evalCell.getCellType() != CellType.FORMULA) {
continue;
}
String rowComment = getCellTextValue(r, SS.COLUMN_ROW_COMMENT, "row comment");
@@ -152,9 +153,9 @@ public abstract class BaseTestFunctionsFromSpreadsheet { assertNotNull(msg + " - Bad setup data expected value is null", expectedCell);
assertNotNull(msg + " - actual value was null", actualValue);
- if (expectedCell.getCellType() == HSSFCell.CELL_TYPE_ERROR) {
+ if (expectedCell.getCellType() == CellType.ERROR) {
int expectedErrorCode = expectedCell.getErrorCellValue();
- assertEquals(msg, HSSFCell.CELL_TYPE_ERROR, actualValue.getCellType());
+ assertEquals(msg, CellType.ERROR, actualValue.getCellType());
assertEquals(msg, ErrorEval.getText(expectedErrorCode), actualValue.formatAsString());
assertEquals(msg, expectedErrorCode, actualValue.getErrorValue());
assertEquals(msg, ErrorEval.getText(expectedErrorCode), ErrorEval.getText(actualValue.getErrorValue()));
@@ -162,24 +163,27 @@ public abstract class BaseTestFunctionsFromSpreadsheet { }
// unexpected error
- assertNotEquals(msg, HSSFCell.CELL_TYPE_ERROR, actualValue.getCellType());
+ assertNotEquals(msg, CellType.ERROR, actualValue.getCellType());
assertNotEquals(msg, formatValue(expectedCell), ErrorEval.getText(actualValue.getErrorValue()));
// wrong type error
assertEquals(msg, expectedCell.getCellType(), actualValue.getCellType());
- switch (expectedCell.getCellType()) {
- case HSSFCell.CELL_TYPE_BOOLEAN:
+ final CellType expectedCellType = expectedCell.getCellType();
+ switch (expectedCellType) {
+ case BOOLEAN:
assertEquals(msg, expectedCell.getBooleanCellValue(), actualValue.getBooleanValue());
break;
- case HSSFCell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
+ case FORMULA: // will never be used, since we will call method after formula evaluation
fail("Cannot expect formula as result of formula evaluation: " + msg);
- case HSSFCell.CELL_TYPE_NUMERIC:
+ case NUMERIC:
assertEquals(expectedCell.getNumericCellValue(), actualValue.getNumberValue(), 0.0);
break;
- case HSSFCell.CELL_TYPE_STRING:
+ case STRING:
assertEquals(msg, expectedCell.getRichStringCellValue().getString(), actualValue.getStringValue());
break;
+ default:
+ fail("Unexpected cell type: " + expectedCellType);
}
}
@@ -208,10 +212,10 @@ public abstract class BaseTestFunctionsFromSpreadsheet { if(cell == null) {
return null;
}
- if(cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
+ if(cell.getCellType() == CellType.BLANK) {
return null;
}
- if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
+ if(cell.getCellType() == CellType.STRING) {
return cell.getRichStringCellValue().getString();
}
@@ -222,12 +226,12 @@ public abstract class BaseTestFunctionsFromSpreadsheet { private static String formatValue(HSSFCell expecedCell) {
switch (expecedCell.getCellType()) {
- case HSSFCell.CELL_TYPE_BLANK: return "<blank>";
- case HSSFCell.CELL_TYPE_BOOLEAN: return Boolean.toString(expecedCell.getBooleanCellValue());
- case HSSFCell.CELL_TYPE_NUMERIC: return Double.toString(expecedCell.getNumericCellValue());
- case HSSFCell.CELL_TYPE_STRING: return expecedCell.getRichStringCellValue().getString();
+ case BLANK: return "<blank>";
+ case BOOLEAN: return Boolean.toString(expecedCell.getBooleanCellValue());
+ case NUMERIC: return Double.toString(expecedCell.getNumericCellValue());
+ case STRING: return expecedCell.getRichStringCellValue().getString();
+ default: fail("Unexpected cell type of expected value (" + expecedCell.getCellType() + ")");
}
- fail("Unexpected cell type of expected value (" + expecedCell.getCellType() + ")");
return "";
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java index 4a1e02bc48..68f9873159 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java @@ -527,7 +527,7 @@ public abstract class BaseTestBugzillaIssues { for(int rn=0; rn<= topRow; rn++) { Row r = s.createRow(rn); for(int cn=0; cn<leftmostColumn; cn++) { - Cell c = r.createCell(cn, Cell.CELL_TYPE_NUMERIC); + Cell c = r.createCell(cn, CellType.NUMERIC); c.setCellValue(100*rn + cn); } } @@ -654,16 +654,16 @@ public abstract class BaseTestBugzillaIssues { Row r1 = s.createRow(0); for (int i=0; i<3; i++) { - r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(0); + r1.createCell(i, CellType.NUMERIC).setCellValue(0); } for (int i=3; i<6; i++) { - r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(1); + r1.createCell(i, CellType.NUMERIC).setCellValue(1); } for (int i=6; i<9; i++) { - r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(0.12345); + r1.createCell(i, CellType.NUMERIC).setCellValue(0.12345); } for (int i=9; i<12; i++) { - r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(1.2345); + r1.createCell(i, CellType.NUMERIC).setCellValue(1.2345); } for (int i=0; i<12; i+=3) { r1.getCell(i).setCellStyle(iPercent); @@ -714,11 +714,11 @@ public abstract class BaseTestBugzillaIssues { // C1 is a string, with different text r1.createCell(2).setCellValue("This some other text"); // D1 is a blank cell - r1.createCell(3, Cell.CELL_TYPE_BLANK); + r1.createCell(3, CellType.BLANK); // E1 is null // A2 will hold our test formulas - Cell cf = r2.createCell(0, Cell.CELL_TYPE_FORMULA); + Cell cf = r2.createCell(0, CellType.FORMULA); // First up, check that TRUE and ISLOGICAL both behave @@ -872,10 +872,10 @@ public abstract class BaseTestBugzillaIssues { // Create the references - Cell c1 = r1.createCell(0, Cell.CELL_TYPE_FORMULA); + Cell c1 = r1.createCell(0, CellType.FORMULA); c1.setCellFormula(refLocal); - Cell c2 = r1.createCell(1, Cell.CELL_TYPE_FORMULA); + Cell c2 = r1.createCell(1, CellType.FORMULA); c2.setCellFormula(refHttp); @@ -952,7 +952,7 @@ public abstract class BaseTestBugzillaIssues { assertEquals(1, cArray.length);*/ Cell cell = row.getCell(0); - assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType()); + assertEquals(CellType.FORMULA, cell.getCellType()); } { // overwrite the row @@ -1119,29 +1119,29 @@ public abstract class BaseTestBugzillaIssues { Row r = s.createRow(0); // Setup - Cell cn = r.createCell(0, Cell.CELL_TYPE_NUMERIC); + Cell cn = r.createCell(0, CellType.NUMERIC); cn.setCellValue(1.2); - Cell cs = r.createCell(1, Cell.CELL_TYPE_STRING); + Cell cs = r.createCell(1, CellType.STRING); cs.setCellValue("Testing"); - Cell cfn = r.createCell(2, Cell.CELL_TYPE_FORMULA); + Cell cfn = r.createCell(2, CellType.FORMULA); cfn.setCellFormula("A1"); - Cell cfs = r.createCell(3, Cell.CELL_TYPE_FORMULA); + Cell cfs = r.createCell(3, CellType.FORMULA); cfs.setCellFormula("B1"); FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); - assertEquals(Cell.CELL_TYPE_NUMERIC, fe.evaluate(cfn).getCellType()); - assertEquals(Cell.CELL_TYPE_STRING, fe.evaluate(cfs).getCellType()); + assertEquals(CellType.NUMERIC, fe.evaluate(cfn).getCellType()); + assertEquals(CellType.STRING, fe.evaluate(cfs).getCellType()); fe.evaluateFormulaCell(cfn); fe.evaluateFormulaCell(cfs); // Now test - assertEquals(Cell.CELL_TYPE_NUMERIC, cn.getCellType()); - assertEquals(Cell.CELL_TYPE_STRING, cs.getCellType()); - assertEquals(Cell.CELL_TYPE_FORMULA, cfn.getCellType()); - assertEquals(Cell.CELL_TYPE_NUMERIC, cfn.getCachedFormulaResultType()); - assertEquals(Cell.CELL_TYPE_FORMULA, cfs.getCellType()); - assertEquals(Cell.CELL_TYPE_STRING, cfs.getCachedFormulaResultType()); + assertEquals(CellType.NUMERIC, cn.getCellType()); + assertEquals(CellType.STRING, cs.getCellType()); + assertEquals(CellType.FORMULA, cfn.getCellType()); + assertEquals(CellType.NUMERIC, cfn.getCachedFormulaResultType()); + assertEquals(CellType.FORMULA, cfs.getCellType()); + assertEquals(CellType.STRING, cfs.getCachedFormulaResultType()); // Different ways of retrieving assertEquals(1.2, cn.getNumericCellValue(), 0); @@ -1195,7 +1195,7 @@ public abstract class BaseTestBugzillaIssues { cell = row.createCell(1); // also verify that setting formulas to null works - cell.setCellType(Cell.CELL_TYPE_FORMULA); + cell.setCellType(CellType.FORMULA); cell.setCellValue((String)null); wb.getCreationHelper().createFormulaEvaluator().evaluateAll(); @@ -1205,7 +1205,7 @@ public abstract class BaseTestBugzillaIssues { value == null || value.length() == 0); // set some value - cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(CellType.STRING); cell.setCellValue("somevalue"); value = cell.getStringCellValue(); @@ -1383,7 +1383,7 @@ public abstract class BaseTestBugzillaIssues { Sheet s = wb.createSheet(); Cell cell = s.createRow(0).createCell(0); cell.setCellValue((String)null); - assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType()); + assertEquals(CellType.BLANK, cell.getCellType()); _testDataProvider.trackAllColumnsForAutosizing(s); @@ -1554,8 +1554,8 @@ public abstract class BaseTestBugzillaIssues { Cell cell = row.getCell(cellId); System.out.println("Formula:" + cell.getCellFormula()); - if (Cell.CELL_TYPE_FORMULA == cell.getCellType()) { - int formulaResultType = cell.getCachedFormulaResultType(); + if (CellType.FORMULA == cell.getCellType()) { + CellType formulaResultType = cell.getCachedFormulaResultType(); System.out.println("Formula Result Type:" + formulaResultType); } @@ -1569,8 +1569,8 @@ public abstract class BaseTestBugzillaIssues { cell = row.getCell(cellId); System.out.println("Formula:" + cell.getCellFormula()); - if (Cell.CELL_TYPE_FORMULA == cell.getCellType()) { - int formulaResultType = cell.getCachedFormulaResultType(); + if (CellType.FORMULA == cell.getCellType()) { + CellType formulaResultType = cell.getCachedFormulaResultType(); System.out.println("Formula Result Type:" + formulaResultType); } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index d701d7c58b..a1c91481a5 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -60,76 +60,78 @@ public abstract class BaseTestCell { cell.setCellValue(1.2); assertEquals(1.2, cell.getNumericCellValue(), 0.0001); - assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); - assertProhibitedValueAccess(cell, Cell.CELL_TYPE_BOOLEAN, Cell.CELL_TYPE_STRING, - Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, + CellType.FORMULA, CellType.ERROR); cell.setCellValue(false); assertEquals(false, cell.getBooleanCellValue()); - assertEquals(Cell.CELL_TYPE_BOOLEAN, cell.getCellType()); + assertEquals(CellType.BOOLEAN, cell.getCellType()); cell.setCellValue(true); assertEquals(true, cell.getBooleanCellValue()); - assertProhibitedValueAccess(cell, Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_STRING, - Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR); + assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, + CellType.FORMULA, CellType.ERROR); cell.setCellValue(factory.createRichTextString("Foo")); assertEquals("Foo", cell.getRichStringCellValue().getString()); assertEquals("Foo", cell.getStringCellValue()); - assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType()); - assertProhibitedValueAccess(cell, Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_BOOLEAN, - Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR); + assertEquals(CellType.STRING, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, + CellType.FORMULA, CellType.ERROR); cell.setCellValue("345"); assertEquals("345", cell.getRichStringCellValue().getString()); assertEquals("345", cell.getStringCellValue()); - assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType()); - assertProhibitedValueAccess(cell, Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_BOOLEAN, - Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR); + assertEquals(CellType.STRING, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, + CellType.FORMULA, CellType.ERROR); Calendar c = LocaleUtil.getLocaleCalendar(); c.setTimeInMillis(123456789); cell.setCellValue(c.getTime()); assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime()); - assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); - assertProhibitedValueAccess(cell, Cell.CELL_TYPE_BOOLEAN, Cell.CELL_TYPE_STRING, - Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, + CellType.FORMULA, CellType.ERROR); cell.setCellValue(c); assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime()); - assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); - assertProhibitedValueAccess(cell, Cell.CELL_TYPE_BOOLEAN, Cell.CELL_TYPE_STRING, - Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR); + assertEquals(CellType.NUMERIC, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, + CellType.FORMULA, CellType.ERROR); cell.setCellErrorValue(FormulaError.NA.getCode()); assertEquals(FormulaError.NA.getCode(), cell.getErrorCellValue()); - assertEquals(Cell.CELL_TYPE_ERROR, cell.getCellType()); - assertProhibitedValueAccess(cell, Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_BOOLEAN, - Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_STRING); + assertEquals(CellType.ERROR, cell.getCellType()); + assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.BOOLEAN, + CellType.FORMULA, CellType.STRING); book.close(); } - private static void assertProhibitedValueAccess(Cell cell, int ... types){ - for(int type : types){ + private static void assertProhibitedValueAccess(Cell cell, CellType ... types) { + for(CellType type : types){ try { switch (type) { - case Cell.CELL_TYPE_NUMERIC: + case NUMERIC: cell.getNumericCellValue(); break; - case Cell.CELL_TYPE_STRING: + case STRING: cell.getStringCellValue(); break; - case Cell.CELL_TYPE_BOOLEAN: + case BOOLEAN: cell.getBooleanCellValue(); break; - case Cell.CELL_TYPE_FORMULA: + case FORMULA: cell.getCellFormula(); break; - case Cell.CELL_TYPE_ERROR: + case ERROR: cell.getErrorCellValue(); break; + default: + fail("Should get exception when reading cell type (" + type + ")."); } - fail("Should get exception when reading cell type (" + type + ")."); + } catch (IllegalStateException e){ // expected during successful test assertTrue(e.getMessage().startsWith("Cannot get a")); @@ -174,13 +176,13 @@ public abstract class BaseTestCell { c = r.getCell(1); assertEquals(0, c.getRowIndex()); assertEquals(1, c.getColumnIndex()); - assertEquals(Cell.CELL_TYPE_BOOLEAN, c.getCellType()); + assertEquals(CellType.BOOLEAN, c.getCellType()); assertEquals("B1 value", true, c.getBooleanCellValue()); c = r.getCell(2); assertEquals(0, c.getRowIndex()); assertEquals(2, c.getColumnIndex()); - assertEquals(Cell.CELL_TYPE_BOOLEAN, c.getCellType()); + assertEquals(CellType.BOOLEAN, c.getCellType()); assertEquals("C1 value", false, c.getBooleanCellValue()); wb2.close(); @@ -224,13 +226,13 @@ public abstract class BaseTestCell { c = r.getCell(1); assertEquals(0, c.getRowIndex()); assertEquals(1, c.getColumnIndex()); - assertEquals(Cell.CELL_TYPE_ERROR, c.getCellType()); + assertEquals(CellType.ERROR, c.getCellType()); assertEquals("B1 value == #NULL!", FormulaError.NULL.getCode(), c.getErrorCellValue()); c = r.getCell(2); assertEquals(0, c.getRowIndex()); assertEquals(2, c.getColumnIndex()); - assertEquals(Cell.CELL_TYPE_ERROR, c.getCellType()); + assertEquals(CellType.ERROR, c.getCellType()); assertEquals("C1 value == #DIV/0!", FormulaError.DIV0.getCode(), c.getErrorCellValue()); wb2.close(); @@ -270,7 +272,7 @@ public abstract class BaseTestCell { r = s.getRow(0); c = r.getCell(0); - assertEquals("Formula Cell at 0,0", Cell.CELL_TYPE_FORMULA, c.getCellType()); + assertEquals("Formula Cell at 0,0", CellType.FORMULA, c.getCellType()); cs = c.getCellStyle(); assertNotNull("Formula Cell Style", cs); @@ -345,25 +347,25 @@ public abstract class BaseTestCell { Cell c1 = r.createCell(0); c1.setCellFormula("NA()"); assertEquals(0.0, c1.getNumericCellValue(), 0.0); - assertEquals(Cell.CELL_TYPE_NUMERIC, c1.getCachedFormulaResultType()); + assertEquals(CellType.NUMERIC, c1.getCachedFormulaResultType()); c1.setCellValue(10); assertEquals(10.0, c1.getNumericCellValue(), 0.0); - assertEquals(Cell.CELL_TYPE_FORMULA, c1.getCellType()); - assertEquals(Cell.CELL_TYPE_NUMERIC, c1.getCachedFormulaResultType()); + assertEquals(CellType.FORMULA, c1.getCellType()); + assertEquals(CellType.NUMERIC, c1.getCachedFormulaResultType()); Cell c2 = r.createCell(1); c2.setCellFormula("NA()"); assertEquals(0.0, c2.getNumericCellValue(), 0.0); - assertEquals(Cell.CELL_TYPE_NUMERIC, c2.getCachedFormulaResultType()); + assertEquals(CellType.NUMERIC, c2.getCachedFormulaResultType()); c2.setCellValue("I changed!"); assertEquals("I changed!", c2.getStringCellValue()); - assertEquals(Cell.CELL_TYPE_FORMULA, c2.getCellType()); - assertEquals(Cell.CELL_TYPE_STRING, c2.getCachedFormulaResultType()); + assertEquals(CellType.FORMULA, c2.getCellType()); + assertEquals(CellType.STRING, c2.getCachedFormulaResultType()); //calglin Cell.setCellFormula(null) for a non-formula cell Cell c3 = r.createCell(2); c3.setCellFormula(null); - assertEquals(Cell.CELL_TYPE_BLANK, c3.getCellType()); + assertEquals(CellType.BLANK, c3.getCellType()); wb.close(); } @@ -418,21 +420,21 @@ public abstract class BaseTestCell { Cell cell = createACell(wb); cell.setCellValue("TRUE"); - assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType()); + assertEquals(CellType.STRING, cell.getCellType()); // test conversion of cell from text to boolean - cell.setCellType(Cell.CELL_TYPE_BOOLEAN); + cell.setCellType(CellType.BOOLEAN); - assertEquals(Cell.CELL_TYPE_BOOLEAN, cell.getCellType()); + assertEquals(CellType.BOOLEAN, cell.getCellType()); assertEquals(true, cell.getBooleanCellValue()); - cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(CellType.STRING); assertEquals("TRUE", cell.getRichStringCellValue().getString()); // 'false' text to bool and back cell.setCellValue("FALSE"); - cell.setCellType(Cell.CELL_TYPE_BOOLEAN); - assertEquals(Cell.CELL_TYPE_BOOLEAN, cell.getCellType()); + cell.setCellType(CellType.BOOLEAN); + assertEquals(CellType.BOOLEAN, cell.getCellType()); assertEquals(false, cell.getBooleanCellValue()); - cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(CellType.STRING); assertEquals("FALSE", cell.getRichStringCellValue().getString()); wb.close(); @@ -446,7 +448,7 @@ public abstract class BaseTestCell { cell.setCellValue(true); // test conversion of cell from boolean to text - cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(CellType.STRING); assertEquals("TRUE", cell.getRichStringCellValue().getString()); wb.close(); @@ -523,7 +525,7 @@ public abstract class BaseTestCell { fe.clearAllCachedResultValues(); fe.evaluateFormulaCell(cellA1); assertEquals("DEF", cellA1.getStringCellValue()); - cellA1.setCellType(Cell.CELL_TYPE_STRING); + cellA1.setCellType(CellType.STRING); assertEquals("DEF", cellA1.getStringCellValue()); cellA1.setCellFormula("25.061"); @@ -531,7 +533,7 @@ public abstract class BaseTestCell { fe.evaluateFormulaCell(cellA1); confirmCannotReadString(cellA1); assertEquals(25.061, cellA1.getNumericCellValue(), 0.0); - cellA1.setCellType(Cell.CELL_TYPE_STRING); + cellA1.setCellType(CellType.STRING); assertEquals("25.061", cellA1.getStringCellValue()); cellA1.setCellFormula("TRUE"); @@ -539,7 +541,7 @@ public abstract class BaseTestCell { fe.evaluateFormulaCell(cellA1); confirmCannotReadString(cellA1); assertEquals(true, cellA1.getBooleanCellValue()); - cellA1.setCellType(Cell.CELL_TYPE_STRING); + cellA1.setCellType(CellType.STRING); assertEquals("TRUE", cellA1.getStringCellValue()); cellA1.setCellFormula("#NAME?"); @@ -547,14 +549,14 @@ public abstract class BaseTestCell { fe.evaluateFormulaCell(cellA1); confirmCannotReadString(cellA1); assertEquals(FormulaError.NAME, forInt(cellA1.getErrorCellValue())); - cellA1.setCellType(Cell.CELL_TYPE_STRING); + cellA1.setCellType(CellType.STRING); assertEquals("#NAME?", cellA1.getStringCellValue()); wb.close(); } private static void confirmCannotReadString(Cell cell) { - assertProhibitedValueAccess(cell, Cell.CELL_TYPE_STRING); + assertProhibitedValueAccess(cell, CellType.STRING); } /** @@ -567,7 +569,7 @@ public abstract class BaseTestCell { Cell cell = createACell(wb); cell.setCellFormula("1=1"); cell.setCellValue(true); - cell.setCellType(Cell.CELL_TYPE_BOOLEAN); + cell.setCellType(CellType.BOOLEAN); assertTrue("Identified bug 46479d", cell.getBooleanCellValue()); assertEquals(true, cell.getBooleanCellValue()); @@ -585,19 +587,19 @@ public abstract class BaseTestCell { Cell cell; Row row = workSheet.createRow(0); - cell = row.createCell(0, Cell.CELL_TYPE_NUMERIC); + cell = row.createCell(0, CellType.NUMERIC); cell.setCellValue(1.0); - assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); + assertEquals(CellType.NUMERIC, cell.getCellType()); assertEquals(1.0, cell.getNumericCellValue(), 0.0); - cell = row.createCell(1, Cell.CELL_TYPE_NUMERIC); + cell = row.createCell(1, CellType.NUMERIC); cell.setCellValue(2.0); - assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); + assertEquals(CellType.NUMERIC, cell.getCellType()); assertEquals(2.0, cell.getNumericCellValue(), 0.0); - cell = row.createCell(2, Cell.CELL_TYPE_FORMULA); + cell = row.createCell(2, CellType.FORMULA); cell.setCellFormula("SUM(A1:B1)"); - assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType()); + assertEquals(CellType.FORMULA, cell.getCellType()); assertEquals("SUM(A1:B1)", cell.getCellFormula()); //serialize and check again @@ -605,15 +607,15 @@ public abstract class BaseTestCell { wb1.close(); row = wb2.getSheetAt(0).getRow(0); cell = row.getCell(0); - assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); + assertEquals(CellType.NUMERIC, cell.getCellType()); assertEquals(1.0, cell.getNumericCellValue(), 0.0); cell = row.getCell(1); - assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); + assertEquals(CellType.NUMERIC, cell.getCellType()); assertEquals(2.0, cell.getNumericCellValue(), 0.0); cell = row.getCell(2); - assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType()); + assertEquals(CellType.FORMULA, cell.getCellType()); assertEquals("SUM(A1:B1)", cell.getCellFormula()); wb2.close(); } @@ -628,7 +630,7 @@ public abstract class BaseTestCell { } /** - * Make sure that cell.setCellType(Cell.CELL_TYPE_BLANK) preserves the cell style + * Make sure that cell.setCellType(CellType.BLANK) preserves the cell style */ @Test public void testSetBlank_bug47028() throws Exception { @@ -637,7 +639,7 @@ public abstract class BaseTestCell { Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0); cell.setCellStyle(style); int i1 = cell.getCellStyle().getIndex(); - cell.setCellType(Cell.CELL_TYPE_BLANK); + cell.setCellType(CellType.BLANK); int i2 = cell.getCellStyle().getIndex(); assertEquals(i1, i2); wb.close(); @@ -670,17 +672,17 @@ public abstract class BaseTestCell { Cell cell0 = row.createCell(0); cell0.setCellValue(Double.NaN); - assertEquals("Double.NaN should change cell type to CELL_TYPE_ERROR", Cell.CELL_TYPE_ERROR, cell0.getCellType()); + assertEquals("Double.NaN should change cell type to CELL_TYPE_ERROR", CellType.ERROR, cell0.getCellType()); assertEquals("Double.NaN should change cell value to #NUM!", FormulaError.NUM, forInt(cell0.getErrorCellValue())); Cell cell1 = row.createCell(1); cell1.setCellValue(Double.POSITIVE_INFINITY); - assertEquals("Double.POSITIVE_INFINITY should change cell type to CELL_TYPE_ERROR", Cell.CELL_TYPE_ERROR, cell1.getCellType()); + assertEquals("Double.POSITIVE_INFINITY should change cell type to CELL_TYPE_ERROR", CellType.ERROR, cell1.getCellType()); assertEquals("Double.POSITIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell1.getErrorCellValue())); Cell cell2 = row.createCell(2); cell2.setCellValue(Double.NEGATIVE_INFINITY); - assertEquals("Double.NEGATIVE_INFINITY should change cell type to CELL_TYPE_ERROR", Cell.CELL_TYPE_ERROR, cell2.getCellType()); + assertEquals("Double.NEGATIVE_INFINITY should change cell type to CELL_TYPE_ERROR", CellType.ERROR, cell2.getCellType()); assertEquals("Double.NEGATIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell2.getErrorCellValue())); Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1); @@ -688,15 +690,15 @@ public abstract class BaseTestCell { row = wb2.getSheetAt(0).getRow(0); cell0 = row.getCell(0); - assertEquals(Cell.CELL_TYPE_ERROR, cell0.getCellType()); + assertEquals(CellType.ERROR, cell0.getCellType()); assertEquals(FormulaError.NUM, forInt(cell0.getErrorCellValue())); cell1 = row.getCell(1); - assertEquals(Cell.CELL_TYPE_ERROR, cell1.getCellType()); + assertEquals(CellType.ERROR, cell1.getCellType()); assertEquals(FormulaError.DIV0, forInt(cell1.getErrorCellValue())); cell2 = row.getCell(2); - assertEquals(Cell.CELL_TYPE_ERROR, cell2.getCellType()); + assertEquals(CellType.ERROR, cell2.getCellType()); assertEquals(FormulaError.DIV0, forInt(cell2.getErrorCellValue())); wb2.close(); } @@ -897,21 +899,21 @@ public abstract class BaseTestCell { RichTextString nullStr = null; cell.setCellValue(nullStr); assertEquals("", cell.getStringCellValue()); - assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType()); + assertEquals(CellType.BLANK, cell.getCellType()); cell = sheet.createRow(0).createCell(1); cell.setCellValue(1.2d); - assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); + assertEquals(CellType.NUMERIC, cell.getCellType()); cell.setCellValue(nullStr); assertEquals("", cell.getStringCellValue()); - assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType()); + assertEquals(CellType.BLANK, cell.getCellType()); cell = sheet.createRow(0).createCell(1); cell.setCellValue(wb.getCreationHelper().createRichTextString("Test")); - assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType()); + assertEquals(CellType.STRING, cell.getCellType()); cell.setCellValue(nullStr); assertEquals("", cell.getStringCellValue()); - assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType()); + assertEquals(CellType.BLANK, cell.getCellType()); wb.close(); } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java index d7439223be..34aa9f5dbd 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java @@ -216,7 +216,7 @@ public abstract class BaseTestFormulaEvaluator { FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); Sheet sheet = wb.createSheet("Sheet1"); Row r = sheet.createRow(0); - Cell c = r.createCell(0, Cell.CELL_TYPE_FORMULA); + Cell c = r.createCell(0, CellType.FORMULA); // Create a value and check it c.setCellFormula("Date(2011,10,6)"); |