diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2019-12-27 23:00:13 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2019-12-27 23:00:13 +0000 |
commit | c66575c1e7059ed403b74b76e699200fdee507b4 (patch) | |
tree | 0fe96421471b53e9f72a2370ce76d61b49a659bc /src/testcases/org/apache/poi/ss/formula/functions | |
parent | 37282aae8f25970b157c40ae0888684f974ba666 (diff) | |
download | poi-c66575c1e7059ed403b74b76e699200fdee507b4.tar.gz poi-c66575c1e7059ed403b74b76e699200fdee507b4.zip |
Migrate all junit tests to Junit 4
get rid of references to junit.framework
don't throw AssertionFailedErrors, but use Assert.fail instead
add try-with-resources where it was missing
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872041 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss/formula/functions')
11 files changed, 67 insertions, 138 deletions
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java b/src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java index 8dc432eb49..e53f88e1fb 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java @@ -17,17 +17,15 @@ package org.apache.poi.ss.formula.functions; -import junit.framework.AssertionFailedError; +import static org.junit.Assert.fail; import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.formula.eval.NotImplementedException; import org.apache.poi.ss.formula.eval.NumericValueEval; import org.apache.poi.ss.formula.eval.ValueEval; -import org.apache.poi.ss.formula.eval.NotImplementedException; /** * Test helper class for invoking functions with numeric results. - * - * @author Josh Micich */ public final class NumericFunctionInvoker { @@ -64,8 +62,8 @@ public final class NumericFunctionInvoker { try { return invokeInternal(f, args, srcCellRow, srcCellCol); } catch (NumericEvalEx e) { - throw new AssertionFailedError("Evaluation of function (" + f.getClass().getName() - + ") failed: " + e.getMessage()); + fail("Evaluation of function (" + f.getClass().getName() + ") failed: " + e.getMessage()); + return -1; } } /** @@ -96,16 +94,9 @@ public final class NumericFunctionInvoker { NumericValueEval result = (NumericValueEval) evalResult; return result.getNumberValue(); } + private static String formatErrorMessage(ErrorEval ee) { - if(errorCodesAreEqual(ee, ErrorEval.VALUE_INVALID)) { - return "Error code: #VALUE! (invalid value)"; - } - return "Error code=" + ee.getErrorCode(); - } - private static boolean errorCodesAreEqual(ErrorEval a, ErrorEval b) { - if(a==b) { - return true; - } - return a.getErrorCode() == b.getErrorCode(); + boolean b = (ee == ErrorEval.VALUE_INVALID || ee.getErrorCode() == ErrorEval.VALUE_INVALID.getErrorCode()); + return b ? "Error code: #VALUE! (invalid value)" : "Error code=" + ee.getErrorCode(); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java b/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java index 2fa92b0b16..1180c2dbcd 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java @@ -19,7 +19,6 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFSheet; @@ -109,9 +108,7 @@ public final class TestCalendarFieldFunction { cell11.setCellFormula(formulaText); evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); - if (cv.getCellType() != CellType.NUMERIC) { - throw new AssertionFailedError("Wrong result type: " + cv.formatAsString()); - } + assertEquals("Wrong result type", CellType.NUMERIC, cv.getCellType()); double actualValue = cv.getNumberValue(); assertEquals(expectedResult, actualValue, 0); } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java b/src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java index 409888031b..36a6f8dfa1 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -152,9 +151,7 @@ public final class TestCountFuncs { assertNotNull(mp); StringEval seA = new StringEval("aa"); // this should not match the criteria '<>aa' StringEval seB = new StringEval("bb"); // this should match - if (mp.matches(seA) && !mp.matches(seB)) { - throw new AssertionFailedError("Identified bug 46647"); - } + assertFalse("Identified bug 46647", mp.matches(seA) && !mp.matches(seB)); assertFalse(mp.matches(seA)); assertTrue(mp.matches(seB)); @@ -280,16 +277,19 @@ public final class TestCountFuncs { I_MatchPredicate mp; mp = Countif.createCriteriaPredicate(ev, 9, srcColIx); + assertNotNull(mp); confirmPredicate(true, mp, srcColIx); confirmPredicate(false, mp, "abc"); confirmPredicate(false, mp, ErrorEval.DIV_ZERO); mp = Countif.createCriteriaPredicate(ev, 10, srcColIx); + assertNotNull(mp); confirmPredicate(false, mp, srcColIx); confirmPredicate(true, mp, "abc"); confirmPredicate(false, mp, ErrorEval.DIV_ZERO); mp = Countif.createCriteriaPredicate(ev, 11, srcColIx); + assertNotNull(mp); confirmPredicate(false, mp, srcColIx); confirmPredicate(false, mp, "abc"); confirmPredicate(true, mp, ErrorEval.DIV_ZERO); @@ -298,6 +298,7 @@ public final class TestCountFuncs { // tricky: indexing outside of A10:A12 // even this #VALUE! error gets used by COUNTIF as valid criteria mp = Countif.createCriteriaPredicate(ev, 12, srcColIx); + assertNotNull(mp); confirmPredicate(false, mp, srcColIx); confirmPredicate(false, mp, "abc"); confirmPredicate(false, mp, ErrorEval.DIV_ZERO); @@ -396,7 +397,7 @@ public final class TestCountFuncs { * and NEQ cases */ @Test - public void testCountifBug51498() throws Exception { + public void testCountifBug51498() { final int REF_COL = 4; final int EVAL_COL = 3; @@ -588,9 +589,6 @@ public final class TestCountFuncs { } } - if (failureCount > 0) { - throw new AssertionFailedError(failureCount + " " + functionName - + " evaluations failed. See stderr for more details"); - } + assertEquals(failureCount + " " + functionName + " evaluations failed.", 0, failureCount); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java index 536697170c..f1b528d2c9 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java @@ -19,7 +19,6 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFSheet; @@ -50,6 +49,7 @@ public final class TestDate { * Test disabled pending a fix in the formula evaluator * TODO - create MissingArgEval and modify the formula evaluator to handle this */ + @Test @Ignore public void testSomeArgumentsMissing() { confirm("DATE(, 1, 0)", 0.0); @@ -58,7 +58,6 @@ public final class TestDate { @Test public void testValid() { - confirm("DATE(1900, 1, 1)", 1); confirm("DATE(1900, 1, 32)", 32); confirm("DATE(1900, 222, 1)", 6727); @@ -88,9 +87,7 @@ public final class TestDate { cell11.setCellFormula(formulaText); evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); - if (cv.getCellType() != CellType.NUMERIC) { - throw new AssertionFailedError("Wrong result type: " + cv.formatAsString()); - } + assertEquals("Wrong result type", CellType.NUMERIC, cv.getCellType()); double actualValue = cv.getNumberValue(); assertEquals(expectedResult, actualValue, 0); } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java index 04ed1e7223..fbb63dc0bd 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue; import java.util.Arrays; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.WorkbookEvaluator; @@ -45,8 +44,6 @@ import org.junit.Test; * with minimum overhead.<br> * Another test: {@link TestIndexFunctionFromSpreadsheet} operates from a higher level * and has far greater coverage of input permutations.<br> - * - * @author Josh Micich */ public final class TestIndex { @@ -121,15 +118,8 @@ public final class TestIndex { }; AreaEval arg0 = EvalFactory.createAreaEval("A10:C10", values); ValueEval[] args = new ValueEval[] { arg0, MissingArgEval.instance, new NumberEval(2), }; - ValueEval actualResult; - try { - actualResult = FUNC_INST.evaluate(args, -1, -1); - } catch (RuntimeException e) { - if (e.getMessage().equals("Unexpected arg eval type (org.apache.poi.hssf.record.formula.eval.MissingArgEval")) { - throw new AssertionFailedError("Identified bug 47048b - INDEX() should support missing-arg"); - } - throw e; - } + // Identified bug 47048b - INDEX() should support missing-arg + ValueEval actualResult = FUNC_INST.evaluate(args, -1, -1); // result should be an area eval "B10:B10" AreaEval ae = confirmAreaEval("B10:B10", actualResult); actualResult = ae.getValue(0, 0); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java index ec01268fa8..9dc7558485 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java @@ -19,7 +19,6 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -32,8 +31,6 @@ import org.junit.Test; /** * Tests for {@link Irr} - * - * @author Marcel May */ public final class TestIrr { @@ -123,10 +120,7 @@ public final class TestIrr { } } - if(failures.length() > 0) { - throw new AssertionFailedError(failureCount + " IRR assertions failed:\n" + failures); - } - + assertEquals("IRR assertions failed", 0, failures.length()); } private static void assertFormulaResult(CellValue cv, HSSFCell cell){ diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java b/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java index a8bdd77097..5a5d123fff 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java @@ -18,8 +18,8 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -42,48 +42,36 @@ import org.junit.Test; public final class TestMirr { @Test - public void testMirr() { + public void testMirr() throws EvaluationException { Mirr mirr = new Mirr(); double mirrValue; double financeRate = 0.12; double reinvestRate = 0.1; double[] values = {-120000d, 39000d, 30000d, 21000d, 37000d, 46000d, reinvestRate, financeRate}; - try { - mirrValue = mirr.evaluate(values); - } catch (EvaluationException e) { - throw new AssertionFailedError("MIRR should not failed with these parameters" + e); - } + // MIRR should not failed with these parameters + mirrValue = mirr.evaluate(values); assertEquals("mirr", 0.126094130366, mirrValue, 0.0000000001); reinvestRate = 0.05; financeRate = 0.08; values = new double[]{-7500d, 3000d, 5000d, 1200d, 4000d, reinvestRate, financeRate}; - try { - mirrValue = mirr.evaluate(values); - } catch (EvaluationException e) { - throw new AssertionFailedError("MIRR should not failed with these parameters" + e); - } + // MIRR should not failed with these parameters + mirrValue = mirr.evaluate(values); assertEquals("mirr", 0.18736225093, mirrValue, 0.0000000001); reinvestRate = 0.065; financeRate = 0.1; values = new double[]{-10000, 3400d, 6500d, 1000d, reinvestRate, financeRate}; - try { - mirrValue = mirr.evaluate(values); - } catch (EvaluationException e) { - throw new AssertionFailedError("MIRR should not failed with these parameters" + e); - } + // MIRR should not failed with these parameters + mirrValue = mirr.evaluate(values); assertEquals("mirr", 0.07039493966, mirrValue, 0.0000000001); reinvestRate = 0.07; financeRate = 0.01; values = new double[]{-10000d, -3400d, -6500d, -1000d, reinvestRate, financeRate}; - try { - mirrValue = mirr.evaluate(values); - } catch (EvaluationException e) { - throw new AssertionFailedError("MIRR should not failed with these parameters" + e); - } + // MIRR should not failed with these parameters + mirrValue = mirr.evaluate(values); assertEquals("mirr", -1, mirrValue, 0.0); } @@ -101,7 +89,7 @@ public final class TestMirr { assertEquals(ErrorEval.DIV_ZERO, e.getErrorEval()); return; } - throw new AssertionFailedError("MIRR should failed with all these positives values"); + fail("MIRR should failed with all these positives values"); } @Test @@ -134,7 +122,6 @@ public final class TestMirr { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("mirrTest.xls"); HSSFSheet sheet = wb.getSheet("Mirr"); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - StringBuilder failures = new StringBuilder(); int failureCount = 0; int[] resultRows = {9, 19, 29, 45}; @@ -145,9 +132,6 @@ public final class TestMirr { CellValue cv = fe.evaluate(cellA); assertFormulaResult(cv, cellA); } catch (Throwable e) { - if (failures.length() > 0) failures.append('\n'); - failures.append("Row[").append(cellA.getRowIndex() + 1).append("]: ").append(cellA.getCellFormula()).append(" "); - failures.append(e.getMessage()); failureCount++; } } @@ -157,10 +141,7 @@ public final class TestMirr { CellValue cv = fe.evaluate(cellA); assertEquals(ErrorEval.DIV_ZERO.getErrorCode(), cv.getErrorValue()); - if (failures.length() > 0) { - throw new AssertionFailedError(failureCount + " IRR assertions failed:\n" + failures); - } - + assertEquals("IRR assertions failed", 0, failureCount); } private static void assertFormulaResult(CellValue cv, HSSFCell cell) { diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java b/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java index 8d3f6c287b..4df5bc898d 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java @@ -19,7 +19,6 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -32,7 +31,6 @@ import org.junit.Test; /** * Tests for {@link Npv} * - * @author Marcel May * @see <a href="http://office.microsoft.com/en-us/excel-help/npv-HP005209199.aspx">Excel Help</a> */ public final class TestNpv { @@ -79,7 +77,6 @@ public final class TestNpv { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("IrrNpvTestCaseData.xls"); HSSFSheet sheet = wb.getSheet("IRR-NPV"); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - StringBuilder failures = new StringBuilder(); int failureCount = 0; // TODO YK: Formulas in rows 16 and 17 operate with ArrayPtg which isn't yet supported // FormulaEvaluator as of r1041407 throws "Unexpected ptg class (org.apache.poi.ss.formula.ptg.ArrayPtg)" @@ -90,16 +87,11 @@ public final class TestNpv { CellValue cv = fe.evaluate(cellB); assertFormulaResult(cv, cellB); } catch (Throwable e){ - if(failures.length() > 0) failures.append('\n'); - failures.append("Row[" + (cellB.getRowIndex() + 1)+ "]: " + cellB.getCellFormula() + " "); - failures.append(e.getMessage()); failureCount++; } } - if(failures.length() > 0) { - throw new AssertionFailedError(failureCount + " IRR evaluations failed:\n" + failures); - } + assertEquals("IRR evaluations failed", 0, failureCount); } private static void assertFormulaResult(CellValue cv, HSSFCell cell){ diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java b/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java index 3c3536a273..b489cdcb4b 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java @@ -20,23 +20,21 @@ */ package org.apache.poi.ss.formula.functions; -import junit.framework.AssertionFailedError; +import static org.junit.Assert.assertNotNull; + import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.EvaluationException; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; -/** - * @author Amol S. Deshmukh < amolweb at ya hoo dot com > - * - */ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testDevsq() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.devsq(v); @@ -71,8 +69,8 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testKthLargest() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.kthLargest(v, 3); @@ -105,13 +103,15 @@ public class TestStatsLib extends AbstractNumericTestCase { assertEquals("kthLargest ", x, d); } + @Test + @Ignore("... implement ...") public void testKthSmallest() { } @Test public void testAvedev() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.avedev(v); @@ -146,8 +146,8 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testMedian() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.median(v); @@ -193,7 +193,6 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testMode() { double[] v; - double d, x = 0; v = new double[] {1,2,3,4,5,6,7,8,9,10}; confirmMode(v, null); @@ -228,9 +227,7 @@ public class TestStatsLib extends AbstractNumericTestCase { double actual; try { actual = Mode.evaluate(v); - if (expectedResult == null) { - throw new AssertionFailedError("Expected N/A exception was not thrown"); - } + assertNotNull("Expected N/A exception was not thrown", expectedResult); } catch (EvaluationException e) { if (expectedResult == null) { Assert.assertEquals(ErrorEval.NA, e.getErrorEval()); @@ -243,8 +240,8 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testStddev() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {1,2,3,4,5,6,7,8,9,10}; d = StatsLib.stdev(v); @@ -279,8 +276,8 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testVar() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {3.50, 5.00, 7.23, 2.99}; d = StatsLib.var(v); @@ -305,8 +302,8 @@ public class TestStatsLib extends AbstractNumericTestCase { @Test public void testVarp() { - double[] v = null; - double d, x = 0; + double[] v; + double d, x; v = new double[] {3.50, 5.00, 7.23, 2.99}; d = StatsLib.varp(v); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java b/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java index b0d1483e54..7f5aabcbd5 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java @@ -18,8 +18,9 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; -import junit.framework.AssertionFailedError; import org.apache.poi.ss.formula.eval.AreaEval; import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -31,8 +32,6 @@ import org.junit.Test; /** * Test cases for SUMPRODUCT() - * - * @author Josh Micich */ public final class TestSumif { private static final NumberEval _30 = new NumberEval(30); @@ -45,9 +44,7 @@ public final class TestSumif { } private static void confirmDouble(double expected, ValueEval actualEval) { - if(!(actualEval instanceof NumericValueEval)) { - throw new AssertionFailedError("Expected numeric result"); - } + assertTrue("Expected numeric result", actualEval instanceof NumericValueEval); NumericValueEval nve = (NumericValueEval)actualEval; assertEquals(expected, nve.getNumberValue(), 0); } @@ -99,9 +96,7 @@ public final class TestSumif { ve = invokeSumif(0, 2, arg0, arg1); // invoking from cell C1 if (ve instanceof NumberEval) { NumberEval ne = (NumberEval) ve; - if (ne.getNumberValue() == 30.0) { - throw new AssertionFailedError("identified error in SUMIF - criteria arg not evaluated properly"); - } + assertNotEquals("identified error in SUMIF - criteria arg not evaluated properly", 30.0, ne.getNumberValue()); } confirmDouble(200, ve); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java b/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java index c9d640f91f..4e441a066e 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java @@ -22,7 +22,6 @@ package org.apache.poi.ss.formula.functions; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import junit.framework.AssertionFailedError; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -38,27 +37,23 @@ import org.junit.Test; /** * Test cases for SUMIFS() - * - * @author Yegor Kozlov */ public final class TestSumifs { private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 0, 1, 0, null); - private static ValueEval invokeSumifs(ValueEval[] args, OperationEvaluationContext ec) { + private static ValueEval invokeSumifs(ValueEval[] args) { return new Sumifs().evaluate(args, EC); } private static void confirmDouble(double expected, ValueEval actualEval) { - if(!(actualEval instanceof NumericValueEval)) { - throw new AssertionFailedError("Expected numeric result"); - } + assertTrue("Expected numeric result", actualEval instanceof NumericValueEval); NumericValueEval nve = (NumericValueEval)actualEval; assertEquals(expected, nve.getNumberValue(), 0); } private static void confirm(double expectedResult, ValueEval[] args) { - confirmDouble(expectedResult, invokeSumifs(args, EC)); + confirmDouble(expectedResult, invokeSumifs(args)); } /** @@ -140,7 +135,7 @@ public final class TestSumifs { EvalFactory.createAreaEval("C2:C9", c2c9), new NumberEval(1), }; - assertEquals(ErrorEval.VALUE_INVALID, invokeSumifs(args, EC)); + assertEquals(ErrorEval.VALUE_INVALID, invokeSumifs(args)); } @@ -189,6 +184,8 @@ public final class TestSumifs { new StringEval(">0.03"), // 3% in the MSFT example EvalFactory.createAreaEval("B4:E4", b4e4), new StringEval(">=0.02"), // 2% in the MSFT example + EvalFactory.createAreaEval("B5:E5", b5e5), + new StringEval(">=0.01"), // 1% in the MSFT example }; confirm(500.0, args); } @@ -299,7 +296,7 @@ public final class TestSumifs { new StringEval("A*"), }; - ValueEval result = invokeSumifs(args, EC); + ValueEval result = invokeSumifs(args); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); args = new ValueEval[]{ @@ -308,7 +305,7 @@ public final class TestSumifs { ErrorEval.VALUE_INVALID, }; - result = invokeSumifs(args, EC); + result = invokeSumifs(args); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); } @@ -332,7 +329,7 @@ public final class TestSumifs { ErrorEval.VALUE_INVALID }; - ValueEval result = invokeSumifs(args, EC); + ValueEval result = invokeSumifs(args); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); assertEquals(ErrorEval.VALUE_INVALID, result); } @@ -357,7 +354,7 @@ public final class TestSumifs { ErrorEval.NAME_INVALID }; - ValueEval result = invokeSumifs(args, EC); + ValueEval result = invokeSumifs(args); assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval); assertEquals(ErrorEval.NAME_INVALID, result); } |