]> source.dussan.org Git - poi.git/commitdiff
update tests
authorPJ Fanning <fanningpj@apache.org>
Wed, 8 Dec 2021 19:03:30 +0000 (19:03 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 8 Dec 2021 19:03:30 +0000 (19:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895705 13f79535-47bb-0310-9956-ffa450edef68

poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java

index 21744b9b88ca17f090f54a57d089a9b02a368b59..8d420462c13b19c16c8bccf9293c41b39276c414 100644 (file)
@@ -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