From: PJ Fanning Date: Wed, 8 Dec 2021 19:03:30 +0000 (+0000) Subject: update tests X-Git-Tag: REL_5_2_0~100 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ea9883af5500f5f92f3c3b3d056f82fc52b2ff16;p=poi.git update tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895705 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java b/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java index 21744b9b88..8d420462c1 100644 --- a/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java +++ b/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java @@ -827,19 +827,34 @@ class TestDataFormatter { @Test void testFormulaEvaluation() throws IOException { - Workbook wb = HSSFTestDataSamples.openSampleWorkbook("FormulaEvalTestData.xls"); + try (Workbook wb = HSSFTestDataSamples.openSampleWorkbook("FormulaEvalTestData.xls")) { + CellReference ref = new CellReference("D47"); - CellReference ref = new CellReference("D47"); + Cell cell = wb.getSheetAt(0).getRow(ref.getRow()).getCell(ref.getCol()); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals("G9:K9 I7:I12", cell.getCellFormula()); - Cell cell = wb.getSheetAt(0).getRow(ref.getRow()).getCell(ref.getCol()); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals("G9:K9 I7:I12", cell.getCellFormula()); - - DataFormatter formatter = new DataFormatter(); - FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); - assertEquals("5.6789", formatter.formatCellValue(cell, evaluator)); + DataFormatter formatter = new DataFormatter(); + FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + assertEquals("5.6789", formatter.formatCellValue(cell, evaluator)); + } + } - wb.close(); + @Test + void testFormulaEvaluationWithoutFormulaEvaluator() throws IOException { + String formula = "G9:K9 I7:I12"; + try (Workbook wb = HSSFTestDataSamples.openSampleWorkbook("FormulaEvalTestData.xls")) { + CellReference ref = new CellReference("D47"); + + Cell cell = wb.getSheetAt(0).getRow(ref.getRow()).getCell(ref.getCol()); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(formula, cell.getCellFormula()); + + DataFormatter formatter = new DataFormatter(); + assertEquals(formula, formatter.formatCellValue(cell)); + formatter.setUseCachedValuesForFormulaCells(true); + assertEquals("5.6789", formatter.formatCellValue(cell)); + } } @Test