]> source.dussan.org Git - poi.git/commitdiff
add disabled SUMIF test
authorPJ Fanning <fanningpj@apache.org>
Fri, 30 Jul 2021 09:45:24 +0000 (09:45 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 30 Jul 2021 09:45:24 +0000 (09:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891893 13f79535-47bb-0310-9956-ffa450edef68

poi/src/test/java/org/apache/poi/ss/formula/functions/TestSumif.java

index 2b41d4cbb0fc89898090921bd9e258016a8ed0b0..965fb777b6421a0beab2b750329a7c4d7ff7b996 100644 (file)
@@ -29,10 +29,8 @@ import org.apache.poi.ss.formula.eval.NumberEval;
 import org.apache.poi.ss.formula.eval.NumericValueEval;
 import org.apache.poi.ss.formula.eval.StringEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
-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.Workbook;
+import org.apache.poi.ss.usermodel.*;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
@@ -120,6 +118,16 @@ final class TestSumif {
         }
     }
 
+    @Disabled("https://bz.apache.org/bugzilla/show_bug.cgi?id=65475")
+    @Test
+    void testMicrosoftExample1WithNA() throws IOException {
+        try (HSSFWorkbook wb = initWorkbook1WithNA()) {
+            HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+            HSSFCell cell = wb.getSheetAt(0).createRow(5).createCell(0);
+            confirmError(fe, cell, "SUMIF(A2:A6,\">160000\",B2:B5)", FormulaError.NA);
+        }
+    }
+
     @Test
     void testMicrosoftExample2() throws IOException {
         try (HSSFWorkbook wb = initWorkbook2()) {
@@ -145,6 +153,13 @@ final class TestSumif {
         return wb;
     }
 
+    private HSSFWorkbook initWorkbook1WithNA() {
+        HSSFWorkbook wb = initWorkbook1();
+        HSSFSheet sheet = wb.getSheetAt(0);
+        addRow(sheet, 5, 500000, "#N/A");
+        return wb;
+    }
+
     private HSSFWorkbook initWorkbook2() {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet sheet = wb.createSheet();
@@ -166,6 +181,8 @@ final class TestSumif {
                 cell.setCellValue((Integer)values[i]);
             } else if (values[i] == null) {
                 cell.setBlank();
+            } else if (values[i] == "#N/A") {
+                cell.setCellErrorValue(FormulaError.NA.getCode());
             } else {
                 cell.setCellValue(values[i].toString());
             }
@@ -193,4 +210,12 @@ final class TestSumif {
         assertEquals(result.getCellType(), CellType.NUMERIC);
         assertEquals(expectedResult, result.getNumberValue());
     }
+
+    private static void confirmError(HSSFFormulaEvaluator fe, HSSFCell cell, String formulaText, FormulaError expectedError) {
+        cell.setCellFormula(formulaText);
+        fe.notifyUpdateCell(cell);
+        CellValue result = fe.evaluate(cell);
+        assertEquals(result.getCellType(), CellType.ERROR);
+        assertEquals(expectedError.getCode(), result.getErrorValue());
+    }
 }