Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java Thu Dec 24 18:42:29 2020 @@ -17,11 +17,13 @@ package org.apache.poi.ss.formula; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; @@ -47,8 +49,8 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellRangeAddress; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * Tests {@link WorkbookEvaluator}. @@ -194,12 +196,9 @@ public class TestWorkbookEvaluator { HSSFCell cell = row.createCell(0); cell.setCellFormula("1+IF(1,,)"); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - CellValue cv = null; - try { - cv = fe.evaluate(cell); - } catch (RuntimeException e) { - fail("Missing arg result not being handled correctly."); - } + assertDoesNotThrow(() -> fe.evaluate(cell), "Missing arg result not being handled correctly."); + + CellValue cv = fe.evaluate(cell); assertEquals(CellType.NUMERIC, cv.getCellType()); // adding blank to 1.0 gives 1.0 assertEquals(1.0, cv.getNumberValue(), 0.0); @@ -260,7 +259,7 @@ public class TestWorkbookEvaluator { public void testNamesInFormulas() throws IOException { Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("Sheet1"); - + Name name1 = wb.createName(); name1.setNameName("aConstant"); name1.setRefersToFormula("3.14"); @@ -272,27 +271,27 @@ public class TestWorkbookEvaluator { Name name3 = wb.createName(); name3.setNameName("aSet"); name3.setRefersToFormula("Sheet1!$A$2:$A$4"); - + Name name4 = wb.createName(); name4.setNameName("offsetFormula"); name4.setRefersToFormula("OFFSET(Sheet1!$A$1:$A$4,2,0,2,1)"); - + Name name5 = wb.createName(); name5.setNameName("rowFormula"); name5.setRefersToFormula("ROW()"); - + Row row0 = sheet.createRow(0); Row row1 = sheet.createRow(1); Row row2 = sheet.createRow(2); Row row3 = sheet.createRow(3); Row row4 = sheet.createRow(4); Row row5 = sheet.createRow(5); - + row0.createCell(0).setCellValue(2); row1.createCell(0).setCellValue(5); row2.createCell(0).setCellValue(3); row3.createCell(0).setCellValue(7); - + row0.createCell(2).setCellFormula("aConstant"); row1.createCell(2).setCellFormula("aFormula"); row2.createCell(2).setCellFormula("SUM(aSet)"); @@ -307,10 +306,10 @@ public class TestWorkbookEvaluator { assertEquals(28.14, fe.evaluate(row3.getCell(2)).getNumberValue(), EPSILON); assertEquals(10.0, fe.evaluate(row4.getCell(2)).getNumberValue(), EPSILON); assertEquals(6.0, fe.evaluate(row5.getCell(2)).getNumberValue(), EPSILON); - + wb.close(); } - + @Test public void testIgnoreMissingWorkbooks() { // TODO: update this test for meaningful functional behavior @@ -336,9 +335,9 @@ public class TestWorkbookEvaluator { evaluator.setDebugEvaluationOutputForNextEval(false); assertFalse(evaluator.isDebugEvaluationOutputForNextEval()); } - + // Test IF-Equals Formula Evaluation (bug 58591) - + private Workbook testIFEqualsFormulaEvaluation_setup(String formula, CellType a1CellType) { Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("IFEquals"); @@ -347,7 +346,7 @@ public class TestWorkbookEvaluator { Cell B1 = row.createCell(1); Cell C1 = row.createCell(2); Cell D1 = row.createCell(3); - + switch (a1CellType) { case NUMERIC: A1.setCellValue(1.0); @@ -376,38 +375,34 @@ public class TestWorkbookEvaluator { B1.setCellValue(2.0); C1.setCellValue(3.0); D1.setCellFormula(formula); - + return wb; } - + private void testIFEqualsFormulaEvaluation_teardown(Workbook wb) { - try { - wb.close(); - } catch (final IOException e) { - fail("Unable to close workbook"); - } + assertDoesNotThrow(wb::close, "Unable to close workbook"); } - - - + + + private void testIFEqualsFormulaEvaluation_evaluate( 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(); CellValue result = eval.evaluate(D1); - + // Call should not modify the contents assertEquals(CellType.FORMULA, D1.getCellType()); assertEquals(expectedFormula, D1.getCellFormula()); - + assertEquals(CellType.NUMERIC, result.getCellType()); assertEquals(expectedResult, result.getNumberValue(), EPSILON); - + testIFEqualsFormulaEvaluation_teardown(wb); } - + private void testIFEqualsFormulaEvaluation_eval( final String formula, final CellType cellType, final String expectedFormula, final double expectedValue) { testIFEqualsFormulaEvaluation_evaluate(formula, cellType, expectedFormula, expectedValue); @@ -416,7 +411,7 @@ public class TestWorkbookEvaluator { testIFEqualsFormulaEvaluation_evaluateAll(formula, cellType, expectedFormula, expectedValue); testIFEqualsFormulaEvaluation_evaluateAllFormulaCells(formula, cellType, expectedFormula, expectedValue); } - + @Test public void testIFEqualsFormulaEvaluation_NumericLiteral() { final String formula = "IF(A1=1, 2, 3)"; @@ -425,7 +420,7 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - + @Test public void testIFEqualsFormulaEvaluation_Numeric() { final String formula = "IF(A1=1, B1, C1)"; @@ -434,7 +429,7 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - + @Test public void testIFEqualsFormulaEvaluation_NumericCoerceToString() { final String formula = "IF(A1&\"\"=\"1\", B1, C1)"; @@ -443,7 +438,7 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - + @Test public void testIFEqualsFormulaEvaluation_String() { final String formula = "IF(A1=1, B1, C1)"; @@ -452,7 +447,7 @@ public class TestWorkbookEvaluator { final double expectedValue = 3.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - + @Test public void testIFEqualsFormulaEvaluation_StringCompareToString() { final String formula = "IF(A1=\"1\", B1, C1)"; @@ -461,7 +456,7 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - + @Test public void testIFEqualsFormulaEvaluation_StringCoerceToNumeric() { final String formula = "IF(A1+0=1, B1, C1)"; @@ -470,8 +465,8 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - - @Ignore("Bug 58591: this test currently fails") + + @Disabled("Bug 58591: this test currently fails") @Test public void testIFEqualsFormulaEvaluation_Boolean() { final String formula = "IF(A1=1, B1, C1)"; @@ -480,8 +475,8 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - - @Ignore("Bug 58591: this test currently fails") + + @Disabled("Bug 58591: this test currently fails") @Test public void testIFEqualsFormulaEvaluation_BooleanSimple() { final String formula = "3-(A1=1)"; @@ -490,7 +485,7 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - + @Test public void testIFEqualsFormulaEvaluation_Formula() { final String formula = "IF(A1=1, B1, C1)"; @@ -499,7 +494,7 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - + @Test public void testIFEqualsFormulaEvaluation_Blank() { final String formula = "IF(A1=1, B1, C1)"; @@ -508,7 +503,7 @@ public class TestWorkbookEvaluator { final double expectedValue = 3.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - + @Test public void testIFEqualsFormulaEvaluation_BlankCompareToZero() { final String formula = "IF(A1=0, B1, C1)"; @@ -517,8 +512,8 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - - @Ignore("Bug 58591: this test currently fails") + + @Disabled("Bug 58591: this test currently fails") @Test public void testIFEqualsFormulaEvaluation_BlankInverted() { final String formula = "IF(NOT(A1)=1, B1, C1)"; @@ -527,8 +522,8 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - - @Ignore("Bug 58591: this test currently fails") + + @Disabled("Bug 58591: this test currently fails") @Test public void testIFEqualsFormulaEvaluation_BlankInvertedSimple() { final String formula = "3-(NOT(A1)=1)"; @@ -537,81 +532,77 @@ public class TestWorkbookEvaluator { final double expectedValue = 2.0; testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue); } - - + + private void testIFEqualsFormulaEvaluation_evaluateFormulaCell( 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(); CellType resultCellType = eval.evaluateFormulaCell(D1); - + // Call should modify the contents, but leave the formula intact assertEquals(CellType.FORMULA, D1.getCellType()); assertEquals(expectedFormula, D1.getCellFormula()); assertEquals(CellType.NUMERIC, resultCellType); assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultType()); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); - + testIFEqualsFormulaEvaluation_teardown(wb); } - + private void testIFEqualsFormulaEvaluation_evaluateInCell( String formula, CellType cellType, double expectedResult) { Workbook wb = testIFEqualsFormulaEvaluation_setup(formula, cellType); Cell D1 = wb.getSheet("IFEquals").getRow(0).getCell(3); - + FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator(); Cell result = eval.evaluateInCell(D1); - + // Call should modify the contents and replace the formula with the result - assertSame(D1, result); // returns the same cell that was provided as an argument so that calls can be chained. - try { - D1.getCellFormula(); - fail("cell formula should be overwritten with formula result"); - } catch (final IllegalStateException expected) { - // expected here - } + // returns the same cell that was provided as an argument so that calls can be chained. + assertSame(D1, result); + assertThrows(IllegalStateException.class, D1::getCellFormula, "cell formula should be overwritten with formula result"); assertEquals(CellType.NUMERIC, D1.getCellType()); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); - + testIFEqualsFormulaEvaluation_teardown(wb); } - + private void testIFEqualsFormulaEvaluation_evaluateAll( 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(); eval.evaluateAll(); - + // Call should modify the contents assertEquals(CellType.FORMULA, D1.getCellType()); assertEquals(expectedFormula, D1.getCellFormula()); - + assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultType()); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); - + testIFEqualsFormulaEvaluation_teardown(wb); } - + private void testIFEqualsFormulaEvaluation_evaluateAllFormulaCells( 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(CellType.FORMULA, D1.getCellType()); // whitespace gets deleted because formula is parsed and re-rendered assertEquals(expectedFormula, D1.getCellFormula()); - + assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultType()); assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON); - + testIFEqualsFormulaEvaluation_teardown(wb); }
Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java Thu Dec 24 18:42:29 2020 @@ -16,7 +16,7 @@ ==================================================================== */ package org.apache.poi.ss.formula.atp; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; @@ -28,7 +28,7 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Testcase for 'Analysis Toolpak' function IFERROR() @@ -79,21 +79,20 @@ public class TestIfError { FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); - assertEquals("Checks that the cell is numeric", - CellType.NUMERIC, evaluator.evaluate(cell1).getCellType()); - assertEquals("Divides 210 by 35 and returns 6.0", - 6.0, evaluator.evaluate(cell1).getNumberValue(), accuracy); - - - assertEquals("Checks that the cell is numeric", - CellType.STRING, evaluator.evaluate(cell2).getCellType()); - assertEquals("Rounds -10 to a nearest multiple of -3 (-9)", - "Error in calculation", evaluator.evaluate(cell2).getStringValue()); - - assertEquals("Check that C1 returns string", - CellType.STRING, evaluator.evaluate(cell3).getCellType()); - assertEquals("Check that C1 returns string \"error\"", - "error", evaluator.evaluate(cell3).getStringValue()); + assertEquals(CellType.NUMERIC, evaluator.evaluate(cell1).getCellType(), + "Checks that the cell is numeric"); + assertEquals(6.0, evaluator.evaluate(cell1).getNumberValue(), accuracy, + "Divides 210 by 35 and returns 6.0"); + + assertEquals(CellType.STRING, evaluator.evaluate(cell2).getCellType(), + "Checks that the cell is numeric"); + assertEquals("Error in calculation", evaluator.evaluate(cell2).getStringValue(), + "Rounds -10 to a nearest multiple of -3 (-9)"); + + assertEquals(CellType.STRING, evaluator.evaluate(cell3).getCellType(), + "Check that C1 returns string"); + assertEquals("error", evaluator.evaluate(cell3).getStringValue(), + "Check that C1 returns string \"error\""); } } } Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java Thu Dec 24 18:42:29 2020 @@ -16,7 +16,7 @@ ==================================================================== */ package org.apache.poi.ss.formula.atp; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -24,7 +24,7 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Testcase for 'Analysis Toolpak' function MROUND() @@ -56,19 +56,19 @@ public class TestMRound { FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); - assertEquals("Rounds 10 to a nearest multiple of 3 (9)", - 9.0, evaluator.evaluate(cell1).getNumberValue(), accuracy); + assertEquals(9.0, evaluator.evaluate(cell1).getNumberValue(), accuracy, + "Rounds 10 to a nearest multiple of 3 (9)"); - assertEquals("Rounds -10 to a nearest multiple of -3 (-9)", - -9.0, evaluator.evaluate(cell2).getNumberValue(), accuracy); + assertEquals(-9.0, evaluator.evaluate(cell2).getNumberValue(), accuracy, + "Rounds -10 to a nearest multiple of -3 (-9)"); - assertEquals("Rounds 1.3 to a nearest multiple of 0.2 (1.4)", - 1.4, evaluator.evaluate(cell3).getNumberValue(), accuracy); + assertEquals(1.4, evaluator.evaluate(cell3).getNumberValue(), accuracy, + "Rounds 1.3 to a nearest multiple of 0.2 (1.4)"); - assertEquals("Returns an error, because -2 and 5 have different signs (#NUM!)", - ErrorEval.NUM_ERROR.getErrorCode(), evaluator.evaluate(cell4).getErrorValue()); + assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), evaluator.evaluate(cell4).getErrorValue(), + "Returns an error, because -2 and 5 have different signs (#NUM!)"); - assertEquals("Returns 0 because the multiple is 0", - 0.0, evaluator.evaluate(cell5).getNumberValue(), 0); + assertEquals(0.0, evaluator.evaluate(cell5).getNumberValue(), 0, + "Returns 0 because the multiple is 0"); } } Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java Thu Dec 24 18:42:29 2020 @@ -19,7 +19,7 @@ package org.apache.poi.ss.formula.atp; import static org.apache.poi.ss.formula.eval.ErrorEval.NAME_INVALID; import static org.apache.poi.ss.formula.eval.ErrorEval.VALUE_INVALID; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.List; @@ -31,7 +31,7 @@ import org.apache.poi.ss.formula.eval.Ar 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.junit.Test; +import org.junit.jupiter.api.Test; public class TestNetworkdaysFunction { Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java Thu Dec 24 18:42:29 2020 @@ -16,7 +16,7 @@ ==================================================================== */ package org.apache.poi.ss.formula.atp; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.poi.ss.formula.eval.AreaEval; import org.apache.poi.ss.formula.eval.BlankEval; @@ -26,7 +26,7 @@ import org.apache.poi.ss.formula.eval.Nu import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.functions.AggregateFunction; import org.apache.poi.ss.formula.functions.EvalFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Testcase for Excel function PERCENTILE() Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java Thu Dec 24 18:42:29 2020 @@ -16,8 +16,8 @@ ==================================================================== */ package org.apache.poi.ss.formula.atp; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -27,23 +27,22 @@ import org.apache.poi.ss.usermodel.Formu import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Testcase for 'Analysis Toolpak' function RANDBETWEEN() */ public class TestRandBetween { - private Workbook wb; private FormulaEvaluator evaluator; private Cell bottomValueCell; private Cell topValueCell; private Cell formulaCell; - @Before + @BeforeEach public void setUp() throws Exception { - wb = HSSFTestDataSamples.openSampleWorkbook("TestRandBetween.xls"); + Workbook wb = HSSFTestDataSamples.openSampleWorkbook("TestRandBetween.xls"); evaluator = wb.getCreationHelper().createFormulaEvaluator(); Sheet sheet = wb.createSheet("RandBetweenSheet"); @@ -76,8 +75,8 @@ public class TestRandBetween { formulaCell.setCellFormula("RANDBETWEEN(0,9999999999)"); evaluator.evaluateFormulaCell(formulaCell); double value = formulaCell.getNumericCellValue(); - assertTrue("rand is greater than or equal to lowerbound", value >= 0.0); - assertTrue("rand is less than or equal to upperbound", value <= 9999999999.0); + assertTrue(value >= 0.0, "rand is greater than or equal to lowerbound"); + assertTrue(value <= 9999999999.0, "rand is less than or equal to upperbound"); } } Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java Thu Dec 24 18:42:29 2020 @@ -18,14 +18,14 @@ package org.apache.poi.ss.formula.atp; import static java.util.Calendar.SATURDAY; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Calendar; import java.util.Date; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.util.LocaleUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestWorkdayCalculator { @@ -139,8 +139,7 @@ public class TestWorkdayCalculator { final double holiday1 = DateUtil.getExcelDate(d(2016, 12, 25)); final double holiday2 = DateUtil.getExcelDate(d(2016, 12, 26)); int count = WorkdayCalculator.instance.calculateNonWeekendHolidays(start, end, new double[]{holiday1, holiday2}); - assertEquals("Expected 1 non-weekend-holiday for " + start + " to " + end + " and " + holiday1 + " and " + holiday2, - 1, count); + assertEquals(1, count, "Expected 1 non-weekend-holiday for " + start + " to " + end + " and " + holiday1 + " and " + holiday2); } @Test @@ -150,7 +149,6 @@ public class TestWorkdayCalculator { final double holiday1 = DateUtil.getExcelDate(d(2016, 12, 25)); final double holiday2 = DateUtil.getExcelDate(d(2016, 12, 26)); int count = WorkdayCalculator.instance.calculateNonWeekendHolidays(start, end, new double[]{holiday1, holiday2}); - assertEquals("Expected 1 non-weekend-holiday for " + start + " to " + end + " and " + holiday1 + " and " + holiday2, - 1, count); + assertEquals(1, count, "Expected 1 non-weekend-holiday for " + start + " to " + end + " and " + holiday1 + " and " + holiday2); } } Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java Thu Dec 24 18:42:29 2020 @@ -20,7 +20,7 @@ package org.apache.poi.ss.formula.atp; import static org.apache.poi.ss.formula.eval.ErrorEval.VALUE_INVALID; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.Calendar; @@ -36,7 +36,7 @@ import org.apache.poi.ss.formula.eval.St import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.util.LocaleUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestWorkdayFunction { @@ -89,7 +89,7 @@ public class TestWorkdayFunction { ValueEval[] ve = {new StringEval("2013/09/30"), new NumberEval(-1)}; double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue(); assertEquals(41544.0, numberValue, 0); - + Date actDate = DateUtil.getJavaDate(numberValue); assertEquals(expDate, actDate); } @@ -140,7 +140,7 @@ public class TestWorkdayFunction { ValueEval[] ve = {new StringEval(STARTING_DATE), new NumberEval(151.99999)}; double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue(); - + Date actDate = DateUtil.getJavaDate(numberValue); assertEquals(expDate, actDate); } @@ -152,7 +152,7 @@ public class TestWorkdayFunction { ValueEval[] ve = {new StringEval(STARTING_DATE), new NumberEval(-5), new StringEval(RETROATIVE_HOLIDAY)}; double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue(); - + Date actDate = DateUtil.getJavaDate(numberValue); assertEquals(expDate, actDate); } @@ -166,7 +166,7 @@ public class TestWorkdayFunction { new StringEval(STARTING_DATE), new NumberEval(151), new MockAreaEval(FIRST_HOLIDAY, SECOND_HOLIDAY, THIRD_HOLIDAY)}; double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue(); - + Date actDate = DateUtil.getJavaDate(numberValue); assertEquals(expDate, actDate); } Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java Thu Dec 24 18:42:29 2020 @@ -17,14 +17,14 @@ package org.apache.poi.ss.formula.atp; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Calendar; import org.apache.poi.ss.formula.eval.EvaluationException; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.util.LocaleUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Specific test cases for YearFracCalculator @@ -56,7 +56,7 @@ public final class TestYearFracCalculato System.out.println(startDate + " " + endDate + " off by " + hours + " hours"); assertEquals(expectedValue, actualValue, 0.000000001); } - + } private static double md(int year, int month, int day) { Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.ss.formula.atp; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Calendar; import java.util.Iterator; @@ -35,13 +35,13 @@ import org.apache.poi.ss.usermodel.CellT import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.util.LocaleUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests YearFracCalculator using test-cases listed in a sample spreadsheet */ public final class TestYearFracCalculatorFromSpreadsheet { - + private static final class SS { public static final int BASIS_COLUMN = 1; // "B" @@ -53,7 +53,7 @@ public final class TestYearFracCalculato @Test public void testAll() throws Exception { - + HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("yearfracExamples.xls"); HSSFSheet sheet = wb.getSheetAt(0); HSSFFormulaEvaluator formulaEvaluator = new HSSFFormulaEvaluator(wb); @@ -61,7 +61,7 @@ public final class TestYearFracCalculato Iterator<Row> rowIterator = sheet.rowIterator(); while(rowIterator.hasNext()) { HSSFRow row = (HSSFRow) rowIterator.next(); - + HSSFCell cell = row.getCell(SS.YEARFRAC_FORMULA_COLUMN); if (cell == null || cell.getCellType() != CellType.FORMULA) { continue; @@ -70,26 +70,26 @@ public final class TestYearFracCalculato nSuccess++; } - assertTrue("No test sample cases found", nSuccess > 0); + assertTrue(nSuccess > 0, "No test sample cases found"); wb.close(); } - + private void processRow(HSSFRow row, HSSFCell cell, HSSFFormulaEvaluator formulaEvaluator) throws EvaluationException { - + double startDate = makeDate(row, SS.START_YEAR_COLUMN); double endDate = makeDate(row, SS.END_YEAR_COLUMN); - + int basis = getIntCell(row, SS.BASIS_COLUMN); - + double expectedValue = getDoubleCell(row, SS.EXPECTED_RESULT_COLUMN); - + double actualValue = YearFracCalculator.calculate(startDate, endDate, basis); String loc = " - row " + (row.getRowNum()+1); - assertEquals("Direct calculate failed"+loc, expectedValue, actualValue, 0); + assertEquals(expectedValue, actualValue, 0, "Direct calculate failed"+loc); actualValue = formulaEvaluator.evaluate(cell).getNumberValue(); - assertEquals("Formula evaluate failed"+loc, expectedValue, actualValue, 0); + assertEquals(expectedValue, actualValue, 0, "Formula evaluate failed"+loc); } private static double makeDate(HSSFRow row, int yearColumn) { @@ -103,13 +103,13 @@ public final class TestYearFracCalculato private static int getIntCell(HSSFRow row, int colIx) { double dVal = getDoubleCell(row, colIx); String msg = "Non integer value (" + dVal + ") cell found at column " + (char)('A' + colIx); - assertEquals(msg, Math.floor(dVal), dVal, 0); + assertEquals(Math.floor(dVal), dVal, 0, msg); return (int)dVal; } private static double getDoubleCell(HSSFRow row, int colIx) { HSSFCell cell = row.getCell(colIx); - assertNotNull("No cell found at column " + colIx, cell); + assertNotNull(cell, "No cell found at column " + colIx); return cell.getNumericCellValue(); } } Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java Thu Dec 24 18:42:29 2020 @@ -18,17 +18,16 @@ package org.apache.poi.ss.formula.constant; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.util.Arrays; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.ss.usermodel.FormulaError; import org.apache.poi.util.HexRead; import org.apache.poi.util.LittleEndianByteArrayOutputStream; import org.apache.poi.util.LittleEndianInput; -import org.junit.Test; +import org.junit.jupiter.api.Test; public final class TestConstantValueParser { private static final Object[] SAMPLE_VALUES = { @@ -58,9 +57,7 @@ public final class TestConstantValuePars ConstantValueParser.encode(new LittleEndianByteArrayOutputStream(data, 0), SAMPLE_VALUES); - if (!Arrays.equals(data, SAMPLE_ENCODING)) { - fail("Encoding differs"); - } + assertArrayEquals(SAMPLE_ENCODING, data, "Encoding differs"); } @Test @@ -69,9 +66,7 @@ public final class TestConstantValuePars Object[] values = ConstantValueParser.parse(in, 4); for (int i = 0; i < values.length; i++) { - if(!isEqual(SAMPLE_VALUES[i], values[i])) { - fail("Decoded result differs"); - } + assertTrue(isEqual(SAMPLE_VALUES[i], values[i]), "Decoded result differs"); } } private static boolean isEqual(Object a, Object b) { Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java Thu Dec 24 18:42:29 2020 @@ -16,11 +16,11 @@ ==================================================================== */ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; @@ -32,7 +32,7 @@ import org.apache.poi.ss.usermodel.Formu import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Common superclass for testing cases of circular references Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java Thu Dec 24 18:42:29 2020 @@ -18,14 +18,14 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.functions.EvalFactory; import org.apache.poi.ss.formula.ptg.AreaPtg; import org.apache.poi.ss.util.AreaReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for <tt>AreaEval</tt> @@ -46,7 +46,7 @@ public final class TestAreaEval { new NumberEval(6), }; AreaEval ae = EvalFactory.createAreaEval(ptg, values); - assertNotEquals("Identified bug 44950 a", one, ae.getAbsoluteValue(1, 2)); + assertNotEquals(one, ae.getAbsoluteValue(1, 2), "Identified bug 44950 a"); confirm(1, ae, 1, 1); confirm(2, ae, 1, 2); confirm(3, ae, 1, 3); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java Thu Dec 24 18:42:29 2020 @@ -17,11 +17,11 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.poi.ss.formula.functions.EvalFactory; import org.apache.poi.ss.formula.functions.NumericFunctionInvoker; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for divide operator evaluator. Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java Thu Dec 24 18:42:29 2020 @@ -17,13 +17,13 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.poi.ss.formula.functions.EvalFactory; import org.apache.poi.ss.formula.functions.Function; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for EqualEval @@ -42,7 +42,7 @@ public final class TestEqualEval { BoolEval.FALSE, }; ValueEval result = evaluate(EvalInstances.Equal, args, 10, 10); - assertNotEquals("Identified bug in evaluation of 1x1 area", ErrorEval.VALUE_INVALID, result); + assertNotEquals(ErrorEval.VALUE_INVALID, result, "Identified bug in evaluation of 1x1 area"); assertTrue(result instanceof BoolEval); assertTrue(((BoolEval)result).getBooleanValue()); } @@ -60,7 +60,7 @@ public final class TestEqualEval { ValueEval result = evaluate(EvalInstances.Equal, args, 10, 10); assertEquals(BoolEval.class, result.getClass()); BoolEval be = (BoolEval) result; - assertTrue("Identified bug blank/empty string equality", be.getBooleanValue()); + assertTrue(be.getBooleanValue(), "Identified bug blank/empty string equality"); } /** @@ -133,11 +133,11 @@ public final class TestEqualEval { public void testZeroEquality_bug47198() { NumberEval zero = new NumberEval(0.0); NumberEval mZero = (NumberEval) evaluate(UnaryMinusEval.instance, new ValueEval[] { zero, }, 0, 0); - assertNotEquals("Identified bug 47198: unary minus should convert -0.0 to 0.0", - 0x8000000000000000L, Double.doubleToLongBits(mZero.getNumberValue())); + assertNotEquals(0x8000000000000000L, Double.doubleToLongBits(mZero.getNumberValue()), + "Identified bug 47198: unary minus should convert -0.0 to 0.0"); ValueEval[] args = { zero, mZero, }; BoolEval result = (BoolEval) evaluate(EvalInstances.Equal, args, 0, 0); - assertTrue("Identified bug 47198: -0.0 != 0.0", result.getBooleanValue()); + assertTrue(result.getBooleanValue(), "Identified bug 47198: -0.0 != 0.0"); } @Test @@ -151,7 +151,7 @@ public final class TestEqualEval { ValueEval[] args = { a, b, }; BoolEval result = (BoolEval) evaluate(EvalInstances.Equal, args, 0, 0); - assertTrue("Identified bug 47598: 1+1.0028-0.9973 != 1.0055", result.getBooleanValue()); + assertTrue(result.getBooleanValue(), "Identified bug 47598: 1+1.0028-0.9973 != 1.0055"); } private static ValueEval evaluate(Function oper, ValueEval[] args, int srcRowIx, int srcColIx) { Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java Thu Dec 24 18:42:29 2020 @@ -17,7 +17,7 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; @@ -32,7 +32,7 @@ import org.apache.poi.ss.formula.functio import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; import org.apache.poi.ss.formula.udf.DefaultUDFFinder; import org.apache.poi.ss.formula.udf.UDFFinder; -import org.junit.Test; +import org.junit.jupiter.api.Test; public final class TestExternalFunction { Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java Thu Dec 24 18:42:29 2020 @@ -17,17 +17,23 @@ package org.apache.poi.ss.formula.eval; -import org.apache.poi.hssf.HSSFTestDataSamples; -import org.apache.poi.hssf.usermodel.*; -import org.apache.poi.ss.usermodel.*; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.io.InputStream; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +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.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.jupiter.api.Test; /** * Miscellaneous tests for bugzilla entries.<p> The test name contains the @@ -61,14 +67,14 @@ public final class TestFormulaBugs { assertEquals(CellType.NUMERIC, cv.getCellType()); assertEquals(3.0, cv.getNumberValue(), 0.0); - + wb.close(); is.close(); } /** * Bug 27405 - isnumber() formula always evaluates to false in if statement<p> - * + * * seems to be a duplicate of 24925 */ @Test @@ -102,18 +108,18 @@ public final class TestFormulaBugs { // throw new RuntimeException(e); // } // } - + // use POI's evaluator as an extra sanity check FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); CellValue cv; cv = fe.evaluate(cell); assertEquals(CellType.NUMERIC, cv.getCellType()); assertEquals(1.0, cv.getNumberValue(), 0.0); - + cv = fe.evaluate(row.getCell(1)); assertEquals(CellType.BOOLEAN, cv.getCellType()); assertTrue(cv.getBooleanValue()); - + wb.close(); } @@ -122,49 +128,48 @@ public final class TestFormulaBugs { */ @Test public void test42448() throws IOException { - Workbook wb = new HSSFWorkbook(); - Sheet sheet1 = wb.createSheet("Sheet1"); + try (Workbook wb = new HSSFWorkbook()) { + Sheet sheet1 = wb.createSheet("Sheet1"); - Row row = sheet1.createRow(0); - Cell cell = row.createCell(0); + Row row = sheet1.createRow(0); + Cell cell = row.createCell(0); - // it's important to create the referenced sheet first - Sheet sheet2 = wb.createSheet("A"); // note name 'A' - // TODO - POI crashes if the formula is added before this sheet - // RuntimeException("Zero length string is an invalid sheet name") - // Excel doesn't crash but the formula doesn't work until it is - // re-entered - - String inputFormula = "SUMPRODUCT(A!C7:A!C67, B8:B68) / B69"; // as per bug report - try { - cell.setCellFormula(inputFormula); - } catch (StringIndexOutOfBoundsException e) { - fail("Identified bug 42448"); - } + // it's important to create the referenced sheet first + Sheet sheet2 = wb.createSheet("A"); // note name 'A' + // TODO - POI crashes if the formula is added before this sheet + // RuntimeException("Zero length string is an invalid sheet name") + // Excel doesn't crash but the formula doesn't work until it is + // re-entered + + String inputFormula = "SUMPRODUCT(A!C7:A!C67, B8:B68) / B69"; // as per bug report + try { + cell.setCellFormula(inputFormula); + } catch (StringIndexOutOfBoundsException e) { + fail("Identified bug 42448"); + } + + assertEquals("SUMPRODUCT(A!C7:A!C67,B8:B68)/B69", cell.getCellFormula()); + + // might as well evaluate the sucker... + + addCell(sheet2, 5, 2, 3.0); // A!C6 + addCell(sheet2, 6, 2, 4.0); // A!C7 + addCell(sheet2, 66, 2, 5.0); // A!C67 + addCell(sheet2, 67, 2, 6.0); // A!C68 + + addCell(sheet1, 6, 1, 7.0); // B7 + addCell(sheet1, 7, 1, 8.0); // B8 + addCell(sheet1, 67, 1, 9.0); // B68 + addCell(sheet1, 68, 1, 10.0); // B69 - assertEquals("SUMPRODUCT(A!C7:A!C67,B8:B68)/B69", cell.getCellFormula()); + double expectedResult = (4.0 * 8.0 + 5.0 * 9.0) / 10.0; - // might as well evaluate the sucker... + FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); + CellValue cv = fe.evaluate(cell); - addCell(sheet2, 5, 2, 3.0); // A!C6 - addCell(sheet2, 6, 2, 4.0); // A!C7 - addCell(sheet2, 66, 2, 5.0); // A!C67 - addCell(sheet2, 67, 2, 6.0); // A!C68 - - addCell(sheet1, 6, 1, 7.0); // B7 - addCell(sheet1, 7, 1, 8.0); // B8 - addCell(sheet1, 67, 1, 9.0); // B68 - addCell(sheet1, 68, 1, 10.0); // B69 - - double expectedResult = (4.0 * 8.0 + 5.0 * 9.0) / 10.0; - - FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); - CellValue cv = fe.evaluate(cell); - - assertEquals(CellType.NUMERIC, cv.getCellType()); - assertEquals(expectedResult, cv.getNumberValue(), 0.0); - - wb.close(); + assertEquals(CellType.NUMERIC, cv.getCellType()); + assertEquals(expectedResult, cv.getNumberValue(), 0.0); + } } private static void addCell(Sheet sheet, int rowIx, int colIx, @@ -183,21 +188,21 @@ public final class TestFormulaBugs { checkFormulaValue(wb, cell, "PV(0.08/12, 20*12, 500, ,0)", -59777.14585); checkFormulaValue(wb, cell, "PV(0.08/12, 20*12, 500, ,)", -59777.14585); checkFormulaValue(wb, cell, "PV(0.08/12, 20*12, 500, 500,)", -59878.6315455); - + checkFormulaValue(wb, cell, "FV(0.08/12, 20*12, 500, ,)", -294510.2078107270); checkFormulaValue(wb, cell, "PMT(0.08/12, 20*12, 500, ,)", -4.1822003450); checkFormulaValue(wb, cell, "NPER(0.08/12, 20*12, 500, ,)", -2.0758873434); wb.close(); } - + // bug 52063: LOOKUP(2-arg) and LOOKUP(3-arg) // FIXME: This could be moved into LookupFunctionsTestCaseData.xls, which is tested by TestLookupFunctionsFromSpreadsheet.java @Test public void testLookupFormula() throws Exception { Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("52063"); - + // Note: Values in arrays are in ascending order since LOOKUP expects that in order to work properly // column // A B C @@ -212,33 +217,33 @@ public final class TestFormulaBugs { row.createCell(0).setCellValue("X"); row.createCell(1).setCellValue("Y"); row.createCell(2).setCellValue("Z"); - + Cell evalcell = sheet.createRow(2).createCell(0); - + //// ROW VECTORS // lookup and result row are the same checkFormulaValue(wb, evalcell, "LOOKUP(\"Q\", A1:C1)", "Q"); checkFormulaValue(wb, evalcell, "LOOKUP(\"R\", A1:C1)", "R"); checkFormulaValue(wb, evalcell, "LOOKUP(\"Q\", A1:C1, A1:C1)", "Q"); checkFormulaValue(wb, evalcell, "LOOKUP(\"R\", A1:C1, A1:C1)", "R"); - + // lookup and result row are different checkFormulaValue(wb, evalcell, "LOOKUP(\"Q\", A1:C2)", "Y"); checkFormulaValue(wb, evalcell, "LOOKUP(\"R\", A1:C2)", "Z"); checkFormulaValue(wb, evalcell, "LOOKUP(\"Q\", A1:C1, A2:C2)", "Y"); checkFormulaValue(wb, evalcell, "LOOKUP(\"R\", A1:C1, A2:C2)", "Z"); - + //// COLUMN VECTORS // lookup and result column are different checkFormulaValue(wb, evalcell, "LOOKUP(\"P\", A1:B2)", "Q"); checkFormulaValue(wb, evalcell, "LOOKUP(\"X\", A1:A2, C1:C2)", "Z"); - + wb.close(); } - + private CellValue evaluateFormulaInCell(Workbook wb, Cell cell, String formula) { cell.setCellFormula(formula); - + FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); return evaluator.evaluate(cell); @@ -248,7 +253,7 @@ public final class TestFormulaBugs { CellValue value = evaluateFormulaInCell(wb, cell, formula); assertEquals(expectedValue, value.getNumberValue(), 0.0001); } - + private void checkFormulaValue(Workbook wb, Cell cell, String formula, String expectedValue) { CellValue value = evaluateFormulaInCell(wb, cell, formula); assertEquals(expectedValue, value.getStringValue()); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java Thu Dec 24 18:42:29 2020 @@ -17,14 +17,15 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Locale; +import java.util.stream.Stream; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -36,12 +37,10 @@ import org.apache.poi.ss.usermodel.CellV import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.util.LocaleUtil; -import org.junit.AfterClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * Tests formulas and operators as loaded from a test data spreadsheet.<p> @@ -51,7 +50,6 @@ import org.junit.runners.Parameterized.P * corresponding test class (<tt>TestXxxx</tt>) of the target (<tt>Xxxx</tt>) implementor, * where execution can be observed more easily. */ -@RunWith(Parameterized.class) public final class TestFormulasFromSpreadsheet { private static HSSFWorkbook workbook; @@ -97,22 +95,13 @@ public final class TestFormulasFromSprea int NUMBER_OF_ROWS_PER_FUNCTION = 4; } - @SuppressWarnings("DefaultAnnotationParam") - @Parameter(value = 0) - public String targetFunctionName; - @Parameter(value = 1) - public int formulasRowIdx; - @Parameter(value = 2) - public int expectedValuesRowIdx; - - @AfterClass + @AfterAll public static void closeResource() throws Exception { LocaleUtil.setUserLocale(userLocale); workbook.close(); } - @Parameters(name="{0}") - public static Collection<Object[]> data() { + public static Stream<Arguments> data() { // Function "Text" uses custom-formats which are locale specific // can't set the locale on a per-testrun execution, as some settings have been // already set, when we would try to change the locale by then @@ -123,7 +112,7 @@ public final class TestFormulasFromSprea sheet = workbook.getSheetAt( 0 ); evaluator = new HSSFFormulaEvaluator(workbook); - List<Object[]> data = new ArrayList<>(); + List<Arguments> data = new ArrayList<>(); processFunctionGroup(data, SS.START_OPERATORS_ROW_INDEX); processFunctionGroup(data, SS.START_FUNCTIONS_ROW_INDEX); @@ -131,20 +120,20 @@ public final class TestFormulasFromSprea // processFunctionGroup(data, SS.START_OPERATORS_ROW_INDEX, "ConcatEval"); // processFunctionGroup(data, SS.START_FUNCTIONS_ROW_INDEX, "Text"); - return data; + return data.stream(); } /** * @param startRowIndex row index in the spreadsheet where the first function/operator is found * Typically pass <code>null</code> to test all functions */ - private static void processFunctionGroup(List<Object[]> data, int startRowIndex) { + private static void processFunctionGroup(List<Arguments> data, int startRowIndex) { for (int rowIndex = startRowIndex; true; rowIndex += SS.NUMBER_OF_ROWS_PER_FUNCTION) { Row r = sheet.getRow(rowIndex); String targetFunctionName = getTargetFunctionName(r); - assertNotNull("Test spreadsheet cell empty on row (" + assertNotNull(targetFunctionName, "Test spreadsheet cell empty on row (" + (rowIndex+1) + "). Expected function name or '" - + SS.FUNCTION_NAMES_END_SENTINEL + "'", targetFunctionName); + + SS.FUNCTION_NAMES_END_SENTINEL + "'"); if(targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) { // found end of functions list break; @@ -153,15 +142,16 @@ public final class TestFormulasFromSprea // expected results are on the row below Row expectedValuesRow = sheet.getRow(rowIndex + 1); int missingRowNum = rowIndex + 2; //+1 for 1-based, +1 for next row - assertNotNull("Missing expected values row for function '" - + targetFunctionName + " (row " + missingRowNum + ")", expectedValuesRow); + assertNotNull(expectedValuesRow, "Missing expected values row for function '" + + targetFunctionName + " (row " + missingRowNum + ")"); - data.add(new Object[]{targetFunctionName, rowIndex, rowIndex + 1}); + data.add(Arguments.of(targetFunctionName, rowIndex, rowIndex + 1)); } } - @Test - public void processFunctionRow() { + @ParameterizedTest + @MethodSource("data") + public void processFunctionRow(String targetFunctionName, int formulasRowIdx, int expectedValuesRowIdx) { Row formulasRow = sheet.getRow(formulasRowIdx); Row expectedValuesRow = sheet.getRow(expectedValuesRowIdx); @@ -180,31 +170,31 @@ public final class TestFormulasFromSprea String msg = String.format(Locale.ROOT, "Function '%s': Formula: %s @ %d:%d" , targetFunctionName, c.getCellFormula(), formulasRow.getRowNum(), colnum); - assertNotNull(msg + " - Bad setup data expected value is null", expValue); - assertNotNull(msg + " - actual value was null", actValue); + assertNotNull(expValue, msg + " - Bad setup data expected value is null"); + assertNotNull(actValue, msg + " - actual value was null"); final CellType cellType = expValue.getCellType(); switch (cellType) { case BLANK: - assertEquals(msg, CellType.BLANK, actValue.getCellType()); + assertEquals(CellType.BLANK, actValue.getCellType(), msg); break; case BOOLEAN: - assertEquals(msg, CellType.BOOLEAN, actValue.getCellType()); - assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue()); + assertEquals(CellType.BOOLEAN, actValue.getCellType(), msg); + assertEquals(expValue.getBooleanCellValue(), actValue.getBooleanValue(), msg); break; case ERROR: - assertEquals(msg, CellType.ERROR, actValue.getCellType()); - assertEquals(msg, ErrorEval.getText(expValue.getErrorCellValue()), ErrorEval.getText(actValue.getErrorValue())); + assertEquals(CellType.ERROR, actValue.getCellType(), msg); + assertEquals(ErrorEval.getText(expValue.getErrorCellValue()), ErrorEval.getText(actValue.getErrorValue()), msg); break; 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 NUMERIC: - assertEquals(msg, CellType.NUMERIC, actValue.getCellType()); - TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); + assertEquals(CellType.NUMERIC, actValue.getCellType(), msg); + TestMathX.assertDouble(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); break; case STRING: - assertEquals(msg, CellType.STRING, actValue.getCellType()); - assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue()); + assertEquals(CellType.STRING, actValue.getCellType(), msg); + assertEquals(expValue.getRichStringCellValue().getString(), actValue.getStringValue(), msg); break; default: fail("Unexpected cell type: " + cellType); @@ -224,14 +214,11 @@ public final class TestFormulasFromSprea 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() == CellType.BLANK) { - return null; - } - if(cell.getCellType() == CellType.STRING) { - return cell.getRichStringCellValue().getString(); - } - fail("Bad cell type for 'function name' column: (" + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")"); - return null; + CellType ct = cell.getCellType(); + assertTrue(ct == CellType.BLANK || ct == CellType.STRING, + "Bad cell type for 'function name' column: (" + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")"); + + return (ct == CellType.STRING) ? cell.getRichStringCellValue().getString() : null; } } Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java Thu Dec 24 18:42:29 2020 @@ -17,12 +17,12 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.poi.ss.formula.functions.Function; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * IEEE 754 defines a quantity '-0.0' which is distinct from '0.0'. Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; @@ -28,7 +28,7 @@ import org.apache.poi.hssf.usermodel.HSS import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.CellValue; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link MissingArgEval} Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java Thu Dec 24 18:42:29 2020 @@ -17,15 +17,16 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Locale; +import java.util.stream.Stream; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -36,15 +37,13 @@ import org.apache.poi.ss.usermodel.CellT import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * Tests formulas for multi sheet reference (i.e. SUM(Sheet1:Sheet5!A1)) */ -@RunWith(Parameterized.class) public final class TestMultiSheetEval { /** * This class defines constants for navigating around the test data spreadsheet used for these tests. @@ -89,27 +88,14 @@ public final class TestMultiSheetEval { private static HSSFFormulaEvaluator evaluator; private static Collection<String> funcs; - @SuppressWarnings("DefaultAnnotationParam") - @Parameter(value = 0) - public String testName; - @Parameter(value = 1) - public String functionName; - - @Parameter(value = 2) - public Cell expected; - - @Parameter(value = 3) - public Row testRow; - - @Parameterized.Parameters(name="{0}") - public static Collection<Object[]> data() { + public static Stream<Arguments> data() { HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook(SS.FILENAME); Sheet sheet = workbook.getSheet(SS.TEST_SHEET_NAME); evaluator = new HSSFFormulaEvaluator(workbook); funcs = FunctionEval.getSupportedFunctionNames(); - List<Object[]> data = new ArrayList<>(); + List<Arguments> data = new ArrayList<>(); for (int rowIndex = SS.START_FUNCTIONS_ROW_INDEX;true;rowIndex++) { Row r = sheet.getRow(rowIndex); @@ -119,7 +105,7 @@ public final class TestMultiSheetEval { } String targetFunctionName = getTargetFunctionName(r); - assertNotNull("Expected function name or '" + SS.FUNCTION_NAMES_END_SENTINEL + "'", targetFunctionName); + assertNotNull(targetFunctionName, "Expected function name or '" + SS.FUNCTION_NAMES_END_SENTINEL + "'"); if (targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) { // found end of functions list break; @@ -128,29 +114,30 @@ public final class TestMultiSheetEval { // expected results are on the row below Cell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_VALUE); - assertNotNull("Missing expected values cell for function '" + targetFunctionName, expectedValueCell); + assertNotNull(expectedValueCell, "Missing expected values cell for function '" + targetFunctionName); - data.add(new Object[]{ targetTestName, targetFunctionName, expectedValueCell, r }); + data.add(Arguments.of( targetTestName, targetFunctionName, expectedValueCell, r )); } - return data; + return data.stream(); } - @Test - public void testFunction() { + @ParameterizedTest + @MethodSource("data") + public void testFunction(String testName, String functionName, Cell expected, Row testRow) { Cell c = testRow.getCell(SS.COLUMN_INDEX_ACTUAL_VALUE); if (c == null || c.getCellType() != CellType.FORMULA) { // missing test data assertTrue(testRow.getRowNum() >= SS.START_FUNCTIONS_ROW_INDEX); - assertTrue("unsupported function", funcs.contains(functionName.toUpperCase(Locale.ROOT))); + assertTrue(funcs.contains(functionName.toUpperCase(Locale.ROOT)), "unsupported function"); return; } CellValue actual = evaluator.evaluate(c); - assertNotNull("Bad setup data expected value is null", expected); - assertNotNull("actual value was null", actual); + assertNotNull(expected, "Bad setup data expected value is null"); + assertNotNull(actual, "actual value was null"); final CellType cellType = expected.getCellType(); @@ -171,7 +158,7 @@ public final class TestMultiSheetEval { break; case NUMERIC: assertEquals(CellType.NUMERIC, actual.getCellType()); - TestMathX.assertEquals("", expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); + TestMathX.assertDouble("", expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR); break; case STRING: assertEquals(CellType.STRING, actual.getCellType()); @@ -184,17 +171,17 @@ public final class TestMultiSheetEval { } private static String getTargetFunctionName(Row r) { - assertNotNull("given null row, can't figure out function name", r); + assertNotNull(r, "given null row, can't figure out function name"); Cell cell = r.getCell(SS.COLUMN_INDEX_FUNCTION_NAME); - assertNotNull("Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name", cell); + assertNotNull(cell, "Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name"); assertEquals(CellType.STRING, cell.getCellType()); return cell.getRichStringCellValue().getString(); } private static String getTargetTestName(Row r) { - assertNotNull("Given null row, can't figure out test name", r); + assertNotNull(r, "Given null row, can't figure out test name"); Cell cell = r.getCell(SS.COLUMN_INDEX_TEST_NAME); - assertNotNull("Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_TEST_NAME + ", can't figure out test name", cell); + assertNotNull(cell, "Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_TEST_NAME + ", can't figure out test name"); assertEquals(CellType.STRING, cell.getCellType()); return cell.getRichStringCellValue().getString(); } Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java Thu Dec 24 18:42:29 2020 @@ -17,14 +17,14 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.LinkedHashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for <tt>OperandResolver</tt> @@ -42,7 +42,7 @@ public final class TestOperandResolver { String value = ".1"; Double resolvedValue = OperandResolver.parseDouble(value); - assertNotNull("Identified bug 49723", resolvedValue); + assertNotNull(resolvedValue, "Identified bug 49723"); } /** Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java Thu Dec 24 18:42:29 2020 @@ -17,7 +17,7 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; @@ -30,7 +30,7 @@ import org.apache.poi.ss.formula.functio import org.apache.poi.ss.formula.functions.NumericFunctionInvoker; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for percent operator evaluator. Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java Thu Dec 24 18:42:29 2020 @@ -17,7 +17,7 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; @@ -26,7 +26,7 @@ import org.apache.poi.hssf.usermodel.HSS import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for power operator evaluator. Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java Thu Dec 24 18:42:29 2020 @@ -17,8 +17,8 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.List; @@ -34,7 +34,7 @@ import org.apache.poi.ss.formula.ptg.Are import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.util.AreaReference; import org.apache.poi.ss.util.CellReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for unary plus operator evaluator. Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java Thu Dec 24 18:42:29 2020 @@ -17,12 +17,12 @@ package org.apache.poi.ss.formula.eval; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.poi.ss.formula.functions.EvalFactory; import org.apache.poi.ss.formula.functions.NumericFunctionInvoker; import org.apache.poi.ss.formula.ptg.AreaPtg; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for unary plus operator evaluator. Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/forked/BaseTestForkedEvaluator.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/forked/BaseTestForkedEvaluator.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/forked/BaseTestForkedEvaluator.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/forked/BaseTestForkedEvaluator.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.ss.formula.eval.forked; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; @@ -29,7 +29,7 @@ import org.apache.poi.ss.formula.eval.Nu import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BaseTestForkedEvaluator { Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java Thu Dec 24 18:42:29 2020 @@ -17,10 +17,10 @@ package org.apache.poi.ss.formula.function; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; public final class TestFunctionMetadataRegistry { @Test Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java Thu Dec 24 18:42:29 2020 @@ -17,8 +17,8 @@ package org.apache.poi.ss.formula.function; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.io.IOException; @@ -28,7 +28,7 @@ import org.apache.poi.ss.formula.ptg.Abs import org.apache.poi.ss.formula.ptg.FuncPtg; import org.apache.poi.ss.formula.ptg.FuncVarPtg; import org.apache.poi.ss.formula.ptg.Ptg; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests parsing of some built-in functions that were not properly @@ -53,7 +53,7 @@ public final class TestParseMissingBuilt throw new RuntimeException("function token missing"); } AbstractFunctionPtg func = (AbstractFunctionPtg) ptgF; - assertNotEquals("Failed to recognise built-in function in formula", 255, func.getFunctionIndex()); + assertNotEquals(255, func.getFunctionIndex(), "Failed to recognise built-in function in formula"); assertEquals(expPtgArraySize, ptgs.length); assertEquals(funcIx, func.getFunctionIndex()); Class<? extends AbstractFunctionPtg> expCls = isVarArgFunc ? FuncVarPtg.class : FuncPtg.class; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org