From fb8c79d96c2f0ddffb13f5b96c0f65b66c77ce5f Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Mon, 4 Jul 2016 09:45:46 +0000 Subject: 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 --- .../apache/poi/hssf/record/TestFormulaRecord.java | 4 +- .../org/apache/poi/hssf/usermodel/TestBugs.java | 63 +++++---- .../apache/poi/hssf/usermodel/TestHSSFCell.java | 42 +++--- .../apache/poi/hssf/usermodel/TestWorkbook.java | 7 +- .../poi/ss/formula/TestWorkbookEvaluator.java | 85 +++++------ .../formula/eval/TestFormulasFromSpreadsheet.java | 34 +++-- .../poi/ss/formula/eval/TestMultiSheetEval.java | 39 +++--- .../BaseTestFunctionsFromSpreadsheet.java | 36 ++--- .../poi/ss/usermodel/BaseTestBugzillaIssues.java | 58 ++++---- .../org/apache/poi/ss/usermodel/BaseTestCell.java | 156 +++++++++++---------- .../poi/ss/usermodel/BaseTestFormulaEvaluator.java | 2 +- 11 files changed, 269 insertions(+), 257 deletions(-) (limited to 'src/testcases/org') 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.

* SUCCESS: HSSF reads a sheet. HSSF returns that the cell is a numeric type cell.

- * FAILURE: HSSF does not read a sheet or excepts. HSSF incorrectly indentifies the cell

+ * FAILURE: HSSF does not read a sheet or excepts. HSSF incorrectly identifies the cell

*/ @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 ""; - 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 ""; + 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