aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-12-24 18:42:29 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-12-24 18:42:29 +0000
commita0fa9e19b1196bc10034f15474d27ce23bf5865a (patch)
tree499c1eb427ebff72f7e447d13dd1de1552df8146 /src/testcases/org/apache/poi/ss
parentfb012041e8dd788637e68737199bc313b3e90098 (diff)
downloadpoi-a0fa9e19b1196bc10034f15474d27ce23bf5865a.tar.gz
poi-a0fa9e19b1196bc10034f15474d27ce23bf5865a.zip
#65026 - Migrate tests to Junit 5
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884783 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss')
-rw-r--r--src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java4
-rw-r--r--src/testcases/org/apache/poi/ss/format/TestCellFormat.java20
-rw-r--r--src/testcases/org/apache/poi/ss/format/TestCellFormatCondition.java6
-rw-r--r--src/testcases/org/apache/poi/ss/format/TestCellFormatResult.java10
-rw-r--r--src/testcases/org/apache/poi/ss/formula/AllSSFormulaTests.java35
-rw-r--r--src/testcases/org/apache/poi/ss/formula/BaseTestExternalFunctions.java58
-rw-r--r--src/testcases/org/apache/poi/ss/formula/BaseTestMissingWorkbook.java29
-rw-r--r--src/testcases/org/apache/poi/ss/formula/SheetRangeAndWorkbookIndexFormatterTest.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/TestEvaluationCache.java15
-rw-r--r--src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java151
-rw-r--r--src/testcases/org/apache/poi/ss/formula/TestFunctionRegistry.java30
-rw-r--r--src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/TestSheetNameFormatter.java46
-rw-r--r--src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java155
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestDateParser.java79
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java29
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java24
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java17
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java10
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java34
-rw-r--r--src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java17
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/AllFormulaEvalTests.java42
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java20
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java121
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java89
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java63
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java10
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/forked/BaseTestForkedEvaluator.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/function/AllFormulaFunctionTests.java33
-rw-r--r--src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java58
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/AllIndividualFunctionEvaluationTests.java64
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/AllSpreadsheetBasedTests.java49
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java88
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/BaseTestNumeric.java29
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java2
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestAddress.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestAreas.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestAverage.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestBin2Dec.java22
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestBooleanFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java10
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestClean.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestCode.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestCodeFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestComplex.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestComplexFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java42
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDGetFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDStarFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDate.java14
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDateTimeToNumberFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDateValue.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java18
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDec2Bin.java37
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java41
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDelta.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestEDate.java18
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestEOMonth.java18
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestFinanceLib.java58
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestFind.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java24
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestFixedFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestFrequency.java17
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestGeomean.java16
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestHex2Dec.java11
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIFFunctionFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIPMT.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestImRealFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestImaginaryFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIndexFunctionFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java28
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIntercept.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java22
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIsBlank.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestLeftRight.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestLen.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestLogicalFunction.java10
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestLogicalFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestLookupFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestMatch.java15
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java492
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestMid.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java28
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestMultiOperandNumericFunction.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestNper.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestOct2Dec.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java50
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestPPMT.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestPmt.java16
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestPoisson.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestProduct.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestRank.java10
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestRelationalOperations.java20
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestReptFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestRomanFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestRowCol.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestSlope.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java97
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestSubstitute.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestSubtotal.java32
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java16
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestSumproduct.java11
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestTFunc.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestText.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestTime.java10
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestTrendFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestTrim.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java19
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestTwoOperandNumericFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestValue.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet2013.java7
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestWeekdayFunc.java54
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestXYNumericFunction.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/AllFormulaTests.java54
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java13
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestArea3DPtg.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestAreaErrPtg.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java51
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java10
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestAttrPtg.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestErrPtg.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestExternalFunctionFormulas.java18
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestFuncPtg.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestFuncVarPtg.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestIntersectionPtg.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestPercentPtg.java16
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestRangePtg.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestRef3DPtg.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java63
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestUnionPtg.java8
-rw-r--r--src/testcases/org/apache/poi/ss/formula/udf/BaseTestUDFFinder.java6
-rw-r--r--src/testcases/org/apache/poi/ss/formula/udf/TestAggregatingUDFFinder.java2
-rw-r--r--src/testcases/org/apache/poi/ss/formula/udf/TestDefaultUDFFinder.java2
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestBorderStyle.java16
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java335
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java184
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java99
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestCloneSheet.java32
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestColumnShifting.java24
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java139
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java20
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java4
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java16
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java45
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java8
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java488
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java24
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestRangeCopier.java12
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java207
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java116
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java14
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetHiding.java87
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftColumns.java34
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java50
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java153
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java90
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestXEvaluationSheet.java6
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java111
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestDateUtil.java165
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java14
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java18
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestIndexedColors.java18
-rw-r--r--src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java41
-rw-r--r--src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java419
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestAreaReference.java15
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestCellAddress.java25
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestCellRangeAddress.java123
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestCellRangeUtil.java15
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestCellReference.java156
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java20
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestDateParser.java61
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java16
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestNumberComparer.java13
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestNumberToTextConverter.java6
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestPropertyTemplate.java30
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestRegionUtil.java24
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java8
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestSheetUtil.java205
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java4
-rw-r--r--src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java4
209 files changed, 3116 insertions, 4118 deletions
diff --git a/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java b/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java
index c1c3a45306..7a2003fc74 100644
--- a/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java
+++ b/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Check that all enum values are properly set
diff --git a/src/testcases/org/apache/poi/ss/format/TestCellFormat.java b/src/testcases/org/apache/poi/ss/format/TestCellFormat.java
index fa24171b9e..f87d42a22a 100644
--- a/src/testcases/org/apache/poi/ss/format/TestCellFormat.java
+++ b/src/testcases/org/apache/poi/ss/format/TestCellFormat.java
@@ -16,9 +16,9 @@
==================================================================== */
package org.apache.poi.ss.format;
-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.io.IOException;
import java.text.ParseException;
@@ -38,23 +38,23 @@ 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.util.LocaleUtil;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
public class TestCellFormat {
private static TimeZone userTimeZone;
- @BeforeClass
+ @BeforeAll
public static void setTimeZone() {
userTimeZone = LocaleUtil.getUserTimeZone();
LocaleUtil.setUserTimeZone(TimeZone.getTimeZone("CET"));
LocaleUtil.setUserLocale(Locale.US);
}
- @AfterClass
+ @AfterAll
public static void resetTimeZone() {
LocaleUtil.setUserTimeZone(userTimeZone);
LocaleUtil.setUserLocale(Locale.ROOT);
@@ -1024,6 +1024,6 @@ public class TestCellFormat {
assertTrue(CellFormatPart.NAMED_COLORS.size() >= HSSFColor.HSSFColorPredefined.values().length);
Stream.of("GREEN", "Green", "RED", "Red", "BLUE", "Blue", "YELLOW", "Yellow")
.map(CellFormatPart.NAMED_COLORS::get)
- .forEach(Assert::assertNotNull);
+ .forEach(Assertions::assertNotNull);
}
}
diff --git a/src/testcases/org/apache/poi/ss/format/TestCellFormatCondition.java b/src/testcases/org/apache/poi/ss/format/TestCellFormatCondition.java
index bda95024f8..87ea43ac15 100644
--- a/src/testcases/org/apache/poi/ss/format/TestCellFormatCondition.java
+++ b/src/testcases/org/apache/poi/ss/format/TestCellFormatCondition.java
@@ -16,10 +16,10 @@
==================================================================== */
package org.apache.poi.ss.format;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestCellFormatCondition {
@Test
diff --git a/src/testcases/org/apache/poi/ss/format/TestCellFormatResult.java b/src/testcases/org/apache/poi/ss/format/TestCellFormatResult.java
index 30ee2b9f67..51290e6e79 100644
--- a/src/testcases/org/apache/poi/ss/format/TestCellFormatResult.java
+++ b/src/testcases/org/apache/poi/ss/format/TestCellFormatResult.java
@@ -16,20 +16,20 @@
==================================================================== */
package org.apache.poi.ss.format;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.awt.Color;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestCellFormatResult {
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testNullTextRaisesException() {
final boolean applies = true;
final String text = null;
final Color textColor = Color.BLACK;
- final CellFormatResult result = new CellFormatResult(applies, text, textColor);
- fail("Cannot initialize CellFormatResult with null text parameter");
+ assertThrows(IllegalArgumentException.class, () -> new CellFormatResult(applies, text, textColor),
+ "Cannot initialize CellFormatResult with null text parameter");
}
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/ss/formula/AllSSFormulaTests.java b/src/testcases/org/apache/poi/ss/formula/AllSSFormulaTests.java
deleted file mode 100644
index 14427df5d4..0000000000
--- a/src/testcases/org/apache/poi/ss/formula/AllSSFormulaTests.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-import org.apache.poi.ss.formula.eval.forked.BaseTestForkedEvaluator;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test suite for org.apache.poi.ss.formula
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestCellCacheEntry.class,
- TestEvaluationCache.class,
- TestWorkbookEvaluator.class,
- BaseTestForkedEvaluator.class
-})
-public class AllSSFormulaTests {
-}
diff --git a/src/testcases/org/apache/poi/ss/formula/BaseTestExternalFunctions.java b/src/testcases/org/apache/poi/ss/formula/BaseTestExternalFunctions.java
index d71d955bbc..5472a92591 100644
--- a/src/testcases/org/apache/poi/ss/formula/BaseTestExternalFunctions.java
+++ b/src/testcases/org/apache/poi/ss/formula/BaseTestExternalFunctions.java
@@ -16,10 +16,10 @@
==================================================================== */
package org.apache.poi.ss.formula;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
@@ -37,7 +37,7 @@ import org.apache.poi.ss.usermodel.CellType;
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;
/**
* Test setting / evaluating of Analysis Toolpack and user-defined functions
@@ -96,42 +96,38 @@ public abstract class BaseTestExternalFunctions {
@Test
public void testExternalFunctions() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
- Sheet sh = wb.createSheet();
+ Sheet sh = wb.createSheet();
- Cell cell1 = sh.createRow(0).createCell(0);
- // functions from the Excel Analysis Toolpack
- cell1.setCellFormula("ISODD(1)+ISEVEN(2)");
- assertEquals("ISODD(1)+ISEVEN(2)", cell1.getCellFormula());
+ Cell cell1 = sh.createRow(0).createCell(0);
+ // functions from the Excel Analysis Toolpack
+ cell1.setCellFormula("ISODD(1)+ISEVEN(2)");
+ assertEquals("ISODD(1)+ISEVEN(2)", cell1.getCellFormula());
- Cell cell2 = sh.createRow(1).createCell(0);
- // unregistered functions are parseable and renderable, but may not be evaluateable
- cell2.setCellFormula("MYFUNC(\"B1\")");
- try {
- evaluator.evaluate(cell2);
- fail("Expected NotImplementedFunctionException/NotImplementedException");
- } catch (final NotImplementedException e) {
+ Cell cell2 = sh.createRow(1).createCell(0);
+ // unregistered functions are parseable and renderable, but may not be evaluateable
+ cell2.setCellFormula("MYFUNC(\"B1\")");
+ NotImplementedException e = assertThrows(NotImplementedException.class, () -> evaluator.evaluate(cell2),
+ "Expected NotImplementedFunctionException/NotImplementedException");
assertTrue(e.getCause() instanceof NotImplementedFunctionException);
// Alternatively, a future implementation of evaluate could return #NAME? error to align behavior with Excel
// assertEquals(ErrorEval.NAME_INVALID, ErrorEval.valueOf(evaluator.evaluate(cell2).getErrorValue()));
- }
-
- wb.addToolPack(customToolpack);
- cell2.setCellFormula("MYFUNC(\"B1\")");
- assertEquals("MYFUNC(\"B1\")", cell2.getCellFormula());
+ wb.addToolPack(customToolpack);
- Cell cell3 = sh.createRow(2).createCell(0);
- cell3.setCellFormula("MYFUNC2(\"C1\")&\"-\"&A2"); //where A2 is defined above
- assertEquals("MYFUNC2(\"C1\")&\"-\"&A2", cell3.getCellFormula());
+ cell2.setCellFormula("MYFUNC(\"B1\")");
+ assertEquals("MYFUNC(\"B1\")", cell2.getCellFormula());
- assertEquals(2.0, evaluator.evaluate(cell1).getNumberValue(), 0);
- assertEquals("B1abc", evaluator.evaluate(cell2).getStringValue());
- assertEquals("C1abc2-B1abc", evaluator.evaluate(cell3).getStringValue());
+ Cell cell3 = sh.createRow(2).createCell(0);
+ cell3.setCellFormula("MYFUNC2(\"C1\")&\"-\"&A2"); //where A2 is defined above
+ assertEquals("MYFUNC2(\"C1\")&\"-\"&A2", cell3.getCellFormula());
- wb.close();
+ assertEquals(2.0, evaluator.evaluate(cell1).getNumberValue(), 0);
+ assertEquals("B1abc", evaluator.evaluate(cell2).getStringValue());
+ assertEquals("C1abc2-B1abc", evaluator.evaluate(cell3).getStringValue());
+ }
}
/**
diff --git a/src/testcases/org/apache/poi/ss/formula/BaseTestMissingWorkbook.java b/src/testcases/org/apache/poi/ss/formula/BaseTestMissingWorkbook.java
index 9cb755cf27..087249022a 100644
--- a/src/testcases/org/apache/poi/ss/formula/BaseTestMissingWorkbook.java
+++ b/src/testcases/org/apache/poi/ss/formula/BaseTestMissingWorkbook.java
@@ -19,11 +19,11 @@
package org.apache.poi.ss.formula;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashMap;
import java.util.Map;
@@ -35,9 +35,9 @@ 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.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public class BaseTestMissingWorkbook {
protected Workbook mainWorkbook;
@@ -58,7 +58,7 @@ public class BaseTestMissingWorkbook {
this.SOURCE_WORKBOOK_FILENAME = SOURCE_WORKBOOK_FILENAME;
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
mainWorkbook = HSSFTestDataSamples.openSampleWorkbook(MAIN_WORKBOOK_FILENAME);
sourceWorkbook = HSSFTestDataSamples.openSampleWorkbook(SOURCE_WORKBOOK_FILENAME);
@@ -67,7 +67,7 @@ public class BaseTestMissingWorkbook {
assertNotNull(sourceWorkbook);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
if(mainWorkbook != null) {
mainWorkbook.close();
@@ -87,12 +87,9 @@ public class BaseTestMissingWorkbook {
Cell lA1Cell = lARow.getCell(0);
assertEquals(CellType.FORMULA, lA1Cell.getCellType());
- try {
- evaluator.evaluateFormulaCell(lA1Cell);
- fail("Missing external workbook reference exception expected!");
- } catch(RuntimeException re) {
- assertTrue("Unexpected exception: " + re, re.getMessage().contains(SOURCE_DUMMY_WORKBOOK_FILENAME));
- }
+ RuntimeException re = assertThrows(RuntimeException.class, () -> evaluator.evaluateFormulaCell(lA1Cell),
+ "Missing external workbook reference exception expected!");
+ assertTrue(re.getMessage().contains(SOURCE_DUMMY_WORKBOOK_FILENAME));
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/SheetRangeAndWorkbookIndexFormatterTest.java b/src/testcases/org/apache/poi/ss/formula/SheetRangeAndWorkbookIndexFormatterTest.java
index 43dd236d38..79897e6115 100644
--- a/src/testcases/org/apache/poi/ss/formula/SheetRangeAndWorkbookIndexFormatterTest.java
+++ b/src/testcases/org/apache/poi/ss/formula/SheetRangeAndWorkbookIndexFormatterTest.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss.formula;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Test;
public class SheetRangeAndWorkbookIndexFormatterTest {
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java b/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java
index f382b92d3f..4ac48ed808 100644
--- a/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java
+++ b/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java
@@ -17,11 +17,11 @@
package org.apache.poi.ss.formula;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests {@link org.apache.poi.ss.formula.CellCacheEntry}.
diff --git a/src/testcases/org/apache/poi/ss/formula/TestEvaluationCache.java b/src/testcases/org/apache/poi/ss/formula/TestEvaluationCache.java
index b022074274..80b6368d74 100644
--- a/src/testcases/org/apache/poi/ss/formula/TestEvaluationCache.java
+++ b/src/testcases/org/apache/poi/ss/formula/TestEvaluationCache.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss.formula;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import java.util.ArrayList;
import java.util.Arrays;
@@ -52,7 +52,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;
/**
* Tests {@link org.apache.poi.ss.formula.EvaluationCache}. Makes sure that where possible (previously calculated) cached
@@ -219,11 +219,10 @@ public class TestEvaluationCache {
private final HSSFSheet _sheet;
private final WorkbookEvaluator _evaluator;
- private final HSSFWorkbook _wb;
private final EvalListener _evalListener;
public MySheet() {
- _wb = new HSSFWorkbook();
+ HSSFWorkbook _wb = new HSSFWorkbook();
_evalListener = new EvalListener(_wb);
_evaluator = WorkbookEvaluatorTestHelper.createEvaluator(_wb, _evalListener);
_sheet = _wb.createSheet("Sheet1");
@@ -621,7 +620,7 @@ public class TestEvaluationCache {
cv = fe.evaluate(cellA1);
// looks like left-over cached result from before change to B1
- assertNotEquals("Identified bug 46053", 2.2, cv.getNumberValue());
+ assertNotEquals(2.2, cv.getNumberValue(), "Identified bug 46053");
assertEquals(2.6, cv.getNumberValue(), 0.0);
}
@@ -666,7 +665,7 @@ public class TestEvaluationCache {
private static void confirmLog(MySheet ms, String[] expectedLog) {
String[] actualLog = ms.getAndClearLog();
- assertArrayEquals("Log entry mismatch", expectedLog, actualLog);
+ assertArrayEquals(expectedLog, actualLog, "Log entry mismatch");
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java b/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java
index f4ceee0bcc..299fbf2058 100644
--- a/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java
+++ b/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java
@@ -17,10 +17,10 @@
package org.apache.poi.ss.formula;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.ptg.AreaErrPtg;
@@ -28,8 +28,7 @@ import org.apache.poi.ss.formula.ptg.AreaPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.Ref3DPtg;
import org.apache.poi.ss.util.CellReference;
-
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link FormulaShifter}.
@@ -121,7 +120,7 @@ public final class TestFormulaShifter {
confirmAreaColumnShift(aptg, 18, 22, 5, 10, 25); // simple expansion at bottom
}
-
+
@Test
public void testCopyAreasSourceRowsRelRel() {
@@ -131,7 +130,7 @@ public final class TestFormulaShifter {
confirmAreaRowCopy(aptg, 0, 30, 20, 30, 40, true);
confirmAreaRowCopy(aptg, 15, 25, -15, -1, -1, true); //DeletedRef
}
-
+
@Test
public void testCopyAreasSourceRowsRelAbs() {
@@ -142,7 +141,7 @@ public final class TestFormulaShifter {
confirmAreaRowCopy(aptg, 0, 30, 20, 20, 30, true);
confirmAreaRowCopy(aptg, 15, 25, -15, -1, -1, true); //DeletedRef
}
-
+
@Test
public void testCopyAreasSourceRowsAbsRel() {
// aptg is part of a formula in a cell that was just copied to another row
@@ -158,7 +157,7 @@ public final class TestFormulaShifter {
confirmAreaRowCopy(aptg, 0, 30, 20, 10, 40, true);
confirmAreaRowCopy(aptg, 15, 25, -15, 5, 10, true); //sortTopLeftToBottomRight swapped firstRow and lastRow because firstRow is absolute
}
-
+
@Test
public void testCopyAreasSourceRowsAbsAbs() {
// aptg is part of a formula in a cell that was just copied to another row
@@ -166,7 +165,7 @@ public final class TestFormulaShifter {
// No other references besides the cells that were involved in the copy need to be updated
// this makes the row copy significantly different from the row shift, where all references
// in the workbook need to track the row shift
-
+
// all these operations are on an area ref spanning rows 10 to 20
final AreaPtg aptg = createAreaPtgRow(10, 20, false, false);
@@ -227,9 +226,9 @@ public final class TestFormulaShifter {
confirmAreaColumnCopy(aptg, 0, 30, 20, 10, 20, false);
confirmAreaColumnCopy(aptg, 15, 25, -15, 10, 20, false);
}
-
-
-
+
+
+
/**
* Tests what happens to an area ref when some outside rows are moved to overlap
* that area ref
@@ -278,7 +277,8 @@ public final class TestFormulaShifter {
FormulaShifter fs = FormulaShifter.createForRowShift(0, "", firstRowMoved, lastRowMoved, numberRowsMoved, SpreadsheetVersion.EXCEL2007);
boolean expectedChanged = aptg.getFirstRow() != expectedAreaFirstRow || aptg.getLastRow() != expectedAreaLastRow;
- AreaPtg copyPtg = (AreaPtg) aptg.copy(); // clone so we can re-use aptg in calling method
+ // clone so we can re-use aptg in calling method
+ AreaPtg copyPtg = aptg.copy();
Ptg[] ptgs = { copyPtg, };
boolean actualChanged = fs.adjustFormula(ptgs, 0);
if (expectedAreaFirstRow < 0) {
@@ -286,7 +286,8 @@ public final class TestFormulaShifter {
return;
}
assertEquals(expectedChanged, actualChanged);
- assertEquals(copyPtg, ptgs[0]); // expected to change in place (although this is not a strict requirement)
+ // expected to change in place (although this is not a strict requirement)
+ assertEquals(copyPtg, ptgs[0]);
assertEquals(expectedAreaFirstRow, copyPtg.getFirstRow());
assertEquals(expectedAreaLastRow, copyPtg.getLastRow());
@@ -300,7 +301,8 @@ public final class TestFormulaShifter {
FormulaShifter fs = FormulaShifter.createForColumnShift(0, "", firstColumnMoved, lastColumnMoved, numberColumnsMoved, SpreadsheetVersion.EXCEL2007);
boolean expectedChanged = aptg.getFirstColumn() != expectedAreaFirstColumn || aptg.getLastColumn() != expectedAreaLastColumn;
- AreaPtg copyPtg = (AreaPtg) aptg.copy(); // clone so we can re-use aptg in calling method
+ // clone so we can re-use aptg in calling method
+ AreaPtg copyPtg = aptg.copy();
Ptg[] ptgs = { copyPtg, };
boolean actualChanged = fs.adjustFormula(ptgs, 0);
if (expectedAreaFirstColumn < 0) {
@@ -308,59 +310,61 @@ public final class TestFormulaShifter {
return;
}
assertEquals(expectedChanged, actualChanged);
- assertEquals(copyPtg, ptgs[0]); // expected to change in place (although this is not a strict requirement)
+ // expected to change in place (although this is not a strict requirement)
+ assertEquals(copyPtg, ptgs[0]);
assertEquals(expectedAreaFirstColumn, copyPtg.getFirstColumn());
assertEquals(expectedAreaLastColumn, copyPtg.getLastColumn());
}
-
-
+
+
private static void confirmAreaRowCopy(AreaPtg aptg,
int firstRowCopied, int lastRowCopied, int rowOffset,
int expectedFirstRow, int expectedLastRow, boolean expectedChanged) {
-
- final AreaPtg copyPtg = (AreaPtg) aptg.copy(); // clone so we can re-use aptg in calling method
+ // clone so we can re-use aptg in calling method
+ final AreaPtg copyPtg = aptg.copy();
final Ptg[] ptgs = { copyPtg, };
final FormulaShifter fs = FormulaShifter.createForRowCopy(0, null, firstRowCopied, lastRowCopied, rowOffset, SpreadsheetVersion.EXCEL2007);
final boolean actualChanged = fs.adjustFormula(ptgs, 0);
-
+
// DeletedAreaRef
if (expectedFirstRow < 0 || expectedLastRow < 0) {
- assertEquals("Reference should have shifted off worksheet, producing #REF! error: " + ptgs[0],
- AreaErrPtg.class, ptgs[0].getClass());
+ assertEquals(AreaErrPtg.class, ptgs[0].getClass(), "Reference should have shifted off worksheet, producing #REF! error: " + ptgs[0]);
return;
}
-
- assertEquals("Should this AreaPtg change due to row copy?", expectedChanged, actualChanged);
- assertEquals("AreaPtgs should be modified in-place when a row containing the AreaPtg is copied", copyPtg, ptgs[0]); // expected to change in place (although this is not a strict requirement)
- assertEquals("AreaPtg first row", expectedFirstRow, copyPtg.getFirstRow());
- assertEquals("AreaPtg last row", expectedLastRow, copyPtg.getLastRow());
+
+ assertEquals(expectedChanged, actualChanged, "Should this AreaPtg change due to row copy?");
+ // expected to change in place (although this is not a strict requirement)
+ assertEquals(copyPtg, ptgs[0], "AreaPtgs should be modified in-place when a row containing the AreaPtg is copied");
+ assertEquals(expectedFirstRow, copyPtg.getFirstRow(), "AreaPtg first row");
+ assertEquals(expectedLastRow, copyPtg.getLastRow(), "AreaPtg last row");
}
private static void confirmAreaColumnCopy(AreaPtg aptg,
int firstColumnCopied, int lastColumnCopied, int columnOffset,
int expectedFirstColumn, int expectedLastColumn, boolean expectedChanged) {
-
- final AreaPtg copyPtg = (AreaPtg) aptg.copy(); // clone so we can re-use aptg in calling method
+ // clone so we can re-use aptg in calling method
+ final AreaPtg copyPtg = aptg.copy();
final Ptg[] ptgs = { copyPtg, };
final FormulaShifter fs = FormulaShifter.createForColumnCopy(0, null, firstColumnCopied, lastColumnCopied, columnOffset, SpreadsheetVersion.EXCEL2007);
final boolean actualChanged = fs.adjustFormula(ptgs, 0);
// DeletedAreaRef
if (expectedFirstColumn < 0 || expectedLastColumn < 0) {
- assertEquals("Reference should have shifted off worksheet, producing #REF! error: " + ptgs[0],
- AreaErrPtg.class, ptgs[0].getClass());
+ assertEquals(AreaErrPtg.class, ptgs[0].getClass(),
+ "Reference should have shifted off worksheet, producing #REF! error: " + ptgs[0]);
return;
}
- assertEquals("Should this AreaPtg change due to column copy?", expectedChanged, actualChanged);
- assertEquals("AreaPtgs should be modified in-place when a column containing the AreaPtg is copied", copyPtg, ptgs[0]); // expected to change in place (although this is not a strict requirement)
- assertEquals("AreaPtg first column", expectedFirstColumn, copyPtg.getFirstColumn());
- assertEquals("AreaPtg last column", expectedLastColumn, copyPtg.getLastColumn());
+ assertEquals(expectedChanged, actualChanged, "Should this AreaPtg change due to column copy?");
+ // expected to change in place (although this is not a strict requirement)
+ assertEquals(copyPtg, ptgs[0], "AreaPtgs should be modified in-place when a column containing the AreaPtg is copied");
+ assertEquals(expectedFirstColumn, copyPtg.getFirstColumn(), "AreaPtg first column");
+ assertEquals(expectedLastColumn, copyPtg.getLastColumn(), "AreaPtg last column");
}
-
+
private static AreaPtg createAreaPtgRow(int initialAreaFirstRow, int initialAreaLastRow) {
return createAreaPtgRow(initialAreaFirstRow, initialAreaLastRow, false, false);
}
@@ -368,7 +372,7 @@ public final class TestFormulaShifter {
private static AreaPtg createAreaPtgColumn(int initialAreaFirstColumn, int initialAreaLastColumn) {
return createAreaPtgColumn(initialAreaFirstColumn, initialAreaLastColumn, false, false);
}
-
+
private static AreaPtg createAreaPtgRow(int initialAreaFirstRow, int initialAreaLastRow, boolean firstRowRelative, boolean lastRowRelative) {
return new AreaPtg(initialAreaFirstRow, initialAreaLastRow, 2, 5, firstRowRelative, lastRowRelative, false, false);
}
@@ -379,33 +383,33 @@ public final class TestFormulaShifter {
@Test
public void testShiftSheet() {
- // 4 sheets, move a sheet from pos 2 to pos 0, i.e. current 0 becomes 1, current 1 becomes pos 2
+ // 4 sheets, move a sheet from pos 2 to pos 0, i.e. current 0 becomes 1, current 1 becomes pos 2
FormulaShifter shifter = FormulaShifter.createForSheetShift(2, 0);
-
+
Ptg[] ptgs = new Ptg[] {
new Ref3DPtg(new CellReference("first", 0, 0, true, true), 0),
new Ref3DPtg(new CellReference("second", 0, 0, true, true), 1),
new Ref3DPtg(new CellReference("third", 0, 0, true, true), 2),
new Ref3DPtg(new CellReference("fourth", 0, 0, true, true), 3),
};
-
+
shifter.adjustFormula(ptgs, -1);
-
- assertEquals("formula previously pointing to sheet 0 should now point to sheet 1",
- 1, ((Ref3DPtg)ptgs[0]).getExternSheetIndex());
- assertEquals("formula previously pointing to sheet 1 should now point to sheet 2",
- 2, ((Ref3DPtg)ptgs[1]).getExternSheetIndex());
- assertEquals("formula previously pointing to sheet 2 should now point to sheet 0",
- 0, ((Ref3DPtg)ptgs[2]).getExternSheetIndex());
- assertEquals("formula previously pointing to sheet 3 should be unchanged",
- 3, ((Ref3DPtg)ptgs[3]).getExternSheetIndex());
+
+ assertEquals(1, ((Ref3DPtg)ptgs[0]).getExternSheetIndex(),
+ "formula previously pointing to sheet 0 should now point to sheet 1");
+ assertEquals(2, ((Ref3DPtg)ptgs[1]).getExternSheetIndex(),
+ "formula previously pointing to sheet 1 should now point to sheet 2");
+ assertEquals(0, ((Ref3DPtg)ptgs[2]).getExternSheetIndex(),
+ "formula previously pointing to sheet 2 should now point to sheet 0");
+ assertEquals(3, ((Ref3DPtg)ptgs[3]).getExternSheetIndex(),
+ "formula previously pointing to sheet 3 should be unchanged");
}
@Test
public void testShiftSheet2() {
- // 4 sheets, move a sheet from pos 1 to pos 2, i.e. current 2 becomes 1, current 1 becomes pos 2
+ // 4 sheets, move a sheet from pos 1 to pos 2, i.e. current 2 becomes 1, current 1 becomes pos 2
FormulaShifter shifter = FormulaShifter.createForSheetShift(1, 2);
-
+
Ptg[] ptgs = new Ptg[] {
new Ref3DPtg(new CellReference("first", 0, 0, true, true), 0),
new Ref3DPtg(new CellReference("second", 0, 0, true, true), 1),
@@ -414,34 +418,25 @@ public final class TestFormulaShifter {
};
shifter.adjustFormula(ptgs, -1);
-
- assertEquals("formula previously pointing to sheet 0 should be unchanged",
- 0, ((Ref3DPtg)ptgs[0]).getExternSheetIndex());
- assertEquals("formula previously pointing to sheet 1 should now point to sheet 2",
- 2, ((Ref3DPtg)ptgs[1]).getExternSheetIndex());
- assertEquals("formula previously pointing to sheet 2 should now point to sheet 1",
- 1, ((Ref3DPtg)ptgs[2]).getExternSheetIndex());
- assertEquals("formula previously pointing to sheet 3 should be unchanged",
- 3, ((Ref3DPtg)ptgs[3]).getExternSheetIndex());
+
+ assertEquals(0, ((Ref3DPtg)ptgs[0]).getExternSheetIndex(),
+ "formula previously pointing to sheet 0 should be unchanged");
+ assertEquals(2, ((Ref3DPtg)ptgs[1]).getExternSheetIndex(),
+ "formula previously pointing to sheet 1 should now point to sheet 2");
+ assertEquals(1, ((Ref3DPtg)ptgs[2]).getExternSheetIndex(),
+ "formula previously pointing to sheet 2 should now point to sheet 1");
+ assertEquals(3, ((Ref3DPtg)ptgs[3]).getExternSheetIndex(),
+ "formula previously pointing to sheet 3 should be unchanged");
}
-
+
@Test
public void testInvalidArgument() {
- try {
- FormulaShifter.createForRowShift(1, "name", 1, 2, 0, SpreadsheetVersion.EXCEL97);
- fail("Should catch exception here");
- } catch (IllegalArgumentException e) {
- // expected here
- }
-
- try {
- FormulaShifter.createForRowShift(1, "name", 2, 1, 2, SpreadsheetVersion.EXCEL97);
- fail("Should catch exception here");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () ->
+ FormulaShifter.createForRowShift(1, "name", 1, 2, 0, SpreadsheetVersion.EXCEL97));
+ assertThrows(IllegalArgumentException.class, () ->
+ FormulaShifter.createForRowShift(1, "name", 2, 1, 2, SpreadsheetVersion.EXCEL97));
}
-
+
@Test
public void testConstructor() {
assertNotNull(FormulaShifter.createForRowShift(1, "name", 1, 2, 2, SpreadsheetVersion.EXCEL97));
diff --git a/src/testcases/org/apache/poi/ss/formula/TestFunctionRegistry.java b/src/testcases/org/apache/poi/ss/formula/TestFunctionRegistry.java
index 7faedd8c03..915510bd4d 100644
--- a/src/testcases/org/apache/poi/ss/formula/TestFunctionRegistry.java
+++ b/src/testcases/org/apache/poi/ss/formula/TestFunctionRegistry.java
@@ -19,9 +19,9 @@
package org.apache.poi.ss.formula;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
@@ -36,13 +36,13 @@ import org.apache.poi.ss.formula.eval.FunctionEval;
import org.apache.poi.ss.formula.eval.NotImplementedException;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.CellValue;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestFunctionRegistry {
HSSFWorkbook wb;
@@ -50,7 +50,7 @@ public class TestFunctionRegistry {
HSSFRow row;
HSSFFormulaEvaluator fe;
- @Before
+ @BeforeEach
public void setup() {
wb = new HSSFWorkbook();
sheet = wb.createSheet("Sheet1");
@@ -58,7 +58,7 @@ public class TestFunctionRegistry {
fe = new HSSFFormulaEvaluator(wb);
}
- @After
+ @AfterEach
public void teardown() throws IOException {
wb.close();
wb = null;
@@ -67,11 +67,11 @@ public class TestFunctionRegistry {
fe = null;
}
- @Test(expected = NotImplementedException.class)
+ @Test
public void testRegisterInRuntimeA() {
HSSFCell cellA = row.createCell(0);
cellA.setCellFormula("FISHER(A5)");
- fe.evaluate(cellA);
+ assertThrows(NotImplementedException.class, () -> fe.evaluate(cellA));
}
@Test
@@ -83,11 +83,11 @@ public class TestFunctionRegistry {
assertEquals(ErrorEval.NA.getErrorCode(), cv.getErrorValue());
}
- @Test(expected = NotImplementedException.class)
+ @Test
public void testRegisterInRuntimeC() {
HSSFCell cellB = row.createCell(1);
cellB.setCellFormula("CUBEMEMBERPROPERTY(A5)");
- fe.evaluate(cellB);
+ assertThrows(NotImplementedException.class, () -> fe.evaluate(cellB));
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java b/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java
index bc89b8dc8a..1f06565fc3 100644
--- a/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java
+++ b/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java
@@ -19,13 +19,13 @@
package org.apache.poi.ss.formula;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import org.apache.poi.ss.formula.PlainCellCache.Loc;
import org.apache.poi.ss.formula.eval.NumberEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestPlainCellCache {
diff --git a/src/testcases/org/apache/poi/ss/formula/TestSheetNameFormatter.java b/src/testcases/org/apache/poi/ss/formula/TestSheetNameFormatter.java
index 76a4fc7ac2..22b9224a0a 100644
--- a/src/testcases/org/apache/poi/ss/formula/TestSheetNameFormatter.java
+++ b/src/testcases/org/apache/poi/ss/formula/TestSheetNameFormatter.java
@@ -17,37 +17,38 @@
package org.apache.poi.ss.formula;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Tests for {@link SheetNameFormatter}
- *
+ *
* @author Josh Micich
*/
public final class TestSheetNameFormatter {
/**
- * Tests main public method 'format'
+ * Tests main public method 'format'
*/
@Test
public void testFormat() {
-
+
confirmFormat("abc", "abc");
confirmFormat("123", "'123'");
-
+
confirmFormat("my sheet", "'my sheet'"); // space
confirmFormat("A:MEM", "'A:MEM'"); // colon
confirmFormat("O'Brian", "'O''Brian'"); // single quote gets doubled
-
+
confirmFormat("3rdTimeLucky", "'3rdTimeLucky'"); // digit in first pos
confirmFormat("_", "_"); // plain underscore OK
confirmFormat("my_3rd_sheet", "my_3rd_sheet"); // underscores and digits OK
- confirmFormat("A12220", "'A12220'");
+ confirmFormat("A12220", "'A12220'");
confirmFormat("TAXRETURN19980415", "TAXRETURN19980415");
confirmFormat(null, "#REF");
@@ -130,19 +131,8 @@ public final class TestSheetNameFormatter {
}
};
- try {
- SheetNameFormatter.appendFormat(mock, null, null);
- fail("Should catch exception here");
- } catch (RuntimeException e) {
- // expected here
- }
-
- try {
- SheetNameFormatter.appendFormat(mock, null);
- fail("Should catch exception here");
- } catch (RuntimeException e) {
- // expected here
- }
+ assertThrows(RuntimeException.class, () -> SheetNameFormatter.appendFormat(mock, null, null));
+ assertThrows(RuntimeException.class, () -> SheetNameFormatter.appendFormat(mock, null));
}
@Test
@@ -151,22 +141,22 @@ public final class TestSheetNameFormatter {
confirmFormat("FALSE", "'FALSE'");
confirmFormat("True", "'True'");
confirmFormat("fAlse", "'fAlse'");
-
+
confirmFormat("Yes", "Yes");
confirmFormat("No", "No");
}
-
+
private static void confirmCellNameMatch(String rawSheetName, boolean expected) {
assertEquals(expected, SheetNameFormatter.nameLooksLikePlainCellReference(rawSheetName));
}
-
+
/**
* Tests functionality to determine whether a sheet name containing only letters and digits
* would look (to Excel) like a cell name.
*/
@Test
public void testLooksLikePlainCellReference() {
-
+
confirmCellNameMatch("A1", true);
confirmCellNameMatch("a111", true);
confirmCellNameMatch("AA", false);
@@ -176,13 +166,13 @@ public final class TestSheetNameFormatter {
confirmCellNameMatch("Sh3", false);
confirmCellNameMatch("SALES20080101", false); // out of range
}
-
+
private static void confirmCellRange(String text, int numberOfPrefixLetters, boolean expected) {
String prefix = text.substring(0, numberOfPrefixLetters);
String suffix = text.substring(numberOfPrefixLetters);
assertEquals(expected, SheetNameFormatter.cellReferenceIsWithinRange(prefix, suffix));
}
-
+
/**
* Tests exact boundaries for names that look very close to cell names (i.e. contain 1 or more
* letters followed by one or more digits).
diff --git a/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java b/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java
index bf89fca10c..05cebd4cc2 100644
--- a/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java
+++ b/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java
@@ -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);
}
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestDateParser.java b/src/testcases/org/apache/poi/ss/formula/atp/TestDateParser.java
deleted file mode 100644
index 95f5ea09ed..0000000000
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestDateParser.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula.atp;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.Calendar;
-
-import org.apache.poi.ss.formula.eval.ErrorEval;
-import org.apache.poi.ss.formula.eval.EvaluationException;
-import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
-
-public class TestDateParser {
- @Test
- public void testFailWhenNoDate() {
- try {
- DateParser.parseDate("potato");
- fail("Shouldn't parse potato!");
- } catch (EvaluationException e) {
- assertEquals(ErrorEval.VALUE_INVALID, e.getErrorEval());
- }
- }
-
- @Test
- public void testFailWhenLooksLikeDateButItIsnt() {
- try {
- DateParser.parseDate("potato/cucumber/banana");
- fail("Shouldn't parse this thing!");
- } catch (EvaluationException e) {
- assertEquals(ErrorEval.VALUE_INVALID, e.getErrorEval());
- }
- }
-
- @Test
- public void testFailWhenIsInvalidDate() {
- try {
- DateParser.parseDate("13/13/13");
- fail("Shouldn't parse this thing!");
- } catch (EvaluationException e) {
- assertEquals(ErrorEval.VALUE_INVALID, e.getErrorEval());
- }
- }
-
- @Test
- public void testShouldParseValidDate() throws EvaluationException {
- Calendar expDate = LocaleUtil.getLocaleCalendar(1984, Calendar.OCTOBER, 20);
- Calendar actDate = DateParser.parseDate("1984/10/20");
- assertEquals("Had: " + expDate.getTime() + " and " + actDate.getTime() + "/" +
- expDate.getTimeInMillis() + "ms and " + actDate.getTimeInMillis() + "ms",
- expDate, actDate);
- }
-
- @Test
- public void testShouldIgnoreTimestamp() throws EvaluationException {
- Calendar expDate = LocaleUtil.getLocaleCalendar(1984, Calendar.OCTOBER, 20);
- Calendar actDate = DateParser.parseDate("1984/10/20 12:34:56");
- assertEquals("Had: " + expDate.getTime() + " and " + actDate.getTime() + "/" +
- expDate.getTimeInMillis() + "ms and " + actDate.getTimeInMillis() + "ms",
- expDate, actDate);
- }
-
-}
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java b/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java
index 7ac623ac86..c94ec8c42d 100644
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java
+++ b/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java
@@ -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(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("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.STRING, evaluator.evaluate(cell3).getCellType(),
+ "Check that C1 returns string");
+ assertEquals("error", evaluator.evaluate(cell3).getStringValue(),
+ "Check that C1 returns string \"error\"");
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java b/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java
index b9aa6f1663..290e4663fc 100644
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java
+++ b/src/testcases/org/apache/poi/ss/formula/atp/TestMRound.java
@@ -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");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java b/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java
index 4c6dc8b048..2d87aca37e 100644
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java
+++ b/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java
@@ -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.AreaEvalBase;
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 {
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java b/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java
index 367109b61e..6c3ecbfc3c 100644
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java
+++ b/src/testcases/org/apache/poi/ss/formula/atp/TestPercentile.java
@@ -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.NumberEval;
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()
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java b/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java
index a4d387f5d9..666d6cb643 100644
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java
+++ b/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java
@@ -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.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.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");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java b/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java
index 3ea70b9947..06a69c03a8 100644
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java
+++ b/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java
@@ -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);
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java b/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java
index aba965bbf6..5772103fbf 100644
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java
+++ b/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java
@@ -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.StringEval;
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);
}
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java b/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java
index 6094d1860b..c9737102c6 100644
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java
+++ b/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java
@@ -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 TestYearFracCalculator {
System.out.println(startDate + " " + endDate + " off by " + hours + " hours");
assertEquals(expectedValue, actualValue, 0.000000001);
}
-
+
}
private static double md(int year, int month, int day) {
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java
index 42675eea2f..b3dd5db273 100644
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java
@@ -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.CellType;
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 TestYearFracCalculatorFromSpreadsheet {
@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 TestYearFracCalculatorFromSpreadsheet {
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 TestYearFracCalculatorFromSpreadsheet {
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 TestYearFracCalculatorFromSpreadsheet {
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();
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java b/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java
index 72a9bcc0d8..aad09be92a 100644
--- a/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java
+++ b/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java
@@ -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 TestConstantValueParser {
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 TestConstantValueParser {
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) {
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/AllFormulaEvalTests.java b/src/testcases/org/apache/poi/ss/formula/eval/AllFormulaEvalTests.java
deleted file mode 100644
index d30e5e585a..0000000000
--- a/src/testcases/org/apache/poi/ss/formula/eval/AllFormulaEvalTests.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula.eval;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests the package <tt>org.apache.poi.hssf.record.formula.eval</tt>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestAreaEval.class,
- TestHSSFCircularReferences.class,
- TestDivideEval.class,
- TestEqualEval.class,
- TestExternalFunction.class,
- TestFormulaBugs.class,
- TestFormulasFromSpreadsheet.class,
- TestMinusZeroResult.class,
- TestMissingArgEval.class,
- TestPercentEval.class,
- TestRangeEval.class,
- TestUnaryPlusEval.class
-})
-public class AllFormulaEvalTests {
-}
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java b/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java
index ef9ab269e8..9ab60c9fb2 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/BaseTestCircularReferences.java
@@ -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.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.Test;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing cases of circular references
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java
index f7f65231f2..83c7616459 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestAreaEval.java
@@ -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);
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java
index a0d4d96497..1d786f9e01 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestDivideEval.java
@@ -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.
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java
index 22dfd56338..c22583dbaa 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java
@@ -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) {
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java b/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java
index 9f86c1eadc..6fcca886c0 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestExternalFunction.java
@@ -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.functions.FreeRefFunction;
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 {
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java
index db2a20c1e2..c74d1050f8 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java
@@ -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");
-
- 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");
- }
+ try (Workbook wb = new HSSFWorkbook()) {
+ Sheet sheet1 = wb.createSheet("Sheet1");
- assertEquals("SUMPRODUCT(A!C7:A!C67,B8:B68)/B69", cell.getCellFormula());
+ Row row = sheet1.createRow(0);
+ Cell cell = row.createCell(0);
- // might as well evaluate the sucker...
+ // 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
- 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
+ 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");
+ }
- 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
- assertEquals(CellType.NUMERIC, cv.getCellType());
- assertEquals(expectedResult, cv.getNumberValue(), 0.0);
+ 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
- wb.close();
+ 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);
+ }
}
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());
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java
index a3062efc36..422d82c5f0 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java
@@ -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.CellValue;
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.Parameters;
* 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 TestFormulasFromSpreadsheet {
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 TestFormulasFromSpreadsheet {
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 TestFormulasFromSpreadsheet {
// 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 TestFormulasFromSpreadsheet {
// 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 TestFormulasFromSpreadsheet {
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 TestFormulasFromSpreadsheet {
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;
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java b/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java
index e725bf7746..e278665d42 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java
@@ -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'.
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java
index 122882d609..b63f38d8e7 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestMissingArgEval.java
@@ -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.HSSFFormulaEvaluator;
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}
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java
index 1c3350f6c0..a8914d2264 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestMultiSheetEval.java
@@ -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.CellType;
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();
}
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java b/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java
index 6aa0370f07..7785a425b3 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java
@@ -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");
}
/**
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java
index 26bd6bf5dc..8357fd6e9e 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestPercentEval.java
@@ -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.functions.EvalFactory;
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.
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java
index 1139cfac24..5fdfda90ad 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestPowerEval.java
@@ -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.HSSFSheet;
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.
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java
index c1becf6cf3..dfde9986a3 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java
@@ -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.AreaI.OffsetArea;
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.
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java
index d85332067f..9846c192b5 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestUnaryPlusEval.java
@@ -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.
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/forked/BaseTestForkedEvaluator.java b/src/testcases/org/apache/poi/ss/formula/eval/forked/BaseTestForkedEvaluator.java
index 70745ef979..8f67e87d65 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/forked/BaseTestForkedEvaluator.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/forked/BaseTestForkedEvaluator.java
@@ -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.NumberEval;
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 {
diff --git a/src/testcases/org/apache/poi/ss/formula/function/AllFormulaFunctionTests.java b/src/testcases/org/apache/poi/ss/formula/function/AllFormulaFunctionTests.java
deleted file mode 100644
index 1931bdbcd1..0000000000
--- a/src/testcases/org/apache/poi/ss/formula/function/AllFormulaFunctionTests.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula.function;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for this <tt>org.apache.poi.hssf.record.formula.function</tt>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestFunctionMetadataRegistry.class,
- TestParseMissingBuiltInFuncs.class,
- TestReadMissingBuiltInFuncs.class
-})
-public class AllFormulaFunctionTests {
-}
diff --git a/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java b/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java
index dcf2277796..7c100f76b0 100644
--- a/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java
+++ b/src/testcases/org/apache/poi/ss/formula/function/TestFunctionMetadataRegistry.java
@@ -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
diff --git a/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java b/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java
index 554afa9751..3f5c55fb1f 100644
--- a/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java
+++ b/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java
@@ -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.AbstractFunctionPtg;
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 TestParseMissingBuiltInFuncs {
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;
diff --git a/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java b/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java
index 2073d45ff1..d5f4a81800 100644
--- a/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java
+++ b/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java
@@ -17,8 +17,10 @@
package org.apache.poi.ss.formula.function;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import java.lang.reflect.InvocationTargetException;
@@ -26,9 +28,9 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.RecordFormatException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
* Tests reading from a sample spreadsheet some built-in functions that were not properly
@@ -44,7 +46,7 @@ public final class TestReadMissingBuiltInFuncs {
private static HSSFWorkbook wb;
private static HSSFSheet _sheet;
- @BeforeClass
+ @BeforeAll
public static void initSheet() {
wb = HSSFTestDataSamples.openSampleWorkbook(SAMPLE_SPREADSHEET_FILE_NAME);
try {
@@ -54,9 +56,8 @@ public final class TestReadMissingBuiltInFuncs {
InvocationTargetException ite = (InvocationTargetException) e.getCause();
if(ite.getTargetException() instanceof RuntimeException) {
RuntimeException re = (RuntimeException) ite.getTargetException();
- if(re.getMessage().equals("Invalid built-in function index (189)")) {
- fail("DPRODUCT() registered with wrong index");
- }
+ assertNotEquals("Invalid built-in function index (189)", re.getMessage(),
+ "DPRODUCT() registered with wrong index");
}
}
// some other unexpected error
@@ -64,7 +65,7 @@ public final class TestReadMissingBuiltInFuncs {
}
}
- @AfterClass
+ @AfterAll
public static void closeResources() throws Exception {
wb.close();
}
@@ -76,9 +77,8 @@ public final class TestReadMissingBuiltInFuncs {
formula = getCellFormula(0);
} catch (IllegalStateException e) {
if(e.getMessage().startsWith("Too few arguments")) {
- if(e.getMessage().indexOf("AttrPtg") > 0) {
- fail("tAttrVolatile not supported in FormulaParser.toFormulaString");
- }
+ assertFalse(e.getMessage().contains("AttrPtg"),
+ "tAttrVolatile not supported in FormulaParser.toFormulaString");
fail("NOW() registered with 1 arg instead of 0");
}
if(e.getMessage().startsWith("too much stuff")) {
@@ -89,31 +89,25 @@ public final class TestReadMissingBuiltInFuncs {
}
assertEquals("DATEDIF(NOW(),NOW(),\"d\")", formula);
}
-
+
@Test
public void testDdb() {
String formula = getCellFormula(1);
- if("externalflag(1,1,1,1,1)".equals(formula)) {
- fail("DDB() not registered");
- }
+ assertNotEquals("externalflag(1,1,1,1,1)", formula, "DDB() not registered");
assertEquals("DDB(1,1,1,1,1)", formula);
}
-
+
@Test
public void testAtan() {
String formula = getCellFormula(2);
- if("ARCTAN(1)".equals(formula)) {
- fail("func ix 18 registered as ARCTAN() instead of ATAN()");
- }
+ assertNotEquals("ARCTAN(1)", formula, "func ix 18 registered as ARCTAN() instead of ATAN()");
assertEquals("ATAN(1)", formula);
}
@Test
public void testUsdollar() {
String formula = getCellFormula(3);
- if("YEN(1)".equals(formula)) {
- fail("func ix 204 registered as YEN() instead of USDOLLAR()");
- }
+ assertNotEquals("YEN(1)", formula, "func ix 204 registered as YEN() instead of USDOLLAR()");
assertEquals("USDOLLAR(1)", formula);
}
@@ -123,35 +117,29 @@ public final class TestReadMissingBuiltInFuncs {
try {
formula = getCellFormula(4);
} catch (IllegalStateException e) {
- if(e.getMessage().startsWith("too much stuff")) {
- fail("DBCS() not registered");
- }
+ assertFalse(e.getMessage().startsWith("too much stuff"), "DBCS() not registered");
// some other unexpected error
throw e;
} catch (NegativeArraySizeException e) {
fail("found err- DBCS() registered with -1 args");
}
- if("JIS(\"abc\")".equals(formula)) {
- fail("func ix 215 registered as JIS() instead of DBCS()");
- }
+ assertNotEquals("JIS(\"abc\")", formula, "func ix 215 registered as JIS() instead of DBCS()");
assertEquals("DBCS(\"abc\")", formula);
}
-
+
@Test
public void testIsnontext() {
String formula;
try {
formula = getCellFormula(5);
} catch (IllegalStateException e) {
- if(e.getMessage().startsWith("too much stuff")) {
- fail("ISNONTEXT() registered with wrong index");
- }
+ assertFalse(e.getMessage().startsWith("too much stuff"), "ISNONTEXT() registered with wrong index");
// some other unexpected error
throw e;
}
assertEquals("ISNONTEXT(\"abc\")", formula);
}
-
+
@Test
public void testDproduct() {
String formula = getCellFormula(6);
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/AllIndividualFunctionEvaluationTests.java b/src/testcases/org/apache/poi/ss/formula/functions/AllIndividualFunctionEvaluationTests.java
deleted file mode 100644
index bbcf2829d8..0000000000
--- a/src/testcases/org/apache/poi/ss/formula/functions/AllIndividualFunctionEvaluationTests.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula.functions;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Direct tests for all implementors of <code>Function</code>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestAverage.class,
- TestCountFuncs.class,
- TestDate.class,
- TestDays360.class,
- TestFinanceLib.class,
- TestFind.class,
- TestIndex.class,
- TestIndexFunctionFromSpreadsheet.class,
- TestIndirect.class,
- TestIsBlank.class,
- TestLen.class,
- TestLookupFunctionsFromSpreadsheet.class,
- TestMatch.class,
- TestMathX.class,
- TestMid.class,
- TestNper.class,
- TestOffset.class,
- TestPmt.class,
- TestRoundFuncs.class,
- TestRowCol.class,
- TestStatsLib.class,
- TestSubtotal.class,
- TestSumif.class,
- TestSumproduct.class,
- TestText.class,
- TestTFunc.class,
- TestTime.class,
- TestTrim.class,
- TestTrunc.class,
- TestValue.class,
- TestXYNumericFunction.class,
- TestAddress.class,
- TestAreas.class,
- TestClean.class
-})
-public class AllIndividualFunctionEvaluationTests {
-}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/AllSpreadsheetBasedTests.java b/src/testcases/org/apache/poi/ss/formula/functions/AllSpreadsheetBasedTests.java
deleted file mode 100644
index 0dc5ed9233..0000000000
--- a/src/testcases/org/apache/poi/ss/formula/functions/AllSpreadsheetBasedTests.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula.functions;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Direct tests for all implementors of <code>Function</code>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestCodeFunctionsFromSpreadsheet.class,
- TestComplexFunctionsFromSpreadsheet.class,
- TestDeltaFunctionsFromSpreadsheet.class,
- TestDGetFunctionsFromSpreadsheet.class,
- TestDStarFunctionsFromSpreadsheet.class,
- TestFactDoubleFunctionsFromSpreadsheet.class,
- TestFixedFunctionsFromSpreadsheet.class,
- TestImaginaryFunctionsFromSpreadsheet.class,
- TestImRealFunctionsFromSpreadsheet.class,
- TestIndexFunctionFromSpreadsheet.class,
- TestIndirectFunctionFromSpreadsheet.class,
- TestLookupFunctionsFromSpreadsheet.class,
- TestMatchFunctionsFromSpreadsheet.class,
- TestQuotientFunctionsFromSpreadsheet.class,
- TestReptFunctionsFromSpreadsheet.class,
- TestRomanFunctionsFromSpreadsheet.class,
- TestTrendFunctionsFromSpreadsheet.class,
- TestWeekNumFunctionsFromSpreadsheet.class,
- TestWeekNumFunctionsFromSpreadsheet2013.class
-})
-public class AllSpreadsheetBasedTests {
-}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java
index 7b899350c1..594b7b68a2 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java
@@ -17,16 +17,16 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-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.assertNotEquals;
+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.HSSFCell;
@@ -34,16 +34,14 @@ import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameter;
+import org.apache.poi.ss.util.CellReference;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
-@RunWith(Parameterized.class)
public abstract class BaseTestFunctionsFromSpreadsheet {
/**
@@ -68,26 +66,13 @@ public abstract class BaseTestFunctionsFromSpreadsheet {
}
- @Parameter()
- public String testName;
- @Parameter(value = 1)
- public String filename;
- @Parameter(value = 2)
- public HSSFSheet sheet;
- @Parameter(value = 3)
- public int formulasRowIdx;
- @Parameter(value = 4)
- public HSSFFormulaEvaluator evaluator;
- @Parameter(value = 5)
- public int precisionColumnIndex;
-
-
-
- protected static Collection<Object[]> data(Class<? extends BaseTestFunctionsFromSpreadsheet> clazz, String filename) throws Exception {
+
+
+ protected static Stream<Arguments> data(Class<? extends BaseTestFunctionsFromSpreadsheet> clazz, String filename) throws Exception {
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook(filename);
confirmReadMeSheet(workbook, clazz);
- List<Object[]> data = new ArrayList<>();
+ List<Arguments> data = new ArrayList<>();
int nSheets = workbook.getNumberOfSheets();
for(int sheetIdx=1; sheetIdx< nSheets; sheetIdx++) {
@@ -96,11 +81,11 @@ public abstract class BaseTestFunctionsFromSpreadsheet {
}
workbook.close();
-
- return data;
+
+ return data.stream();
}
- private static void processFunctionGroup(List<Object[]> data, HSSFSheet sheet, final int startRowIndex, String filename) {
+ private static void processFunctionGroup(List<Arguments> data, HSSFSheet sheet, final int startRowIndex, String filename) {
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet.getWorkbook());
int precisionColumnIndex = -1;
@@ -118,7 +103,7 @@ public abstract class BaseTestFunctionsFromSpreadsheet {
if(r == null) {
continue;
}
- String newMarkerValue = getCellTextValue(r, SS.COLUMN_INDEX_MARKER, "marker");
+ String newMarkerValue = getCellTextValue(r, SS.COLUMN_INDEX_MARKER, "marker");
if(SS.TEST_CASES_END_MARKER.equalsIgnoreCase(newMarkerValue)) {
// normal exit point
return;
@@ -140,14 +125,17 @@ public abstract class BaseTestFunctionsFromSpreadsheet {
if (testName.isEmpty()) {
testName = evalCell.getCellFormula();
}
-
- data.add(new Object[]{testName, filename, sheet, rowIndex, evaluator, precisionColumnIndex});
+
+ data.add(Arguments.of(testName, filename, sheet, rowIndex, evaluator, precisionColumnIndex));
}
fail("Missing end marker '" + SS.TEST_CASES_END_MARKER + "' on sheet '" + sheet.getSheetName() + "'");
}
- @Test
- public void processFunctionRow() throws Exception {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void processFunctionRow(
+ String testName, String filename, HSSFSheet sheet, int formulasRowIdx, HSSFFormulaEvaluator evaluator, int precisionColumnIndex
+ ) throws Exception {
HSSFRow r = sheet.getRow(formulasRowIdx);
HSSFCell evalCell = r.getCell(SS.COLUMN_INDEX_EVALUATION);
HSSFCell expectedCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT);
@@ -159,29 +147,29 @@ public abstract class BaseTestFunctionsFromSpreadsheet {
CellValue actualValue = evaluator.evaluate(evalCell);
- assertNotNull(msg + " - Bad setup data expected value is null", expectedCell);
- assertNotNull(msg + " - actual value was null", actualValue);
+ assertNotNull(expectedCell, msg + " - Bad setup data expected value is null");
+ assertNotNull(actualValue, msg + " - actual value was null");
if (expectedCell.getCellType() == CellType.ERROR) {
int expectedErrorCode = expectedCell.getErrorCellValue();
- assertEquals(msg, CellType.ERROR, actualValue.getCellType());
- assertEquals(msg, ErrorEval.getText(expectedErrorCode), actualValue.formatAsString());
- assertEquals(msg, expectedErrorCode, actualValue.getErrorValue());
- assertEquals(msg, ErrorEval.getText(expectedErrorCode), ErrorEval.getText(actualValue.getErrorValue()));
+ assertEquals(CellType.ERROR, actualValue.getCellType(), msg);
+ assertEquals(ErrorEval.getText(expectedErrorCode), actualValue.formatAsString(), msg);
+ assertEquals(expectedErrorCode, actualValue.getErrorValue(), msg);
+ assertEquals(ErrorEval.getText(expectedErrorCode), ErrorEval.getText(actualValue.getErrorValue()), msg);
return;
}
// unexpected error
- assertNotEquals(msg, CellType.ERROR, actualValue.getCellType());
+ assertNotEquals(CellType.ERROR, actualValue.getCellType(), msg);
assertNotEquals(msg, formatValue(expectedCell), ErrorEval.getText(actualValue.getErrorValue()));
// wrong type error
- assertEquals(msg, expectedCell.getCellType(), actualValue.getCellType());
+ assertEquals(expectedCell.getCellType(), actualValue.getCellType(), msg);
final CellType expectedCellType = expectedCell.getCellType();
switch (expectedCellType) {
case BOOLEAN:
- assertEquals(msg, expectedCell.getBooleanCellValue(), actualValue.getBooleanValue());
+ assertEquals(expectedCell.getBooleanCellValue(), actualValue.getBooleanValue(), 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);
@@ -191,7 +179,7 @@ public abstract class BaseTestFunctionsFromSpreadsheet {
assertEquals(expectedCell.getNumericCellValue(), actualValue.getNumberValue(), precision);
break;
case STRING:
- assertEquals(msg, expectedCell.getRichStringCellValue().getString(), actualValue.getStringValue());
+ assertEquals(expectedCell.getRichStringCellValue().getString(), actualValue.getStringValue(), msg);
break;
default:
fail("Unexpected cell type: " + expectedCellType);
@@ -205,11 +193,11 @@ public abstract class BaseTestFunctionsFromSpreadsheet {
*/
private static void confirmReadMeSheet(HSSFWorkbook workbook, Class<? extends BaseTestFunctionsFromSpreadsheet> clazz) {
String firstSheetName = workbook.getSheetName(0);
- assertTrue("First sheet's name was '" + firstSheetName + "' but expected '" + SS.README_SHEET_NAME + "'",
- firstSheetName.equalsIgnoreCase(SS.README_SHEET_NAME));
+ assertTrue(firstSheetName.equalsIgnoreCase(SS.README_SHEET_NAME),
+ "First sheet's name was '" + firstSheetName + "' but expected '" + SS.README_SHEET_NAME + "'");
HSSFSheet sheet = workbook.getSheetAt(0);
String specifiedClassName = sheet.getRow(2).getCell(0).getRichStringCellValue().getString();
- assertEquals("Test class name in spreadsheet comment", clazz.getName(), specifiedClassName);
+ assertEquals(clazz.getName(), specifiedClassName, "Test class name in spreadsheet comment");
HSSFRow precisionRow = sheet.getRow(11);
HSSFCell precisionCell = precisionRow == null ? null : precisionRow.getCell(0);
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestNumeric.java b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestNumeric.java
index ea1055cf7a..d5e02e0de8 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestNumeric.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestNumeric.java
@@ -20,7 +20,7 @@
*/
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
@@ -37,35 +37,30 @@ public abstract class BaseTestNumeric {
* for comparing doubles. DO NOT use that.
* TODO: This class should really be in an abstract super class
* to avoid code duplication across this project.
- * @param message
- * @param baseval
- * @param checkval
*/
- public static void assertEquals(String message, double baseval, double checkval, double almostZero, double diffToleranceFactor) {
+ public static void assertDouble(String message, double baseval, double checkval, double almostZero, double diffToleranceFactor) {
double posZero = Math.abs(almostZero);
double negZero = -1 * posZero;
if (Double.isNaN(baseval)) {
- assertTrue(message+": Expected " + baseval + " but was " + checkval
- , Double.isNaN(baseval));
+ assertTrue(Double.isNaN(baseval), message+": Expected " + baseval + " but was " + checkval);
}
else if (Double.isInfinite(baseval)) {
- assertTrue(message+": Expected " + baseval + " but was " + checkval
- , Double.isInfinite(baseval) && ((baseval<0) == (checkval<0)));
+ assertTrue(Double.isInfinite(baseval) && ((baseval<0) == (checkval<0)), message+": Expected " + baseval + " but was " + checkval);
}
else {
- assertTrue(message+": Expected " + baseval + " but was " + checkval
- ,baseval != 0
- ? Math.abs(baseval - checkval) <= Math.abs(diffToleranceFactor * baseval)
- : checkval < posZero && checkval > negZero);
+ assertTrue(baseval != 0
+ ? Math.abs(baseval - checkval) <= Math.abs(diffToleranceFactor * baseval)
+ : checkval < posZero && checkval > negZero,
+ message+": Expected " + baseval + " but was " + checkval);
}
}
- public static void assertEquals(String msg, double baseval, double checkval) {
- assertEquals(msg, baseval, checkval, POS_ZERO, DIFF_TOLERANCE_FACTOR);
+ public static void assertDouble(String msg, double baseval, double checkval) {
+ assertDouble(msg, baseval, checkval, POS_ZERO, DIFF_TOLERANCE_FACTOR);
}
- public static void assertEquals(double baseval, double checkval) {
- assertEquals("", baseval, checkval, POS_ZERO, DIFF_TOLERANCE_FACTOR);
+ public static void assertDouble(double baseval, double checkval) {
+ assertDouble("", baseval, checkval, POS_ZERO, DIFF_TOLERANCE_FACTOR);
}
}
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 e53f88e1fb..bf49dad45d 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/NumericFunctionInvoker.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NotImplementedException;
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestAddress.java b/src/testcases/org/apache/poi/ss/formula/functions/TestAddress.java
index e8b302b3ef..62f7f5e647 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestAddress.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestAddress.java
@@ -16,14 +16,14 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-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;
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;
public final class TestAddress {
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestAreas.java b/src/testcases/org/apache/poi/ss/formula/functions/TestAreas.java
index 08de5131de..5861d42ecf 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestAreas.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestAreas.java
@@ -17,14 +17,14 @@
package org.apache.poi.ss.formula.functions;
-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;
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;
public final class TestAreas {
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestAverage.java b/src/testcases/org/apache/poi/ss/formula/functions/TestAverage.java
index e24dd080f2..32ac46a525 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestAverage.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestAverage.java
@@ -17,14 +17,14 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for Excel function AVERAGE()
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestBin2Dec.java b/src/testcases/org/apache/poi/ss/formula/functions/TestBin2Dec.java
index f35d5253c6..ab906cdb24 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestBin2Dec.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestBin2Dec.java
@@ -17,18 +17,17 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.formula.IStabilityClassifier;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
/**
* Tests for {@link Bin2Dec}
@@ -44,14 +43,14 @@ public final class TestBin2Dec {
private static void confirmValue(String msg, String number1, String expected) {
ValueEval result = invokeValue(number1);
- assertEquals("Had: " + result, NumberEval.class, result.getClass());
- assertEquals(msg, expected, ((NumberEval) result).getStringValue());
+ assertEquals(NumberEval.class, result.getClass(), "Had: " + result);
+ assertEquals(expected, ((NumberEval) result).getStringValue(), msg);
}
private static void confirmValueError(String msg, String number1, ErrorEval numError) {
ValueEval result = invokeValue(number1);
assertEquals(ErrorEval.class, result.getClass());
- assertEquals(msg, numError, result);
+ assertEquals(numError, result, msg);
}
@Test
@@ -95,15 +94,8 @@ public final class TestBin2Dec {
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet();
HSSFEvaluationWorkbook workbook = HSSFEvaluationWorkbook.create(wb);
- WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, new IStabilityClassifier() {
-
- @Override
- public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
- return true;
- }
- }, null);
- return new OperationEvaluationContext(workbookEvaluator,
- workbook, 0, 0, 0, null);
+ WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, (sheetIndex, rowIndex, columnIndex) -> true, null);
+ return new OperationEvaluationContext(workbookEvaluator, workbook, 0, 0, 0, null);
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestBooleanFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestBooleanFunctionsFromSpreadsheet.java
index ef69a9c65b..1689cba236 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestBooleanFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestBooleanFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import org.junit.runners.Parameterized.Parameters;
+import java.util.stream.Stream;
-import java.util.Collection;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests boolean functions as loaded from a test data spreadsheet.<p>
*/
public class TestBooleanFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestBooleanFunctionsFromSpreadsheet.class, "BooleanFunctionsTestCaseData.xls");
}
}
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 1180c2dbcd..cf5dcb6fee 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-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;
@@ -25,8 +25,8 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Test for YEAR / MONTH / DAY / HOUR / MINUTE / SECOND
@@ -36,7 +36,7 @@ public final class TestCalendarFieldFunction {
private HSSFCell cell11;
private HSSFFormulaEvaluator evaluator;
- @Before
+ @BeforeEach
public void setUp() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
@@ -108,7 +108,7 @@ public final class TestCalendarFieldFunction {
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
- assertEquals("Wrong result type", CellType.NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType(), "Wrong result type");
double actualValue = cv.getNumberValue();
assertEquals(expectedResult, actualValue, 0);
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestClean.java b/src/testcases/org/apache/poi/ss/formula/functions/TestClean.java
index ef8d9a08e1..d6542611c1 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestClean.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestClean.java
@@ -16,14 +16,14 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-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;
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;
public final class TestClean {
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestCode.java b/src/testcases/org/apache/poi/ss/formula/functions/TestCode.java
index 8c1a176b6c..9b9e315a24 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestCode.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestCode.java
@@ -16,12 +16,12 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.ErrorEval;
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;
/**
* Tests for {@link Code}
@@ -37,13 +37,13 @@ public class TestCode {
private static void confirmValue(String msg, String number1, String expected) {
ValueEval result = invokeValue(number1);
assertEquals(StringEval.class, result.getClass());
- assertEquals(msg, expected, ((StringEval) result).getStringValue());
+ assertEquals(expected, ((StringEval) result).getStringValue(), msg);
}
private static void confirmValueError(String msg, String number1, ErrorEval numError) {
ValueEval result = invokeValue(number1);
assertEquals(ErrorEval.class, result.getClass());
- assertEquals(msg, numError, result);
+ assertEquals(numError, result, msg);
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestCodeFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestCodeFunctionsFromSpreadsheet.java
index 1d2e2cf0a7..7e9257bbc0 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestCodeFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestCodeFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests CODE() as loaded from a test data spreadsheet.<p>
*/
public class TestCodeFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestCodeFunctionsFromSpreadsheet.class, "CodeFunctionTestCaseData.xls");
}
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestComplex.java b/src/testcases/org/apache/poi/ss/formula/functions/TestComplex.java
index 54f7241df1..dd16248742 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestComplex.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestComplex.java
@@ -16,12 +16,12 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.ErrorEval;
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;
/**
* Tests for {@link Complex}
@@ -37,13 +37,13 @@ public class TestComplex {
private static void confirmValue(String msg, String real_num, String i_num, String suffix, String expected) {
ValueEval result = invokeValue(real_num, i_num, suffix);
assertEquals(StringEval.class, result.getClass());
- assertEquals(msg, expected, ((StringEval) result).getStringValue());
+ assertEquals(expected, ((StringEval) result).getStringValue(), msg);
}
private static void confirmValueError(String msg, String real_num, String i_num, String suffix, ErrorEval numError) {
ValueEval result = invokeValue(real_num, i_num, suffix);
assertEquals(ErrorEval.class, result.getClass());
- assertEquals(msg, numError, result);
+ assertEquals(numError, result, msg);
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestComplexFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestComplexFunctionsFromSpreadsheet.java
index f16246fd1c..6761090ed0 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestComplexFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestComplexFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests COMPLEX() as loaded from a test data spreadsheet.<p>
*/
public class TestComplexFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestComplexFunctionsFromSpreadsheet.class, "ComplexFunctionTestCaseData.xls");
}
} \ No newline at end of file
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 36a6f8dfa1..65238d17fb 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestCountFuncs.java
@@ -17,10 +17,10 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFCell;
@@ -41,7 +41,7 @@ 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.util.CellReference;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test cases for COUNT(), COUNTA() COUNTIF(), COUNTBLANK()
@@ -151,7 +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
- assertFalse("Identified bug 46647", mp.matches(seA) && !mp.matches(seB));
+ assertFalse(mp.matches(seA) && !mp.matches(seB), "Identified bug 46647");
assertFalse(mp.matches(seA));
assertTrue(mp.matches(seB));
@@ -420,10 +420,8 @@ public final class TestCountFuncs {
double expectedValue = cellRef.getNumericCellValue();
double actualValue = evaluator.evaluate(cellFmla).getNumberValue();
- assertEquals(
- "Problem with a formula at " +
- new CellReference(cellFmla).formatAsString() + "[" + cellFmla.getCellFormula()+"] ",
- expectedValue, actualValue, 0.0001);
+ assertEquals(expectedValue, actualValue, 0.0001,
+ "Problem with a formula at " + new CellReference(cellFmla).formatAsString() + "[" + cellFmla.getCellFormula()+"] ");
}
// string criteria
@@ -434,10 +432,8 @@ public final class TestCountFuncs {
double expectedValue = cellRef.getNumericCellValue();
double actualValue = evaluator.evaluate(cellFmla).getNumberValue();
- assertEquals(
- "Problem with a formula at " +
- new CellReference(cellFmla).formatAsString() + "[" + cellFmla.getCellFormula()+"] ",
- expectedValue, actualValue, 0.0001);
+ assertEquals(expectedValue, actualValue, 0.0001,
+ "Problem with a formula at " + new CellReference(cellFmla).formatAsString() + "[" + cellFmla.getCellFormula()+"] ");
}
}
@@ -533,11 +529,8 @@ public final class TestCountFuncs {
CellValue cv = fe.evaluate(cellA);
double actualValue = cv.getNumberValue();
double expectedValue = cellC.getNumericCellValue();
- assertEquals(
- "Problem with a formula at " + new CellReference(cellA).formatAsString()
- + ": " + cellA.getCellFormula() + " :"
- + "Expected = (" + expectedValue + ") Actual=(" + actualValue + ") ",
- expectedValue, actualValue, 0.0001);
+ assertEquals(expectedValue, actualValue, 0.0001,
+ "Problem with a formula at " + new CellReference(cellA).formatAsString() + ": " + cellA.getCellFormula() + " :Expected = (" + expectedValue + ") Actual=(" + actualValue + ") ");
}
HSSFSheet sheet2 = wb.getSheet("MSDN Example 2");
@@ -552,12 +545,9 @@ public final class TestCountFuncs {
double actualValue = cv.getNumberValue();
double expectedValue = cellC.getNumericCellValue();
- assertEquals(
- "Problem with a formula at " +
- new CellReference(cellA).formatAsString() + "[" + cellA.getCellFormula()+"]: "
- + "Expected = (" + expectedValue + ") Actual=(" + actualValue + ") ",
- expectedValue, actualValue, 0.0001);
-
+ assertEquals(expectedValue, actualValue, 0.0001,
+ "Problem with a formula at " + new CellReference(cellA).formatAsString() + "[" +
+ cellA.getCellFormula()+"]: Expected = (" + expectedValue + ") Actual=(" + actualValue + ") ");
}
}
@@ -589,6 +579,6 @@ public final class TestCountFuncs {
}
}
- assertEquals(failureCount + " " + functionName + " evaluations failed.", 0, failureCount);
+ assertEquals(0, failureCount, failureCount + " " + functionName + " evaluations failed.");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDGetFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDGetFunctionsFromSpreadsheet.java
index 4ac7b9861e..2f5a487730 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDGetFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDGetFunctionsFromSpreadsheet.java
@@ -16,16 +16,15 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests DGET() as loaded from a test data spreadsheet.
*/
public class TestDGetFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestDGetFunctionsFromSpreadsheet.class, "DGet.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDStarFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDStarFunctionsFromSpreadsheet.java
index 0d20d98d5d..3eb684bd89 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDStarFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDStarFunctionsFromSpreadsheet.java
@@ -16,16 +16,15 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests D*() functions as loaded from a test data spreadsheet.
*/
public class TestDStarFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestDStarFunctionsFromSpreadsheet.class, "DStar.xls");
}
}
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 f1b528d2c9..851b8da32d 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-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;
@@ -25,9 +25,9 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* @author Pavel Krupets (pkrupets at palmtreebusiness dot com)
@@ -37,7 +37,7 @@ public final class TestDate {
private HSSFCell cell11;
private HSSFFormulaEvaluator evaluator;
- @Before
+ @BeforeEach
public void setUp() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
@@ -50,7 +50,7 @@ public final class TestDate {
* TODO - create MissingArgEval and modify the formula evaluator to handle this
*/
@Test
- @Ignore
+ @Disabled
public void testSomeArgumentsMissing() {
confirm("DATE(, 1, 0)", 0.0);
confirm("DATE(, 1, 1)", 1.0);
@@ -87,7 +87,7 @@ public final class TestDate {
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
- assertEquals("Wrong result type", CellType.NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType(), "Wrong result type");
double actualValue = cv.getNumberValue();
assertEquals(expectedResult, actualValue, 0);
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDateTimeToNumberFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDateTimeToNumberFromSpreadsheet.java
index 87f709d91d..e53d46da69 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDateTimeToNumberFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDateTimeToNumberFromSpreadsheet.java
@@ -17,13 +17,12 @@
package org.apache.poi.ss.formula.functions;
-import org.junit.runners.Parameterized.Parameters;
+import java.util.stream.Stream;
-import java.util.Collection;
+import org.junit.jupiter.params.provider.Arguments;
public class TestDateTimeToNumberFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestDateTimeToNumberFromSpreadsheet.class, "DateTimeToNumberTestCases.xls");
}
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDateValue.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDateValue.java
index a25fa270d1..05da127bd9 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDateValue.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDateValue.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Locale;
@@ -27,9 +27,9 @@ import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.util.LocaleUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
* Tests for Excel function DATEVALUE()
@@ -38,12 +38,12 @@ import org.junit.Test;
*/
public final class TestDateValue {
- @BeforeClass
+ @BeforeAll
public static void init() {
LocaleUtil.setUserLocale(Locale.US);
}
- @AfterClass
+ @AfterAll
public static void clear() {
LocaleUtil.setUserLocale(null);
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java
index a20f444d70..590a33a5d8 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.formula.functions;
-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.Calendar;
import java.util.Date;
@@ -29,7 +29,7 @@ import org.apache.poi.ss.formula.eval.NumberEval;
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 final class TestDays360 {
@@ -60,7 +60,7 @@ public final class TestDays360 {
// longer time spans
confirm(562, 2008, 8, 11, 2010, 3, 3);
confirm(916, 2007, 2, 23, 2009, 9, 9);
-
+
// other tests
confirm(1, makeDate(1993, 2, 28), makeDate(1993, 3, 1), false);
confirm(1, makeDate(1996, 2, 29), makeDate(1996, 3, 1), false);
@@ -78,7 +78,7 @@ public final class TestDays360 {
confirm(expResult, makeDate(y1, m1, d1), makeDate(y2, m2, d2), false);
confirm(-expResult, makeDate(y2, m2, d2), makeDate(y1, m1, d1), false);
}
-
+
/**
* The <tt>method</tt> parameter only makes a difference when the second parameter
* is the last day of the month that does <em>not</em> have 30 days.
@@ -148,17 +148,17 @@ public final class TestDays360 {
} else {
ve = invokeDays360(convert(firstArg), convert(secondArg));
}
- assertTrue("wrong return type (" + ve.getClass().getName() + ")", ve instanceof NumberEval);
+ assertTrue(ve instanceof NumberEval, "wrong return type (" + ve.getClass().getName() + ")");
NumberEval numberEval = (NumberEval) ve;
String err = String.format(Locale.ROOT, "days360(%tF,%tF,%b) wrong result", firstArg, secondArg, method);
- assertEquals(err, expResult, numberEval.getNumberValue(), 0);
+ assertEquals(expResult, numberEval.getNumberValue(), 0, err);
}
-
+
private static ValueEval invokeDays360(ValueEval...args) {
return new Days360().evaluate(args, -1, -1);
}
-
+
private static NumberEval convert(Date d) {
return new NumberEval(DateUtil.getExcelDate(d));
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Bin.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Bin.java
index 336871811a..dd13c85aee 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Bin.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Bin.java
@@ -17,11 +17,10 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.formula.IStabilityClassifier;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.eval.ErrorEval;
@@ -31,7 +30,7 @@ import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link Dec2Bin}
@@ -52,14 +51,14 @@ public final class TestDec2Bin {
private static void confirmValue(String msg, String number1, String expected) {
ValueEval result = invokeValue(number1);
- assertEquals("Had: " + result, StringEval.class, result.getClass());
- assertEquals(msg, expected, ((StringEval) result).getStringValue());
+ assertEquals(StringEval.class, result.getClass(), "Had: " + result);
+ assertEquals(expected, ((StringEval) result).getStringValue(), msg);
}
private static void confirmValueError(String msg, String number1, ErrorEval numError) {
ValueEval result = invokeValue(number1);
assertEquals(ErrorEval.class, result.getClass());
- assertEquals(msg, numError, result);
+ assertEquals(numError, result, msg);
}
@Test
@@ -115,15 +114,8 @@ public final class TestDec2Bin {
cell.setCellValue("1");
HSSFEvaluationWorkbook workbook = HSSFEvaluationWorkbook.create(wb);
- WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, new IStabilityClassifier() {
-
- @Override
- public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
- return true;
- }
- }, null);
- return new OperationEvaluationContext(workbookEvaluator,
- workbook, 0, 0, 0, null);
+ WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, (sheetIndex, rowIndex, columnIndex) -> true, null);
+ return new OperationEvaluationContext(workbookEvaluator, workbook, 0, 0, 0, null);
}
@Test
@@ -133,7 +125,7 @@ public final class TestDec2Bin {
ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0) };
ValueEval result = new Dec2Bin().evaluate(args, -1, -1);
- assertEquals("Had: " + result, StringEval.class, result.getClass());
+ assertEquals(StringEval.class, result.getClass(), "Had: " + result);
assertEquals("1101", ((StringEval) result).getStringValue());
}
@@ -144,7 +136,7 @@ public final class TestDec2Bin {
ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0), ctx.getRefEval(0, 1) };
ValueEval result = new Dec2Bin().evaluate(args, -1, -1);
- assertEquals("Had: " + result, StringEval.class, result.getClass());
+ assertEquals(StringEval.class, result.getClass(), "Had: " + result);
// TODO: documentation and behavior do not match here!
assertEquals("1101", ((StringEval) result).getStringValue());
}
@@ -156,7 +148,7 @@ public final class TestDec2Bin {
ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0), ctx.getRefEval(0, 1) };
ValueEval result = new Dec2Bin().evaluate(args, ctx);
- assertEquals("Had: " + result, StringEval.class, result.getClass());
+ assertEquals(StringEval.class, result.getClass(), "Had: " + result);
// TODO: documentation and behavior do not match here!
assertEquals("1101", ((StringEval) result).getStringValue());
}
@@ -242,15 +234,12 @@ public final class TestDec2Bin {
public void testBackAndForth() {
for (int i = -512; i < 512; i++) {
ValueEval result = invokeValue(Integer.toString(i));
- assertEquals("Had: " + result, StringEval.class,
- result.getClass());
+ assertEquals(StringEval.class, result.getClass(), "Had: " + result);
ValueEval back = invokeBack(((StringEval) result).getStringValue());
- assertEquals("Had: " + back, NumberEval.class,
- back.getClass());
+ assertEquals(NumberEval.class, back.getClass(), "Had: " + back);
- assertEquals(Integer.toString(i),
- ((NumberEval) back).getStringValue());
+ assertEquals(Integer.toString(i), ((NumberEval) back).getStringValue());
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java
index ac88365dde..286c3c837e 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java
@@ -17,11 +17,10 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.formula.IStabilityClassifier;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.eval.ErrorEval;
@@ -31,7 +30,7 @@ import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link Dec2Hex}
@@ -58,19 +57,19 @@ public final class TestDec2Hex {
private static void confirmValue(String msg, String number1, String number2, String expected) {
ValueEval result = invokeValue(number1, number2);
assertEquals(StringEval.class, result.getClass());
- assertEquals(msg, expected, ((StringEval) result).getStringValue());
+ assertEquals(expected, ((StringEval) result).getStringValue(), msg);
}
private static void confirmValue(String msg, String number1, String expected) {
ValueEval result = invokeValue(number1);
assertEquals(StringEval.class, result.getClass());
- assertEquals(msg, expected, ((StringEval) result).getStringValue());
+ assertEquals(expected, ((StringEval) result).getStringValue(), msg);
}
private static void confirmValueError(String msg, String number1, String number2, ErrorEval numError) {
ValueEval result = invokeValue(number1, number2);
assertEquals(ErrorEval.class, result.getClass());
- assertEquals(msg, numError, result);
+ assertEquals(numError, result, msg);
}
@Test
@@ -98,11 +97,11 @@ public final class TestDec2Hex {
assertEquals("2147483648", maxIntPlusOne);
confirmValue("Converts INT_MAX + 1 to hexadecimal", maxIntPlusOne, "80000000");
- String maxLong = Long.toString(549755813887l);
+ String maxLong = Long.toString(549755813887L);
assertEquals("549755813887", maxLong);
confirmValue("Converts the max supported value to hexadecimal", maxLong, "7FFFFFFFFF");
- String minLong = Long.toString(-549755813888l);
+ String minLong = Long.toString(-549755813888L);
assertEquals("-549755813888", minLong);
confirmValue("Converts the min supported value to hexadecimal", minLong, "FF80000000");
}
@@ -139,15 +138,8 @@ public final class TestDec2Hex {
cell.setCellValue("-8");
HSSFEvaluationWorkbook workbook = HSSFEvaluationWorkbook.create(wb);
- WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, new IStabilityClassifier() {
-
- @Override
- public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
- return true;
- }
- }, null);
- return new OperationEvaluationContext(workbookEvaluator,
- workbook, 0, 0, 0, null);
+ WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, (sheetIndex, rowIndex, columnIndex) -> true, null);
+ return new OperationEvaluationContext(workbookEvaluator, workbook, 0, 0, 0, null);
}
@Test
@@ -157,7 +149,7 @@ public final class TestDec2Hex {
ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0) };
ValueEval result = new Dec2Hex().evaluate(args, -1, -1);
- assertEquals("Had: " + result, StringEval.class, result.getClass());
+ assertEquals(StringEval.class, result.getClass(), "Had: " + result);
assertEquals("7B", ((StringEval) result).getStringValue());
}
@@ -168,7 +160,7 @@ public final class TestDec2Hex {
ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0), ctx.getRefEval(0, 1) };
ValueEval result = new Dec2Hex().evaluate(args, -1, -1);
- assertEquals("Had: " + result, StringEval.class, result.getClass());
+ assertEquals(StringEval.class, result.getClass(), "Had: " + result);
assertEquals("0000007B", ((StringEval) result).getStringValue());
}
@@ -179,7 +171,7 @@ public final class TestDec2Hex {
ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0), ctx.getRefEval(0, 1) };
ValueEval result = new Dec2Hex().evaluate(args, ctx);
- assertEquals("Had: " + result, StringEval.class, result.getClass());
+ assertEquals(StringEval.class, result.getClass(), "Had: " + result);
assertEquals("0000007B", ((StringEval) result).getStringValue());
}
@@ -242,15 +234,12 @@ public final class TestDec2Hex {
public void testBackAndForth() {
for (int i = -512; i < 512; i++) {
ValueEval result = invokeValue(Integer.toString(i));
- assertEquals("Had: " + result, StringEval.class,
- result.getClass());
+ assertEquals(StringEval.class, result.getClass(), "Had: " + result);
ValueEval back = invokeBack(((StringEval) result).getStringValue());
- assertEquals("Had: " + back, NumberEval.class,
- back.getClass());
+ assertEquals(NumberEval.class, back.getClass(), "Had: " + back);
- assertEquals(Integer.toString(i),
- ((NumberEval) back).getStringValue());
+ assertEquals(Integer.toString(i), ((NumberEval) back).getStringValue());
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDelta.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDelta.java
index 756b532bf2..b7f64c22e6 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDelta.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDelta.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
/**
* Tests for {@link org.apache.poi.ss.formula.functions.Delta}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java
index f1725d70bc..75755db7e0 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java
@@ -16,16 +16,15 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests DELTA() as loaded from a test data spreadsheet.<p>
*/
public class TestDeltaFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestDeltaFunctionsFromSpreadsheet.class, "DeltaFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestEDate.java b/src/testcases/org/apache/poi/ss/formula/functions/TestEDate.java
index 1b134483de..3bcebaa613 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestEDate.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestEDate.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.formula.functions;
-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.Calendar;
import java.util.Date;
@@ -30,7 +30,7 @@ import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestEDate {
@@ -53,7 +53,7 @@ public class TestEDate {
NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new NumberEval(startDate), new NumberEval(monthInc)}, null);
assertEquals(expectedResult, result.getNumberValue(), 0);
}
-
+
@Test
public void testEDateInvalidValues() {
EDate eDate = new EDate();
@@ -87,9 +87,9 @@ public class TestEDate {
instance.add(Calendar.MONTH, offset);
assertEquals(resultDate, instance.getTime());
}
-
+
@Test
- public void testBug56688() {
+ public void testBug56688() {
EDate eDate = new EDate();
NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new NumberEval(1000), new RefEvalImplementation(new NumberEval(0))}, null);
assertEquals(1000d, result.getNumberValue(), 0);
@@ -119,11 +119,9 @@ public class TestEDate {
public void testEDateBlankRefValueEval() {
EDate eDate = new EDate();
NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new RefEvalImplementation(BlankEval.instance), new NumberEval(0)}, null);
- assertEquals("0 startDate triggers BAD_DATE currently, thus -1.0!",
- -1.0d, result.getNumberValue(), 0);
+ assertEquals(-1.0d, result.getNumberValue(), 0, "0 startDate triggers BAD_DATE currently, thus -1.0!");
result = (NumberEval) eDate.evaluate(new ValueEval[]{new NumberEval(1), new RefEvalImplementation(BlankEval.instance)}, null);
- assertEquals("Blank is handled as 0 otherwise",
- 1.0d, result.getNumberValue(), 0);
+ assertEquals(1.0d, result.getNumberValue(), 0, "Blank is handled as 0 otherwise");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestEOMonth.java b/src/testcases/org/apache/poi/ss/formula/functions/TestEOMonth.java
index 8fbfa69961..0d7f60e2f0 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestEOMonth.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestEOMonth.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.formula.functions;
-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.Calendar;
import java.util.Date;
@@ -32,7 +32,7 @@ import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestEOMonth {
@@ -76,10 +76,10 @@ public class TestEOMonth {
@Test
public void testEOMonthZeroDate() {
NumberEval result = (NumberEval) eOMonth.evaluate(new ValueEval[] {new NumberEval(0), new NumberEval(0)}, ec);
- assertEquals("0 startDate is 1900-01-00", DATE_1900_01_31, result.getNumberValue(), 0);
+ assertEquals(DATE_1900_01_31, result.getNumberValue(), 0, "0 startDate is 1900-01-00");
result = (NumberEval) eOMonth.evaluate(new ValueEval[] {new NumberEval(0), new NumberEval(1)}, ec);
- assertEquals("0 startDate is 1900-01-00", DATE_1900_02_28, result.getNumberValue(), 0);
+ assertEquals(DATE_1900_02_28, result.getNumberValue(), 0, "0 startDate is 1900-01-00");
}
@Test
@@ -114,7 +114,7 @@ public class TestEOMonth {
};
NumberEval result = (NumberEval) eOMonth.evaluate(ve, ec);
Date actDate = DateUtil.getJavaDate(result.getNumberValue());
-
+
assertEquals(expDate, actDate);
}
}
@@ -136,17 +136,17 @@ public class TestEOMonth {
@Test
public void testEOMonthBlankValueEval() {
NumberEval evaluate = (NumberEval) eOMonth.evaluate(new ValueEval[] {BlankEval.instance, new NumberEval(0)}, ec);
- assertEquals("Blank is handled as 0", DATE_1900_01_31, evaluate.getNumberValue(), 0);
+ assertEquals(DATE_1900_01_31, evaluate.getNumberValue(), 0, "Blank is handled as 0");
}
@Test
public void testEOMonthBlankRefValueEval() {
ValueEval[] ve1 = {new RefEvalImplementation(BlankEval.instance), new NumberEval(1)};
NumberEval result = (NumberEval) eOMonth.evaluate(ve1, ec);
- assertEquals("Blank is handled as 0", DATE_1900_02_28, result.getNumberValue(), 0);
+ assertEquals(DATE_1900_02_28, result.getNumberValue(), 0, "Blank is handled as 0");
ValueEval[] ve2 = {new NumberEval(1), new RefEvalImplementation(BlankEval.instance)};
result = (NumberEval) eOMonth.evaluate(ve2, ec);
- assertEquals("Blank is handled as 0", DATE_1900_01_31, result.getNumberValue(), 0);
+ assertEquals(DATE_1900_01_31, result.getNumberValue(), 0, "Blank is handled as 0");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java
index 2d21db2260..ff28a5fd34 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests FactDouble() as loaded from a test data spreadsheet.<p>
*/
public class TestFactDoubleFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestFactDoubleFunctionsFromSpreadsheet.class, "FactDoubleFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestFinanceLib.java b/src/testcases/org/apache/poi/ss/formula/functions/TestFinanceLib.java
index 2e08083ca2..8a151ea2ac 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestFinanceLib.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestFinanceLib.java
@@ -21,7 +21,7 @@
package org.apache.poi.ss.formula.functions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
@@ -38,38 +38,38 @@ public class TestFinanceLib extends BaseTestNumeric {
r = 0; n = 3; y = 2; p = 7; t = true;
f = FinanceLib.fv(r, n, y, p, t);
x = -13;
- assertEquals("fv ", x, f);
+ assertDouble("fv ", x, f);
r = 1; n = 10; y = 100; p = 10000; t = false;
f = FinanceLib.fv(r, n, y, p, t);
x = -10342300;
- assertEquals("fv ", x, f);
+ assertDouble("fv ", x, f);
r = 1; n = 10; y = 100; p = 10000; t = true;
f = FinanceLib.fv(r, n, y, p, t);
x = -10444600;
- assertEquals("fv ", x, f);
+ assertDouble("fv ", x, f);
r = 2; n = 12; y = 120; p = 12000; t = false;
f = FinanceLib.fv(r, n, y, p, t);
x = -6409178400d;
- assertEquals("fv ", x, f);
+ assertDouble("fv ", x, f);
r = 2; n = 12; y = 120; p = 12000; t = true;
f = FinanceLib.fv(r, n, y, p, t);
x = -6472951200d;
- assertEquals("fv ", x, f);
+ assertDouble("fv ", x, f);
// cross tests with pv
r = 2.95; n = 13; y = 13000; p = -4406.78544294496; t = false;
f = FinanceLib.fv(r, n, y, p, t);
x = 333891.230010986; // as returned by excel
- assertEquals("fv ", x, f);
+ assertDouble("fv ", x, f);
r = 2.95; n = 13; y = 13000; p = -17406.7852148156; t = true;
f = FinanceLib.fv(r, n, y, p, t);
x = 333891.230102539; // as returned by excel
- assertEquals("fv ", x, f);
+ assertDouble("fv ", x, f);
}
@@ -83,22 +83,22 @@ public class TestFinanceLib extends BaseTestNumeric {
r = 1; v = new double[]{100, 200, 300, 400};
npv = FinanceLib.npv(r, v);
x = 162.5;
- assertEquals("npv ", x, npv);
+ assertDouble("npv ", x, npv);
r = 2.5; v = new double[]{1000, 666.66666, 333.33, 12.2768416};
npv = FinanceLib.npv(r, v);
x = 347.99232604144827;
- assertEquals("npv ", x, npv);
+ assertDouble("npv ", x, npv);
r = 12.33333; v = new double[]{1000, 0, -900, -7777.5765};
npv = FinanceLib.npv(r, v);
x = 74.3742433377061;
- assertEquals("npv ", x, npv);
+ assertDouble("npv ", x, npv);
r = 0.05; v = new double[]{200000, 300000.55, 400000, 1000000, 6000000, 7000000, -300000};
npv = FinanceLib.npv(r, v);
x = 11342283.4233124;
- assertEquals("npv ", x, npv);
+ assertDouble("npv ", x, npv);
}
@Test
@@ -110,29 +110,29 @@ public class TestFinanceLib extends BaseTestNumeric {
r = 0; n = 3; p = 2; f = 7; t = true;
y = FinanceLib.pmt(r, n, p, f, t);
x = -3;
- assertEquals("pmt ", x, y);
+ assertDouble("pmt ", x, y);
// cross check with pv
r = 1; n = 10; p = -109.66796875; f = 10000; t = false;
y = FinanceLib.pmt(r, n, p, f, t);
x = 100;
- assertEquals("pmt ", x, y);
+ assertDouble("pmt ", x, y);
r = 1; n = 10; p = -209.5703125; f = 10000; t = true;
y = FinanceLib.pmt(r, n, p, f, t);
x = 100;
- assertEquals("pmt ", x, y);
+ assertDouble("pmt ", x, y);
// cross check with fv
r = 2; n = 12; f = -6409178400d; p = 12000; t = false;
y = FinanceLib.pmt(r, n, p, f, t);
x = 120;
- assertEquals("pmt ", x, y);
+ assertDouble("pmt ", x, y);
r = 2; n = 12; f = -6472951200d; p = 12000; t = true;
y = FinanceLib.pmt(r, n, p, f, t);
x = 120;
- assertEquals("pmt ", x, y);
+ assertDouble("pmt ", x, y);
}
@Test
@@ -144,38 +144,38 @@ public class TestFinanceLib extends BaseTestNumeric {
r = 0; n = 3; y = 2; f = 7; t = true;
f = FinanceLib.pv(r, n, y, f, t);
x = -13;
- assertEquals("pv ", x, f);
+ assertDouble("pv ", x, f);
r = 1; n = 10; y = 100; f = 10000; t = false;
p = FinanceLib.pv(r, n, y, f, t);
x = -109.66796875;
- assertEquals("pv ", x, p);
+ assertDouble("pv ", x, p);
r = 1; n = 10; y = 100; f = 10000; t = true;
p = FinanceLib.pv(r, n, y, f, t);
x = -209.5703125;
- assertEquals("pv ", x, p);
+ assertDouble("pv ", x, p);
r = 2.95; n = 13; y = 13000; f = 333891.23; t = false;
p = FinanceLib.pv(r, n, y, f, t);
x = -4406.78544294496;
- assertEquals("pv ", x, p);
+ assertDouble("pv ", x, p);
r = 2.95; n = 13; y = 13000; f = 333891.23; t = true;
p = FinanceLib.pv(r, n, y, f, t);
x = -17406.7852148156;
- assertEquals("pv ", x, p);
+ assertDouble("pv ", x, p);
// cross tests with fv
r = 2; n = 12; y = 120; f = -6409178400d; t = false;
p = FinanceLib.pv(r, n, y, f, t);
x = 12000;
- assertEquals("pv ", x, p);
+ assertDouble("pv ", x, p);
r = 2; n = 12; y = 120; f = -6472951200d; t = true;
p = FinanceLib.pv(r, n, y, f, t);
x = 12000;
- assertEquals("pv ", x, p);
+ assertDouble("pv ", x, p);
}
@@ -187,28 +187,28 @@ public class TestFinanceLib extends BaseTestNumeric {
r = 0; y = 7; p = 2; f = 3; t = false;
n = FinanceLib.nper(r, y, p, f, t);
x = -0.71428571429; // can you believe it? excel returns nper as a fraction!??
- assertEquals("nper ", x, n);
+ assertDouble("nper ", x, n);
// cross check with pv
r = 1; y = 100; p = -109.66796875; f = 10000; t = false;
n = FinanceLib.nper(r, y, p, f, t);
x = 10;
- assertEquals("nper ", x, n);
+ assertDouble("nper ", x, n);
r = 1; y = 100; p = -209.5703125; f = 10000; t = true;
n = FinanceLib.nper(r, y, p, f, t);
x = 10;
- assertEquals("nper ", x, n);
+ assertDouble("nper ", x, n);
// cross check with fv
r = 2; y = 120; f = -6409178400d; p = 12000; t = false;
n = FinanceLib.nper(r, y, p, f, t);
x = 12;
- assertEquals("nper ", x, n);
+ assertDouble("nper ", x, n);
r = 2; y = 120; f = -6472951200d; p = 12000; t = true;
n = FinanceLib.nper(r, y, p, f, t);
x = 12;
- assertEquals("nper ", x, n);
+ assertDouble("nper ", x, n);
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestFind.java b/src/testcases/org/apache/poi/ss/formula/functions/TestFind.java
index 0bfff626af..520cd435b1 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestFind.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestFind.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
@@ -27,7 +27,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaError;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link Financed}
@@ -57,7 +57,7 @@ public final class TestFind {
confirmError(fe, cell, "find(\"k\", \"haystack\",0)", FormulaError.VALUE);
confirmError(fe, cell, "find(#DIV/0!, #N/A, #REF!)", FormulaError.DIV0);
confirmError(fe, cell, "find(2, #N/A, #REF!)", FormulaError.NA);
-
+
wb.close();
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java b/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java
index 462acd3115..9b2da6b1ec 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.formula.functions;
-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.io.IOException;
@@ -34,15 +34,15 @@ import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaError;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public final class TestFixed {
private HSSFCell cell11;
private HSSFFormulaEvaluator evaluator;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet("new sheet");
@@ -86,14 +86,14 @@ public final class TestFixed {
// rounding propagation
confirm("FIXED(99.9,0,TRUE)", "100");
}
-
+
@Test
public void testOptionalParams() {
Fixed fixed = new Fixed();
ValueEval evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789));
assertTrue(evaluate instanceof StringEval);
assertEquals("1,234.57", ((StringEval)evaluate).getStringValue());
-
+
evaluate = fixed.evaluate(0, 0, new NumberEval(1234.56789), new NumberEval(1));
assertTrue(evaluate instanceof StringEval);
assertEquals("1,234.6", ((StringEval)evaluate).getStringValue());
@@ -113,17 +113,17 @@ public final class TestFixed {
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
- assertEquals("Wrong result type: " + cv.formatAsString(), CellType.STRING, cv.getCellType());
+ assertEquals(CellType.STRING, cv.getCellType(), "Wrong result type: " + cv.formatAsString());
String actualValue = cv.getStringValue();
assertEquals(expectedResult, actualValue);
}
-
+
private void confirmValueError(String formulaText) {
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
- assertTrue("Wrong result type: " + cv.formatAsString(),
- cv.getCellType() == CellType.ERROR
- && cv.getErrorValue() == FormulaError.VALUE.getCode());
+ assertTrue(cv.getCellType() == CellType.ERROR
+ && cv.getErrorValue() == FormulaError.VALUE.getCode(),
+ "Wrong result type: " + cv.formatAsString());
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestFixedFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestFixedFunctionsFromSpreadsheet.java
index a5efd75e2e..050b61d676 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestFixedFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestFixedFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests FIXED() as loaded from a test data spreadsheet.
*/
public class TestFixedFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestFixedFunctionsFromSpreadsheet.class, "57003-FixedFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestFrequency.java b/src/testcases/org/apache/poi/ss/formula/functions/TestFrequency.java
index c441c82ade..271cba7d20 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestFrequency.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestFrequency.java
@@ -16,14 +16,19 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
+import static org.apache.poi.ss.formula.functions.Frequency.histogram;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellRange;
+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.apache.poi.ss.util.CellRangeAddress;
-import org.junit.Test;
-
-import static org.apache.poi.ss.formula.functions.Frequency.histogram;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Test;
/**
* Testcase for the function FREQUENCY(data, bins)
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestGeomean.java b/src/testcases/org/apache/poi/ss/formula/functions/TestGeomean.java
index 50b57b3671..50fbf41cab 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestGeomean.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestGeomean.java
@@ -16,11 +16,17 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-import org.apache.poi.ss.formula.eval.*;
-import org.junit.Test;
-
-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.ss.formula.eval.BlankEval;
+import org.apache.poi.ss.formula.eval.BoolEval;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.MissingArgEval;
+import org.apache.poi.ss.formula.eval.NumberEval;
+import org.apache.poi.ss.formula.eval.StringEval;
+import org.apache.poi.ss.formula.eval.ValueEval;
+import org.junit.jupiter.api.Test;
/**
* From Excel documentation at https://support.office.com/en-us/article/geomean-function-db1ac48d-25a5-40a0-ab83-0b38980e40d5:
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestHex2Dec.java b/src/testcases/org/apache/poi/ss/formula/functions/TestHex2Dec.java
index dac6dda140..d09810bd98 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestHex2Dec.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestHex2Dec.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -27,7 +27,7 @@ import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
/**
* Tests for {@link Hex2Dec}
@@ -44,13 +44,13 @@ public final class TestHex2Dec {
private static void confirmValue(String msg, String number1, String expected) {
ValueEval result = invokeValue(number1);
assertEquals(NumberEval.class, result.getClass());
- assertEquals(msg, expected, ((NumberEval) result).getStringValue());
+ assertEquals(expected, ((NumberEval) result).getStringValue(), msg);
}
private static void confirmValueError(String msg, String number1, ErrorEval numError) {
ValueEval result = invokeValue(number1);
assertEquals(ErrorEval.class, result.getClass());
- assertEquals(msg, numError, result);
+ assertEquals(numError, result, msg);
}
@Test
@@ -93,8 +93,7 @@ public final class TestHex2Dec {
wb.createSheet();
HSSFEvaluationWorkbook workbook = HSSFEvaluationWorkbook.create(wb);
WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, (sheetIndex, rowIndex, columnIndex) -> true, null);
- return new OperationEvaluationContext(workbookEvaluator,
- workbook, 0, 0, 0, null);
+ return new OperationEvaluationContext(workbookEvaluator, workbook, 0, 0, 0, null);
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIFFunctionFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIFFunctionFromSpreadsheet.java
index cbdbfa5043..8e6fb4573b 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIFFunctionFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIFFunctionFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import org.junit.runners.Parameterized.Parameters;
+import java.util.stream.Stream;
-import java.util.Collection;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests IF() as loaded from a test data spreadsheet.<p>
*/
public class TestIFFunctionFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestIFFunctionFromSpreadsheet.class, "IfFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIPMT.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIPMT.java
index abd265bdf6..2fc27bbdb2 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIPMT.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIPMT.java
@@ -19,14 +19,14 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test cases for IPMT()
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestImRealFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestImRealFunctionsFromSpreadsheet.java
index 4fcd937597..b9ba1ae580 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestImRealFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestImRealFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests ImReal() as loaded from a test data spreadsheet.<p>
*/
public class TestImRealFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestImRealFunctionsFromSpreadsheet.class, "ImRealFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestImaginaryFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestImaginaryFunctionsFromSpreadsheet.java
index cb03894316..a0ffeb2849 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestImaginaryFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestImaginaryFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests Imaginary() as loaded from a test data spreadsheet.<p>
*/
public class TestImaginaryFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestImaginaryFunctionsFromSpreadsheet.class, "ImaginaryFunctionTestCaseData.xls");
}
}
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 fbb63dc0bd..bc44ab3c15 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndex.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.formula.functions;
-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;
@@ -35,7 +35,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.CellRangeAddress;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for the INDEX() function.</p>
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIndexFunctionFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIndexFunctionFromSpreadsheet.java
index 6a543f3ff7..c477104ffb 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIndexFunctionFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndexFunctionFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests INDEX() as loaded from a test data spreadsheet.<p>
*/
public final class TestIndexFunctionFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestIndexFunctionFromSpreadsheet.class, "IndexFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java
index ea5ac9c7aa..7bd3025c1c 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java
@@ -17,8 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
@@ -32,7 +31,7 @@ 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.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for the INDIRECT() function.</p>
@@ -175,35 +174,26 @@ public final class TestIndirect {
// 2 level recursion
confirm(feB, cellB, "INDIRECT(\"[MyBook]Sheet2!A1\")", 50); // set up (and check) first level
confirm(feA, cellA, "INDIRECT(\"'[Figures for January]Sheet1'!A11\")", 50); // points to cellB
-
+
wbB.close();
wbA.close();
}
- private static void confirm(FormulaEvaluator fe, Cell cell, String formula,
- double expectedResult) {
+ private static void confirm(FormulaEvaluator fe, Cell cell, String formula, double expectedResult) {
fe.clearAllCachedResultValues();
cell.setCellFormula(formula);
CellValue cv = fe.evaluate(cell);
- if (cv.getCellType() != CellType.NUMERIC) {
- fail("expected numeric cell type but got " + cv.formatAsString());
- }
+ assertEquals(CellType.NUMERIC, cv.getCellType(), "expected numeric cell type but got " + cv.formatAsString());
assertEquals(expectedResult, cv.getNumberValue(), 0.0);
}
-
- private static void confirm(FormulaEvaluator fe, Cell cell, String formula,
- ErrorEval expectedResult) {
+
+ private static void confirm(FormulaEvaluator fe, Cell cell, String formula, ErrorEval expectedResult) {
fe.clearAllCachedResultValues();
cell.setCellFormula(formula);
CellValue cv = fe.evaluate(cell);
- if (cv.getCellType() != CellType.ERROR) {
- fail("expected error cell type but got " + cv.formatAsString());
- }
+ assertEquals(CellType.ERROR, cv.getCellType(), "expected error cell type but got " + cv.formatAsString());
int expCode = expectedResult.getErrorCode();
- if (cv.getErrorValue() != expCode) {
- fail("Expected error '" + ErrorEval.getText(expCode)
- + "' but got '" + cv.formatAsString() + "'.");
- }
+ assertEquals(expCode, cv.getErrorValue(), "Expected error '" + ErrorEval.getText(expCode) + "' but got '" + cv.formatAsString() + "'.");
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java
index 5df83b43bd..8f7f15fffb 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests INDIRECT() as loaded from a test data spreadsheet.<p>
@@ -29,8 +29,7 @@ import org.junit.runners.Parameterized.Parameters;
* more easily.
*/
public final class TestIndirectFunctionFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestIndirectFunctionFromSpreadsheet.class, "IndirectFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIntercept.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIntercept.java
index 393ebb3710..e375051c12 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIntercept.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIntercept.java
@@ -19,7 +19,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFCell;
@@ -29,7 +29,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test for Excel function INTERCEPT()
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 9dc7558485..3630f48b0e 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIrr.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFCell;
@@ -27,7 +27,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
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 {@link Irr}
@@ -40,28 +40,28 @@ public final class TestIrr {
double[] incomes = {-4000d, 1200d, 1410d, 1875d, 1050d};
double irr = Irr.irr(incomes);
double irrRounded = Math.round(irr * 1000d) / 1000d;
- assertEquals("irr", 0.143d, irrRounded, 0);
+ assertEquals(0.143d, irrRounded, 0);
// http://www.techonthenet.com/excel/formulas/irr.php
incomes = new double[]{-7500d, 3000d, 5000d, 1200d, 4000d};
irr = Irr.irr(incomes);
irrRounded = Math.round(irr * 100d) / 100d;
- assertEquals("irr", 0.28d, irrRounded, 0);
+ assertEquals(0.28d, irrRounded, 0);
incomes = new double[]{-10000d, 3400d, 6500d, 1000d};
irr = Irr.irr(incomes);
irrRounded = Math.round(irr * 100d) / 100d;
- assertEquals("irr", 0.05, irrRounded, 0);
+ assertEquals(0.05, irrRounded, 0);
incomes = new double[]{100d, -10d, -110d};
irr = Irr.irr(incomes);
irrRounded = Math.round(irr * 100d) / 100d;
- assertEquals("irr", 0.1, irrRounded, 0);
+ assertEquals(0.1, irrRounded, 0);
incomes = new double[]{-70000d, 12000, 15000};
irr = Irr.irr(incomes, -0.1);
irrRounded = Math.round(irr * 100d) / 100d;
- assertEquals("irr", -0.44, irrRounded, 0);
+ assertEquals(-0.44, irrRounded, 0);
}
@Test
@@ -92,7 +92,6 @@ public final class TestIrr {
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)"
for(int rownum = 9; rownum <= 15; rownum++){
@@ -105,7 +104,6 @@ public final class TestIrr {
if(failures.length() > 0) failures.append('\n');
failures.append("Row[" + (cellA.getRowIndex() + 1)+ "]: " + cellA.getCellFormula() + " ");
failures.append(e.getMessage());
- failureCount++;
}
HSSFCell cellC = row.getCell(2); //IRR-NPV relationship: NPV(IRR(values), values) = 0
@@ -116,17 +114,15 @@ public final class TestIrr {
if(failures.length() > 0) failures.append('\n');
failures.append("Row[" + (cellC.getRowIndex() + 1)+ "]: " + cellC.getCellFormula() + " ");
failures.append(e.getMessage());
- failureCount++;
}
}
-
- assertEquals("IRR assertions failed", 0, failures.length());
+ assertEquals(0, failures.length(), "IRR assertions failed");
}
private static void assertFormulaResult(CellValue cv, HSSFCell cell){
double actualValue = cv.getNumberValue();
double expectedValue = cell.getNumericCellValue(); // cached formula result calculated by Excel
- assertEquals("Invalid formula result: " + cv, CellType.NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType(), "Invalid formula result: " + cv);
assertEquals(expectedValue, actualValue, 1E-4); // should agree within 0.01%
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIsBlank.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIsBlank.java
index 5d142c8ec6..989d88f474 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIsBlank.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIsBlank.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.formula.functions;
-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.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
@@ -27,7 +27,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
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 Excel function ISBLANK()
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestLeftRight.java b/src/testcases/org/apache/poi/ss/formula/functions/TestLeftRight.java
index a564f07b25..a96def2d7e 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestLeftRight.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestLeftRight.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
/**
*
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestLen.java b/src/testcases/org/apache/poi/ss/formula/functions/TestLen.java
index 4350569aaa..6ff7be55a5 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestLen.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestLen.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.BoolEval;
@@ -25,7 +25,7 @@ import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
/**
* Tests for Excel function LEN()
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestLogicalFunction.java b/src/testcases/org/apache/poi/ss/formula/functions/TestLogicalFunction.java
index 712ff361de..d14e9f6591 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestLogicalFunction.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestLogicalFunction.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
@@ -31,8 +31,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.CellReference;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* LogicalFunction unit tests.
@@ -44,7 +44,7 @@ public class TestLogicalFunction {
private Cell cell1;
private Cell cell2;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
try (Workbook wb = new HSSFWorkbook()) {
buildWorkbook(wb);
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestLogicalFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestLogicalFunctionsFromSpreadsheet.java
index 6432eb2f42..7552bf5af3 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestLogicalFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestLogicalFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import org.junit.runners.Parameterized.Parameters;
+import java.util.stream.Stream;
-import java.util.Collection;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests for logical ISxxx functions as loaded from a test data spreadsheet.<p>
*/
public class TestLogicalFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestLogicalFunctionsFromSpreadsheet.class, "LogicalFunctionsTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestLookupFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestLookupFunctionsFromSpreadsheet.java
index d3c27ce1d1..ad0a60ec9b 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestLookupFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestLookupFunctionsFromSpreadsheet.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests lookup functions (VLOOKUP, HLOOKUP, LOOKUP, MATCH) as loaded from a test data spreadsheet.<p>
@@ -31,8 +31,7 @@ import org.junit.runners.Parameterized.Parameters;
* more easily.
*/
public final class TestLookupFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestLookupFunctionsFromSpreadsheet.class, "LookupFunctionsTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestMatch.java b/src/testcases/org/apache/poi/ss/formula/functions/TestMatch.java
index 21ede8af66..8e172a3646 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestMatch.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMatch.java
@@ -17,8 +17,9 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+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 org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.BoolEval;
@@ -27,7 +28,7 @@ import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.NumericValueEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test cases for MATCH()
@@ -52,9 +53,7 @@ public final class TestMatch {
}
private static void confirmInt(int expected, ValueEval actualEval) {
- if(!(actualEval instanceof NumericValueEval)) {
- fail("Expected numeric result but had " + actualEval);
- }
+ assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result but had " + actualEval);
NumericValueEval nve = (NumericValueEval)actualEval;
assertEquals(expected, nve.getNumberValue(), 0);
}
@@ -283,7 +282,7 @@ public final class TestMatch {
confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
- assertEquals("Should return #REF! for invalid match type",
- ErrorEval.REF_INVALID, invokeMatch(new StringEval("Ben"), ae, MATCH_INVALID));
+ assertEquals(ErrorEval.REF_INVALID, invokeMatch(new StringEval("Ben"), ae, MATCH_INVALID),
+ "Should return #REF! for invalid match type");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java
index cff3216107..ef7ee77195 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests Match functions as loaded from a test data spreadsheet.<p>
@@ -29,8 +29,7 @@ import org.junit.runners.Parameterized.Parameters;
* more easily.
*/
public final class TestMatchFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestMatchFunctionsFromSpreadsheet.class, "MatchFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java b/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java
index 22506bd00e..a5b0a53499 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java
@@ -20,10 +20,10 @@
*/
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.poi.ss.formula.functions.XYNumericFunction.Accumulator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
@@ -37,22 +37,22 @@ public class TestMathX extends BaseTestNumeric {
double d;
d = MathX.acosh(0);
- assertTrue("Acosh 0 is NaN", Double.isNaN(d));
+ assertTrue( Double.isNaN(d), "Acosh 0 is NaN" );
d = MathX.acosh(1);
- assertEquals("Acosh 1 ", 0, d);
+ assertDouble("Acosh 1 ", 0, d);
d = MathX.acosh(-1);
- assertTrue("Acosh -1 is NaN", Double.isNaN(d));
+ assertTrue( Double.isNaN(d), "Acosh -1 is NaN" );
d = MathX.acosh(100);
- assertEquals("Acosh 100 ", 5.298292366d, d);
+ assertDouble("Acosh 100 ", 5.298292366d, d);
d = MathX.acosh(101.001);
- assertEquals("Acosh 101.001 ", 5.308253091d, d);
+ assertDouble("Acosh 101.001 ", 5.308253091d, d);
d = MathX.acosh(200000);
- assertEquals("Acosh 200000 ", 12.89921983d, d);
+ assertDouble("Acosh 200000 ", 12.89921983d, d);
}
@@ -61,25 +61,25 @@ public class TestMathX extends BaseTestNumeric {
double d;
d = MathX.asinh(0);
- assertEquals("asinh 0", d, 0);
+ assertDouble("asinh 0", d, 0);
d = MathX.asinh(1);
- assertEquals("asinh 1 ", 0.881373587, d);
+ assertDouble("asinh 1 ", 0.881373587, d);
d = MathX.asinh(-1);
- assertEquals("asinh -1 ", -0.881373587, d);
+ assertDouble("asinh -1 ", -0.881373587, d);
d = MathX.asinh(-100);
- assertEquals("asinh -100 ", -5.298342366, d);
+ assertDouble("asinh -100 ", -5.298342366, d);
d = MathX.asinh(100);
- assertEquals("asinh 100 ", 5.298342366, d);
+ assertDouble("asinh 100 ", 5.298342366, d);
d = MathX.asinh(200000);
- assertEquals("asinh 200000", 12.899219826096400, d);
+ assertDouble("asinh 200000", 12.899219826096400, d);
d = MathX.asinh(-200000);
- assertEquals("asinh -200000 ", -12.899223853137, d);
+ assertDouble("asinh -200000 ", -12.899223853137, d);
}
@@ -87,31 +87,31 @@ public class TestMathX extends BaseTestNumeric {
public void testAtanh() {
double d;
d = MathX.atanh(0);
- assertEquals("atanh 0", d, 0);
+ assertDouble("atanh 0", d, 0);
d = MathX.atanh(1);
- assertEquals("atanh 1 ", Double.POSITIVE_INFINITY, d);
+ assertDouble("atanh 1 ", Double.POSITIVE_INFINITY, d);
d = MathX.atanh(-1);
- assertEquals("atanh -1 ", Double.NEGATIVE_INFINITY, d);
+ assertDouble("atanh -1 ", Double.NEGATIVE_INFINITY, d);
d = MathX.atanh(-100);
- assertEquals("atanh -100 ", Double.NaN, d);
+ assertDouble("atanh -100 ", Double.NaN, d);
d = MathX.atanh(100);
- assertEquals("atanh 100 ", Double.NaN, d);
+ assertDouble("atanh 100 ", Double.NaN, d);
d = MathX.atanh(200000);
- assertEquals("atanh 200000", Double.NaN, d);
+ assertDouble("atanh 200000", Double.NaN, d);
d = MathX.atanh(-200000);
- assertEquals("atanh -200000 ", Double.NaN, d);
+ assertDouble("atanh -200000 ", Double.NaN, d);
d = MathX.atanh(0.1);
- assertEquals("atanh 0.1", 0.100335348, d);
+ assertDouble("atanh 0.1", 0.100335348, d);
d = MathX.atanh(-0.1);
- assertEquals("atanh -0.1 ", -0.100335348, d);
+ assertDouble("atanh -0.1 ", -0.100335348, d);
}
@@ -119,31 +119,31 @@ public class TestMathX extends BaseTestNumeric {
public void testCosh() {
double d;
d = MathX.cosh(0);
- assertEquals("cosh 0", 1, d);
+ assertDouble("cosh 0", 1, d);
d = MathX.cosh(1);
- assertEquals("cosh 1 ", 1.543080635, d);
+ assertDouble("cosh 1 ", 1.543080635, d);
d = MathX.cosh(-1);
- assertEquals("cosh -1 ", 1.543080635, d);
+ assertDouble("cosh -1 ", 1.543080635, d);
d = MathX.cosh(-100);
- assertEquals("cosh -100 ", 1.344058570908070E+43, d);
+ assertDouble("cosh -100 ", 1.344058570908070E+43, d);
d = MathX.cosh(100);
- assertEquals("cosh 100 ", 1.344058570908070E+43, d);
+ assertDouble("cosh 100 ", 1.344058570908070E+43, d);
d = MathX.cosh(15);
- assertEquals("cosh 15", 1634508.686, d);
+ assertDouble("cosh 15", 1634508.686, d);
d = MathX.cosh(-15);
- assertEquals("cosh -15 ", 1634508.686, d);
+ assertDouble("cosh -15 ", 1634508.686, d);
d = MathX.cosh(0.1);
- assertEquals("cosh 0.1", 1.005004168, d);
+ assertDouble("cosh 0.1", 1.005004168, d);
d = MathX.cosh(-0.1);
- assertEquals("cosh -0.1 ", 1.005004168, d);
+ assertDouble("cosh -0.1 ", 1.005004168, d);
}
@@ -151,31 +151,31 @@ public class TestMathX extends BaseTestNumeric {
public void testTanh() {
double d;
d = MathX.tanh(0);
- assertEquals("tanh 0", 0, d);
+ assertDouble("tanh 0", 0, d);
d = MathX.tanh(1);
- assertEquals("tanh 1 ", 0.761594156, d);
+ assertDouble("tanh 1 ", 0.761594156, d);
d = MathX.tanh(-1);
- assertEquals("tanh -1 ", -0.761594156, d);
+ assertDouble("tanh -1 ", -0.761594156, d);
d = MathX.tanh(-100);
- assertEquals("tanh -100 ", -1, d);
+ assertDouble("tanh -100 ", -1, d);
d = MathX.tanh(100);
- assertEquals("tanh 100 ", 1, d);
+ assertDouble("tanh 100 ", 1, d);
d = MathX.tanh(15);
- assertEquals("tanh 15", 1, d);
+ assertDouble("tanh 15", 1, d);
d = MathX.tanh(-15);
- assertEquals("tanh -15 ", -1, d);
+ assertDouble("tanh -15 ", -1, d);
d = MathX.tanh(0.1);
- assertEquals("tanh 0.1", 0.099667995, d);
+ assertDouble("tanh 0.1", 0.099667995, d);
d = MathX.tanh(-0.1);
- assertEquals("tanh -0.1 ", -0.099667995, d);
+ assertDouble("tanh -0.1 ", -0.099667995, d);
}
@@ -189,11 +189,11 @@ public class TestMathX extends BaseTestNumeric {
d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1;
double m = MathX.max(d);
- assertEquals("Max ", 20.1, m);
+ assertDouble("Max ", 20.1, m);
d = new double[1000];
m = MathX.max(d);
- assertEquals("Max ", 0, m);
+ assertDouble("Max ", 0, m);
d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1;
d[4] = -5.1; d[5] = 6.1; d[6] = -7.1; d[7] = 8.1;
@@ -201,7 +201,7 @@ public class TestMathX extends BaseTestNumeric {
d[12] = -13.1; d[13] = 14.1; d[14] = -15.1; d[15] = 16.1;
d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1;
m = MathX.max(d);
- assertEquals("Max ", 20.1, m);
+ assertDouble("Max ", 20.1, m);
d = new double[20];
d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1;
@@ -210,7 +210,7 @@ public class TestMathX extends BaseTestNumeric {
d[12] = -13.1; d[13] = -14.1; d[14] = -15.1; d[15] = -16.1;
d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1;
m = MathX.max(d);
- assertEquals("Max ", -1.1, m);
+ assertDouble("Max ", -1.1, m);
}
@@ -224,7 +224,7 @@ public class TestMathX extends BaseTestNumeric {
d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1;
double m = MathX.min(d);
- assertEquals("Min ", 0, m);
+ assertDouble("Min ", 0, m);
d = new double[20];
d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1;
@@ -234,11 +234,11 @@ public class TestMathX extends BaseTestNumeric {
d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1;
m = MathX.min(d);
- assertEquals("Min ", 1.1, m);
+ assertDouble("Min ", 1.1, m);
d = new double[1000];
m = MathX.min(d);
- assertEquals("Min ", 0, m);
+ assertDouble("Min ", 0, m);
d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1;
d[4] = -5.1; d[5] = 6.1; d[6] = -7.1; d[7] = 8.1;
@@ -246,7 +246,7 @@ public class TestMathX extends BaseTestNumeric {
d[12] = -13.1; d[13] = 14.1; d[14] = -15.1; d[15] = 16.1;
d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1;
m = MathX.min(d);
- assertEquals("Min ", -19.1, m);
+ assertDouble("Min ", -19.1, m);
d = new double[20];
d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1;
@@ -255,20 +255,20 @@ public class TestMathX extends BaseTestNumeric {
d[12] = -13.1; d[13] = -14.1; d[14] = -15.1; d[15] = -16.1;
d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1;
m = MathX.min(d);
- assertEquals("Min ", -20.1, m);
+ assertDouble("Min ", -20.1, m);
}
@Test
public void testProduct() {
- assertEquals("Product ", 0, MathX.product(null));
- assertEquals("Product ", 0, MathX.product(new double[] {}));
- assertEquals("Product ", 0, MathX.product(new double[] {1, 0}));
+ assertDouble("Product ", 0, MathX.product(null));
+ assertDouble("Product ", 0, MathX.product(new double[] {}));
+ assertDouble("Product ", 0, MathX.product(new double[] {1, 0}));
- assertEquals("Product ", 1, MathX.product(new double[] { 1 }));
- assertEquals("Product ", 1, MathX.product(new double[] { 1, 1 }));
- assertEquals("Product ", 10, MathX.product(new double[] { 10, 1 }));
- assertEquals("Product ", -2, MathX.product(new double[] { 2, -1 }));
- assertEquals("Product ", 99988000209999d, MathX.product(new double[] { 99999, 99999, 9999 }));
+ assertDouble("Product ", 1, MathX.product(new double[] { 1 }));
+ assertDouble("Product ", 1, MathX.product(new double[] { 1, 1 }));
+ assertDouble("Product ", 10, MathX.product(new double[] { 10, 1 }));
+ assertDouble("Product ", -2, MathX.product(new double[] { 2, -1 }));
+ assertDouble("Product ", 99988000209999d, MathX.product(new double[] { 99999, 99999, 9999 }));
double[] d = new double[100];
d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1;
@@ -278,7 +278,7 @@ public class TestMathX extends BaseTestNumeric {
d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1;
double m = MathX.product(d);
- assertEquals("Product ", 0, m);
+ assertDouble("Product ", 0, m);
d = new double[20];
d[0] = 1.1; d[1] = 2.1; d[2] = 3.1; d[3] = 4.1;
@@ -288,11 +288,11 @@ public class TestMathX extends BaseTestNumeric {
d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1;
m = MathX.product(d);
- assertEquals("Product ", 3459946360003355534d, m);
+ assertDouble("Product ", 3459946360003355534d, m);
d = new double[1000];
m = MathX.product(d);
- assertEquals("Product ", 0, m);
+ assertDouble("Product ", 0, m);
d = new double[20];
d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1;
@@ -301,29 +301,29 @@ public class TestMathX extends BaseTestNumeric {
d[12] = -13.1; d[13] = -14.1; d[14] = -15.1; d[15] = -16.1;
d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1;
m = MathX.product(d);
- assertEquals("Product ", 3459946360003355534d, m);
+ assertDouble("Product ", 3459946360003355534d, m);
}
@Test
public void testMod() {
//example from Excel help
- assertEquals(1.0, MathX.mod(3, 2));
- assertEquals(1.0, MathX.mod(-3, 2));
- assertEquals(-1.0, MathX.mod(3, -2));
- assertEquals(-1.0, MathX.mod(-3, -2));
-
- assertEquals(0.0, MathX.mod(0, 2));
- assertEquals(Double.NaN, MathX.mod(3, 0));
- assertEquals(1.4, MathX.mod(3.4, 2));
- assertEquals(-1.4, MathX.mod(-3.4, -2));
- assertEquals(0.6000000000000001, MathX.mod(-3.4, 2.0));// should actually be 0.6
- assertEquals(-0.6000000000000001, MathX.mod(3.4, -2.0));// should actually be -0.6
- assertEquals(3.0, MathX.mod(3, Double.MAX_VALUE));
- assertEquals(2.0, MathX.mod(Double.MAX_VALUE, 3));
+ assertDouble(1.0, MathX.mod(3, 2));
+ assertDouble(1.0, MathX.mod(-3, 2));
+ assertDouble(-1.0, MathX.mod(3, -2));
+ assertDouble(-1.0, MathX.mod(-3, -2));
+
+ assertDouble(0.0, MathX.mod(0, 2));
+ assertDouble(Double.NaN, MathX.mod(3, 0));
+ assertDouble(1.4, MathX.mod(3.4, 2));
+ assertDouble(-1.4, MathX.mod(-3.4, -2));
+ assertDouble(0.6000000000000001, MathX.mod(-3.4, 2.0));// should actually be 0.6
+ assertDouble(-0.6000000000000001, MathX.mod(3.4, -2.0));// should actually be -0.6
+ assertDouble(3.0, MathX.mod(3, Double.MAX_VALUE));
+ assertDouble(2.0, MathX.mod(Double.MAX_VALUE, 3));
// Bugzilla 50033
- assertEquals(1.0, MathX.mod(13, 12));
+ assertDouble(1.0, MathX.mod(13, 12));
}
@Test
@@ -331,47 +331,47 @@ public class TestMathX extends BaseTestNumeric {
int n=100;
int k=50;
double d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", 1.00891344545564E29, d);
+ assertDouble("NChooseK ", 1.00891344545564E29, d);
n = -1; k = 1;
d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", Double.NaN, d);
+ assertDouble("NChooseK ", Double.NaN, d);
n = 1; k = -1;
d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", Double.NaN, d);
+ assertDouble("NChooseK ", Double.NaN, d);
n = 0; k = 1;
d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", Double.NaN, d);
+ assertDouble("NChooseK ", Double.NaN, d);
n = 1; k = 0;
d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", 1, d);
+ assertDouble("NChooseK ", 1, d);
n = 10; k = 9;
d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", 10, d);
+ assertDouble("NChooseK ", 10, d);
n = 10; k = 10;
d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", 1, d);
+ assertDouble("NChooseK ", 1, d);
n = 10; k = 1;
d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", 10, d);
+ assertDouble("NChooseK ", 10, d);
n = 1000; k = 1;
d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", 1000, d); // awesome ;)
+ assertDouble("NChooseK ", 1000, d); // awesome ;)
n = 1000; k = 2;
d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", 499500, d); // awesome ;)
+ assertDouble("NChooseK ", 499500, d); // awesome ;)
n = 13; k = 7;
d = MathX.nChooseK(n, k);
- assertEquals("NChooseK ", 1716, d);
+ assertDouble("NChooseK ", 1716, d);
}
@@ -383,48 +383,48 @@ public class TestMathX extends BaseTestNumeric {
double d;
- assertEquals("Sign ", minus, MathX.sign(minus));
- assertEquals("Sign ", plus, MathX.sign(plus));
- assertEquals("Sign ", zero, MathX.sign(zero));
+ assertDouble("Sign ", minus, MathX.sign(minus));
+ assertDouble("Sign ", plus, MathX.sign(plus));
+ assertDouble("Sign ", zero, MathX.sign(zero));
d = 0;
- assertEquals("Sign ", zero, MathX.sign(d));
+ assertDouble("Sign ", zero, MathX.sign(d));
d = -1.000001;
- assertEquals("Sign ", minus, MathX.sign(d));
+ assertDouble("Sign ", minus, MathX.sign(d));
d = -.000001;
- assertEquals("Sign ", minus, MathX.sign(d));
+ assertDouble("Sign ", minus, MathX.sign(d));
d = -1E-200;
- assertEquals("Sign ", minus, MathX.sign(d));
+ assertDouble("Sign ", minus, MathX.sign(d));
d = Double.NEGATIVE_INFINITY;
- assertEquals("Sign ", minus, MathX.sign(d));
+ assertDouble("Sign ", minus, MathX.sign(d));
d = -200.11;
- assertEquals("Sign ", minus, MathX.sign(d));
+ assertDouble("Sign ", minus, MathX.sign(d));
d = -2000000000000.11;
- assertEquals("Sign ", minus, MathX.sign(d));
+ assertDouble("Sign ", minus, MathX.sign(d));
d = 1.000001;
- assertEquals("Sign ", plus, MathX.sign(d));
+ assertDouble("Sign ", plus, MathX.sign(d));
d = .000001;
- assertEquals("Sign ", plus, MathX.sign(d));
+ assertDouble("Sign ", plus, MathX.sign(d));
d = 1E-200;
- assertEquals("Sign ", plus, MathX.sign(d));
+ assertDouble("Sign ", plus, MathX.sign(d));
d = Double.POSITIVE_INFINITY;
- assertEquals("Sign ", plus, MathX.sign(d));
+ assertDouble("Sign ", plus, MathX.sign(d));
d = 200.11;
- assertEquals("Sign ", plus, MathX.sign(d));
+ assertDouble("Sign ", plus, MathX.sign(d));
d = 2000000000000.11;
- assertEquals("Sign ", plus, MathX.sign(d));
+ assertDouble("Sign ", plus, MathX.sign(d));
}
@@ -432,31 +432,31 @@ public class TestMathX extends BaseTestNumeric {
public void testSinh() {
double d;
d = MathX.sinh(0);
- assertEquals("sinh 0", 0, d);
+ assertDouble("sinh 0", 0, d);
d = MathX.sinh(1);
- assertEquals("sinh 1 ", 1.175201194, d);
+ assertDouble("sinh 1 ", 1.175201194, d);
d = MathX.sinh(-1);
- assertEquals("sinh -1 ", -1.175201194, d);
+ assertDouble("sinh -1 ", -1.175201194, d);
d = MathX.sinh(-100);
- assertEquals("sinh -100 ", -1.344058570908070E+43, d);
+ assertDouble("sinh -100 ", -1.344058570908070E+43, d);
d = MathX.sinh(100);
- assertEquals("sinh 100 ", 1.344058570908070E+43, d);
+ assertDouble("sinh 100 ", 1.344058570908070E+43, d);
d = MathX.sinh(15);
- assertEquals("sinh 15", 1634508.686, d);
+ assertDouble("sinh 15", 1634508.686, d);
d = MathX.sinh(-15);
- assertEquals("sinh -15 ", -1634508.686, d);
+ assertDouble("sinh -15 ", -1634508.686, d);
d = MathX.sinh(0.1);
- assertEquals("sinh 0.1", 0.10016675, d);
+ assertDouble("sinh 0.1", 0.10016675, d);
d = MathX.sinh(-0.1);
- assertEquals("sinh -0.1 ", -0.10016675, d);
+ assertDouble("sinh -0.1 ", -0.10016675, d);
}
@@ -470,11 +470,11 @@ public class TestMathX extends BaseTestNumeric {
d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1;
double s = MathX.sum(d);
- assertEquals("Sum ", 212, s);
+ assertDouble("Sum ", 212, s);
d = new double[1000];
s = MathX.sum(d);
- assertEquals("Sum ", 0, s);
+ assertDouble("Sum ", 0, s);
d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1;
d[4] = -5.1; d[5] = 6.1; d[6] = -7.1; d[7] = 8.1;
@@ -482,7 +482,7 @@ public class TestMathX extends BaseTestNumeric {
d[12] = -13.1; d[13] = 14.1; d[14] = -15.1; d[15] = 16.1;
d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1;
s = MathX.sum(d);
- assertEquals("Sum ", 10, s);
+ assertDouble("Sum ", 10, s);
d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1;
d[4] = -5.1; d[5] = -6.1; d[6] = -7.1; d[7] = -8.1;
@@ -490,7 +490,7 @@ public class TestMathX extends BaseTestNumeric {
d[12] = -13.1; d[13] = -14.1; d[14] = -15.1; d[15] = -16.1;
d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1;
s = MathX.sum(d);
- assertEquals("Sum ", -212, s);
+ assertDouble("Sum ", -212, s);
}
@@ -504,11 +504,11 @@ public class TestMathX extends BaseTestNumeric {
d[16] = 17.1; d[17] = 18.1; d[18] = 19.1; d[19] = 20.1;
double s = MathX.sumsq(d);
- assertEquals("Sumsq ", 2912.2, s);
+ assertDouble("Sumsq ", 2912.2, s);
d = new double[1000];
s = MathX.sumsq(d);
- assertEquals("Sumsq ", 0, s);
+ assertDouble("Sumsq ", 0, s);
d[0] = -1.1; d[1] = 2.1; d[2] = -3.1; d[3] = 4.1;
d[4] = -5.1; d[5] = 6.1; d[6] = -7.1; d[7] = 8.1;
@@ -516,7 +516,7 @@ public class TestMathX extends BaseTestNumeric {
d[12] = -13.1; d[13] = 14.1; d[14] = -15.1; d[15] = 16.1;
d[16] = -17.1; d[17] = 18.1; d[18] = -19.1; d[19] = 20.1;
s = MathX.sumsq(d);
- assertEquals("Sumsq ", 2912.2, s);
+ assertDouble("Sumsq ", 2912.2, s);
d[0] = -1.1; d[1] = -2.1; d[2] = -3.1; d[3] = -4.1;
d[4] = -5.1; d[5] = -6.1; d[6] = -7.1; d[7] = -8.1;
@@ -524,7 +524,7 @@ public class TestMathX extends BaseTestNumeric {
d[12] = -13.1; d[13] = -14.1; d[14] = -15.1; d[15] = -16.1;
d[16] = -17.1; d[17] = -18.1; d[18] = -19.1; d[19] = -20.1;
s = MathX.sumsq(d);
- assertEquals("Sumsq ", 2912.2, s);
+ assertDouble("Sumsq ", 2912.2, s);
}
@Test
@@ -534,27 +534,27 @@ public class TestMathX extends BaseTestNumeric {
n = 0;
s = MathX.factorial(n);
- assertEquals("Factorial ", 1, s);
+ assertDouble("Factorial ", 1, s);
n = 1;
s = MathX.factorial(n);
- assertEquals("Factorial ", 1, s);
+ assertDouble("Factorial ", 1, s);
n = 10;
s = MathX.factorial(n);
- assertEquals("Factorial ", 3628800, s);
+ assertDouble("Factorial ", 3628800, s);
n = 99;
s = MathX.factorial(n);
- assertEquals("Factorial ", 9.33262154439E+155, s);
+ assertDouble("Factorial ", 9.33262154439E+155, s);
n = -1;
s = MathX.factorial(n);
- assertEquals("Factorial ", Double.NaN, s);
+ assertDouble("Factorial ", Double.NaN, s);
n = Integer.MAX_VALUE;
s = MathX.factorial(n);
- assertEquals("Factorial ", Double.POSITIVE_INFINITY, s);
+ assertDouble("Factorial ", Double.POSITIVE_INFINITY, s);
}
@Test
@@ -651,7 +651,7 @@ public class TestMathX extends BaseTestNumeric {
for (int i = 0; i < xarr.length; i++) {
result += acc.accumulate(xarr[i], yarr[i]);
}
- assertEquals(expectedResult, result);
+ assertDouble(expectedResult, result);
}
@Test
@@ -660,70 +660,70 @@ public class TestMathX extends BaseTestNumeric {
int p;
d = 0; p = 0;
- assertEquals("round ", 0, MathX.round(d, p));
+ assertDouble("round ", 0, MathX.round(d, p));
d = 10; p = 0;
- assertEquals("round ", 10, MathX.round(d, p));
+ assertDouble("round ", 10, MathX.round(d, p));
d = 123.23; p = 0;
- assertEquals("round ", 123, MathX.round(d, p));
+ assertDouble("round ", 123, MathX.round(d, p));
d = -123.23; p = 0;
- assertEquals("round ", -123, MathX.round(d, p));
+ assertDouble("round ", -123, MathX.round(d, p));
d = 123.12; p = 2;
- assertEquals("round ", 123.12, MathX.round(d, p));
+ assertDouble("round ", 123.12, MathX.round(d, p));
d = 88.123459; p = 5;
- assertEquals("round ", 88.12346, MathX.round(d, p));
+ assertDouble("round ", 88.12346, MathX.round(d, p));
d = 0; p = 2;
- assertEquals("round ", 0, MathX.round(d, p));
+ assertDouble("round ", 0, MathX.round(d, p));
d = 0; p = -1;
- assertEquals("round ", 0, MathX.round(d, p));
+ assertDouble("round ", 0, MathX.round(d, p));
d = 0.01; p = -1;
- assertEquals("round ", 0, MathX.round(d, p));
+ assertDouble("round ", 0, MathX.round(d, p));
d = 123.12; p = -2;
- assertEquals("round ", 100, MathX.round(d, p));
+ assertDouble("round ", 100, MathX.round(d, p));
d = 88.123459; p = -3;
- assertEquals("round ", 0, MathX.round(d, p));
+ assertDouble("round ", 0, MathX.round(d, p));
d = 49.00000001; p = -1;
- assertEquals("round ", 50, MathX.round(d, p));
+ assertDouble("round ", 50, MathX.round(d, p));
d = 149.999999; p = -2;
- assertEquals("round ", 100, MathX.round(d, p));
+ assertDouble("round ", 100, MathX.round(d, p));
d = 150.0; p = -2;
- assertEquals("round ", 200, MathX.round(d, p));
+ assertDouble("round ", 200, MathX.round(d, p));
d = 2162.615d; p = 2;
- assertEquals("round ", 2162.62d, MathX.round(d, p));
+ assertDouble("round ", 2162.62d, MathX.round(d, p));
d = 0.049999999999999975d; p = 2;
- assertEquals("round ", 0.05d, MathX.round(d, p));
+ assertDouble("round ", 0.05d, MathX.round(d, p));
d = 0.049999999999999975d; p = 1;
- assertEquals("round ", 0.1d, MathX.round(d, p));
+ assertDouble("round ", 0.1d, MathX.round(d, p));
d = Double.NaN; p = 1;
- assertEquals("round ", Double.NaN, MathX.round(d, p));
+ assertDouble("round ", Double.NaN, MathX.round(d, p));
d = Double.POSITIVE_INFINITY; p = 1;
- assertEquals("round ", Double.NaN, MathX.round(d, p));
+ assertDouble("round ", Double.NaN, MathX.round(d, p));
d = Double.NEGATIVE_INFINITY; p = 1;
- assertEquals("round ", Double.NaN, MathX.round(d, p));
+ assertDouble("round ", Double.NaN, MathX.round(d, p));
d = Double.MAX_VALUE; p = 1;
- assertEquals("round ", Double.MAX_VALUE, MathX.round(d, p));
+ assertDouble("round ", Double.MAX_VALUE, MathX.round(d, p));
d = Double.MIN_VALUE; p = 1;
- assertEquals("round ", 0.0d, MathX.round(d, p));
+ assertDouble("round ", 0.0d, MathX.round(d, p));
}
@Test
@@ -732,70 +732,70 @@ public class TestMathX extends BaseTestNumeric {
int p;
d = 0; p = 0;
- assertEquals("roundDown ", 0, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 0, MathX.roundDown(d, p));
d = 10; p = 0;
- assertEquals("roundDown ", 10, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 10, MathX.roundDown(d, p));
d = 123.99; p = 0;
- assertEquals("roundDown ", 123, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 123, MathX.roundDown(d, p));
d = -123.99; p = 0;
- assertEquals("roundDown ", -123, MathX.roundDown(d, p));
+ assertDouble("roundDown ", -123, MathX.roundDown(d, p));
d = 123.99; p = 2;
- assertEquals("roundDown ", 123.99, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 123.99, MathX.roundDown(d, p));
d = 88.123459; p = 5;
- assertEquals("roundDown ", 88.12345, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 88.12345, MathX.roundDown(d, p));
d = 0; p = 2;
- assertEquals("roundDown ", 0, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 0, MathX.roundDown(d, p));
d = 0; p = -1;
- assertEquals("roundDown ", 0, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 0, MathX.roundDown(d, p));
d = 0.01; p = -1;
- assertEquals("roundDown ", 0, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 0, MathX.roundDown(d, p));
d = 199.12; p = -2;
- assertEquals("roundDown ", 100, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 100, MathX.roundDown(d, p));
d = 88.123459; p = -3;
- assertEquals("roundDown ", 0, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 0, MathX.roundDown(d, p));
d = 99.00000001; p = -1;
- assertEquals("roundDown ", 90, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 90, MathX.roundDown(d, p));
d = 100.00001; p = -2;
- assertEquals("roundDown ", 100, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 100, MathX.roundDown(d, p));
d = 150.0; p = -2;
- assertEquals("roundDown ", 100, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 100, MathX.roundDown(d, p));
d = 0.0499999999999975d; p = 2;
- assertEquals("roundDown ", 0.04d, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 0.04d, MathX.roundDown(d, p));
d = 0.049999999999999975d; p = 1;
- assertEquals("roundDown ", 0.0d, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 0.0d, MathX.roundDown(d, p));
d = Double.NaN; p = 1;
- assertEquals("roundDown ", Double.NaN, MathX.roundDown(d, p));
+ assertDouble("roundDown ", Double.NaN, MathX.roundDown(d, p));
d = Double.POSITIVE_INFINITY; p = 1;
- assertEquals("roundDown ", Double.NaN, MathX.roundDown(d, p));
+ assertDouble("roundDown ", Double.NaN, MathX.roundDown(d, p));
d = Double.NEGATIVE_INFINITY; p = 1;
- assertEquals("roundDown ", Double.NaN, MathX.roundDown(d, p));
+ assertDouble("roundDown ", Double.NaN, MathX.roundDown(d, p));
d = Double.MAX_VALUE; p = 1;
- assertEquals("roundDown ", Double.MAX_VALUE, MathX.roundDown(d, p));
+ assertDouble("roundDown ", Double.MAX_VALUE, MathX.roundDown(d, p));
d = Double.MIN_VALUE; p = 1;
- assertEquals("roundDown ", 0.0d, MathX.roundDown(d, p));
+ assertDouble("roundDown ", 0.0d, MathX.roundDown(d, p));
d = 3987 * 0.2; p = 2;
- assertEquals("roundDown ", 797.40, MathX.round(d, p));
+ assertDouble("roundDown ", 797.40, MathX.round(d, p));
}
@Test
@@ -804,75 +804,75 @@ public class TestMathX extends BaseTestNumeric {
int p;
d = 0; p = 0;
- assertEquals("roundUp ", 0, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 0, MathX.roundUp(d, p));
d = 10; p = 0;
- assertEquals("roundUp ", 10, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 10, MathX.roundUp(d, p));
d = 123.23; p = 0;
- assertEquals("roundUp ", 124, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 124, MathX.roundUp(d, p));
d = -123.23; p = 0;
- assertEquals("roundUp ", -124, MathX.roundUp(d, p));
+ assertDouble("roundUp ", -124, MathX.roundUp(d, p));
d = 123.12; p = 2;
- assertEquals("roundUp ", 123.12, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 123.12, MathX.roundUp(d, p));
d = 88.123459; p = 5;
- assertEquals("roundUp ", 88.12346, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 88.12346, MathX.roundUp(d, p));
d = 0; p = 2;
- assertEquals("roundUp ", 0, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 0, MathX.roundUp(d, p));
d = 0; p = -1;
- assertEquals("roundUp ", 0, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 0, MathX.roundUp(d, p));
d = 0.01; p = -1;
- assertEquals("roundUp ", 10, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 10, MathX.roundUp(d, p));
d = 123.12; p = -2;
- assertEquals("roundUp ", 200, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 200, MathX.roundUp(d, p));
d = 88.123459; p = -3;
- assertEquals("roundUp ", 1000, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 1000, MathX.roundUp(d, p));
d = 49.00000001; p = -1;
- assertEquals("roundUp ", 50, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 50, MathX.roundUp(d, p));
d = 149.999999; p = -2;
- assertEquals("roundUp ", 200, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 200, MathX.roundUp(d, p));
d = 150.0; p = -2;
- assertEquals("roundUp ", 200, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 200, MathX.roundUp(d, p));
d = 0.049999999999999975d; p = 2;
- assertEquals("roundUp ", 0.05d, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 0.05d, MathX.roundUp(d, p));
d = 0.049999999999999975d; p = 1;
- assertEquals("roundUp ", 0.1d, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 0.1d, MathX.roundUp(d, p));
d = Double.NaN; p = 1;
- assertEquals("roundUp ", Double.NaN, MathX.roundUp(d, p));
+ assertDouble("roundUp ", Double.NaN, MathX.roundUp(d, p));
d = Double.POSITIVE_INFINITY; p = 1;
- assertEquals("roundUp ", Double.NaN, MathX.roundUp(d, p));
+ assertDouble("roundUp ", Double.NaN, MathX.roundUp(d, p));
d = Double.NEGATIVE_INFINITY; p = 1;
- assertEquals("roundUp ", Double.NaN, MathX.roundUp(d, p));
+ assertDouble("roundUp ", Double.NaN, MathX.roundUp(d, p));
d = Double.MAX_VALUE; p = 1;
- assertEquals("roundUp ", Double.MAX_VALUE, MathX.roundUp(d, p));
+ assertDouble("roundUp ", Double.MAX_VALUE, MathX.roundUp(d, p));
// Excel's min positive value is several orders of magnitude larger than Java's (Java 8: 4.9e-324, Excel 2016 on Windows 10: 2.2259157957E-308)
d = Double.MIN_VALUE; p = 1;
- assertEquals("roundUp ", 0.0d, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 0.0d, MathX.roundUp(d, p));
d = 2.2259157957E-308; p = 1;
- assertEquals("roundUp ", 0.1d, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 0.1d, MathX.roundUp(d, p));
//github-43: https://github.com/apache/poi/pull/43
// "ROUNDUP(3987*0.2, 2) currently fails by returning 797.41")
d = 3987 * 0.2; p = 2;
- assertEquals("roundUp ", 797.40, MathX.roundUp(d, p));
+ assertDouble("roundUp ", 797.40, MathX.roundUp(d, p));
}
@Test
@@ -881,84 +881,84 @@ public class TestMathX extends BaseTestNumeric {
double s;
d = 0; s = 0;
- assertEquals("ceiling ", 0, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 0, MathX.ceiling(d, s));
d = 1; s = 0;
- assertEquals("ceiling ", 0, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 0, MathX.ceiling(d, s));
d = 0; s = 1;
- assertEquals("ceiling ", 0, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 0, MathX.ceiling(d, s));
d = -1; s = 0;
- assertEquals("ceiling ", 0, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 0, MathX.ceiling(d, s));
d = 0; s = -1;
- assertEquals("ceiling ", 0, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 0, MathX.ceiling(d, s));
d = 10; s = 1.11;
- assertEquals("ceiling ", 11.1, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 11.1, MathX.ceiling(d, s));
d = 11.12333; s = 0.03499;
- assertEquals("ceiling ", 11.12682, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 11.12682, MathX.ceiling(d, s));
d = -11.12333; s = 0.03499;
- assertEquals("ceiling ", Double.NaN, MathX.ceiling(d, s));
+ assertDouble("ceiling ", Double.NaN, MathX.ceiling(d, s));
d = 11.12333; s = -0.03499;
- assertEquals("ceiling ", Double.NaN, MathX.ceiling(d, s));
+ assertDouble("ceiling ", Double.NaN, MathX.ceiling(d, s));
d = -11.12333; s = -0.03499;
- assertEquals("ceiling ", -11.12682, MathX.ceiling(d, s));
+ assertDouble("ceiling ", -11.12682, MathX.ceiling(d, s));
d = 100; s = 0.001;
- assertEquals("ceiling ", 100, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 100, MathX.ceiling(d, s));
d = -0.001; s = -9.99;
- assertEquals("ceiling ", -9.99, MathX.ceiling(d, s));
+ assertDouble("ceiling ", -9.99, MathX.ceiling(d, s));
d = 4.42; s = 0.05;
- assertEquals("ceiling ", 4.45, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 4.45, MathX.ceiling(d, s));
d = 0.05; s = 4.42;
- assertEquals("ceiling ", 4.42, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 4.42, MathX.ceiling(d, s));
d = 0.6666; s = 3.33;
- assertEquals("ceiling ", 3.33, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 3.33, MathX.ceiling(d, s));
d = 2d/3; s = 3.33;
- assertEquals("ceiling ", 3.33, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 3.33, MathX.ceiling(d, s));
// samples from http://www.excelfunctions.net/Excel-Ceiling-Function.html
// and https://support.office.com/en-us/article/CEILING-function-0a5cd7c8-0720-4f0a-bd2c-c943e510899f
d = 22.25; s = 0.1;
- assertEquals("ceiling ", 22.3, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 22.3, MathX.ceiling(d, s));
d = 22.25; s = 0.5;
- assertEquals("ceiling ", 22.5, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 22.5, MathX.ceiling(d, s));
d = 22.25; s = 1;
- assertEquals("ceiling ", 23, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 23, MathX.ceiling(d, s));
d = 22.25; s = 10;
- assertEquals("ceiling ", 30, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 30, MathX.ceiling(d, s));
d = 22.25; s = 20;
- assertEquals("ceiling ", 40, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 40, MathX.ceiling(d, s));
d = -22.25; s = -0.1;
- assertEquals("ceiling ", -22.3, MathX.ceiling(d, s));
+ assertDouble("ceiling ", -22.3, MathX.ceiling(d, s));
d = -22.25; s = -1;
- assertEquals("ceiling ", -23, MathX.ceiling(d, s));
+ assertDouble("ceiling ", -23, MathX.ceiling(d, s));
d = -22.25; s = -5;
- assertEquals("ceiling ", -25, MathX.ceiling(d, s));
+ assertDouble("ceiling ", -25, MathX.ceiling(d, s));
d = 22.25; s = 1;
- assertEquals("ceiling ", 23, MathX.ceiling(d, s));
+ assertDouble("ceiling ", 23, MathX.ceiling(d, s));
d = 22.25; s = -1;
- assertEquals("ceiling ", Double.NaN, MathX.ceiling(d, s));
+ assertDouble("ceiling ", Double.NaN, MathX.ceiling(d, s));
d = -22.25; s = 1;
- assertEquals("ceiling ", -22, MathX.ceiling(d, s)); // returns an error in Excel 2007 & earlier
+ assertDouble("ceiling ", -22, MathX.ceiling(d, s)); // returns an error in Excel 2007 & earlier
d = -22.25; s = -1;
- assertEquals("ceiling ", -23, MathX.ceiling(d, s));
+ assertDouble("ceiling ", -23, MathX.ceiling(d, s));
// test cases for newer versions of Excel where d can be negative for
d = -11.12333; s = 0.03499;
- assertEquals("ceiling ", -11.09183, MathX.ceiling(d, s));
+ assertDouble("ceiling ", -11.09183, MathX.ceiling(d, s));
}
@Test
@@ -967,69 +967,69 @@ public class TestMathX extends BaseTestNumeric {
double s;
d = 0; s = 0;
- assertEquals("floor ", 0, MathX.floor(d, s));
+ assertDouble("floor ", 0, MathX.floor(d, s));
d = 1; s = 0;
- assertEquals("floor ", Double.NaN, MathX.floor(d, s));
+ assertDouble("floor ", Double.NaN, MathX.floor(d, s));
d = 0; s = 1;
- assertEquals("floor ", 0, MathX.floor(d, s));
+ assertDouble("floor ", 0, MathX.floor(d, s));
d = -1; s = 0;
- assertEquals("floor ", Double.NaN, MathX.floor(d, s));
+ assertDouble("floor ", Double.NaN, MathX.floor(d, s));
d = 0; s = -1;
- assertEquals("floor ", 0, MathX.floor(d, s));
+ assertDouble("floor ", 0, MathX.floor(d, s));
d = 10; s = 1.11;
- assertEquals("floor ", 9.99, MathX.floor(d, s));
+ assertDouble("floor ", 9.99, MathX.floor(d, s));
d = 11.12333; s = 0.03499;
- assertEquals("floor ", 11.09183, MathX.floor(d, s));
+ assertDouble("floor ", 11.09183, MathX.floor(d, s));
d = -11.12333; s = 0.03499;
- assertEquals("floor ", Double.NaN, MathX.floor(d, s));
+ assertDouble("floor ", Double.NaN, MathX.floor(d, s));
d = 11.12333; s = -0.03499;
- assertEquals("floor ", Double.NaN, MathX.floor(d, s));
+ assertDouble("floor ", Double.NaN, MathX.floor(d, s));
d = -11.12333; s = -0.03499;
- assertEquals("floor ", -11.09183, MathX.floor(d, s));
+ assertDouble("floor ", -11.09183, MathX.floor(d, s));
d = 100; s = 0.001;
- assertEquals("floor ", 100, MathX.floor(d, s));
+ assertDouble("floor ", 100, MathX.floor(d, s));
d = -0.001; s = -9.99;
- assertEquals("floor ", 0, MathX.floor(d, s));
+ assertDouble("floor ", 0, MathX.floor(d, s));
d = 4.42; s = 0.05;
- assertEquals("floor ", 4.4, MathX.floor(d, s));
+ assertDouble("floor ", 4.4, MathX.floor(d, s));
d = 0.05; s = 4.42;
- assertEquals("floor ", 0, MathX.floor(d, s));
+ assertDouble("floor ", 0, MathX.floor(d, s));
d = 0.6666; s = 3.33;
- assertEquals("floor ", 0, MathX.floor(d, s));
+ assertDouble("floor ", 0, MathX.floor(d, s));
d = 2d/3; s = 3.33;
- assertEquals("floor ", 0, MathX.floor(d, s));
+ assertDouble("floor ", 0, MathX.floor(d, s));
// samples from http://www.excelfunctions.net/Excel-Ceiling-Function.html
// and https://support.office.com/en-us/article/CEILING-function-0a5cd7c8-0720-4f0a-bd2c-c943e510899f
d = 3.7; s = 2;
- assertEquals("floor ", 2, MathX.floor(d, s));
+ assertDouble("floor ", 2, MathX.floor(d, s));
d = -2.5; s = -2;
- assertEquals("floor ", -2, MathX.floor(d, s));
+ assertDouble("floor ", -2, MathX.floor(d, s));
d = 2.5; s = -2;
- assertEquals("floor ", Double.NaN, MathX.floor(d, s));
+ assertDouble("floor ", Double.NaN, MathX.floor(d, s));
d = 1.58; s = 0.1;
- assertEquals("floor ", 1.5, MathX.floor(d, s));
+ assertDouble("floor ", 1.5, MathX.floor(d, s));
d = 0.234; s = 0.01;
- assertEquals("floor ", 0.23, MathX.floor(d, s));
+ assertDouble("floor ", 0.23, MathX.floor(d, s));
// see bug 62839
d = -123;
s = 10;
- assertEquals("floor ", -130, MathX.floor(d, s));
+ assertDouble("floor ", -130, MathX.floor(d, s));
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestMid.java b/src/testcases/org/apache/poi/ss/formula/functions/TestMid.java
index e141eff915..e1641528c3 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestMid.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMid.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-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;
@@ -27,7 +27,7 @@ import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.RefEval;
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;
/**
* Tests for Excel function MID()
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 5a5d123fff..9eabaa44a6 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMirr.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFCell;
@@ -30,7 +30,7 @@ import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
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 {@link org.apache.poi.ss.formula.functions.Mirr}
@@ -51,28 +51,28 @@ public final class TestMirr {
double[] values = {-120000d, 39000d, 30000d, 21000d, 37000d, 46000d, reinvestRate, financeRate};
// MIRR should not failed with these parameters
mirrValue = mirr.evaluate(values);
- assertEquals("mirr", 0.126094130366, mirrValue, 0.0000000001);
+ assertEquals(0.126094130366, mirrValue, 0.0000000001);
reinvestRate = 0.05;
financeRate = 0.08;
values = new double[]{-7500d, 3000d, 5000d, 1200d, 4000d, reinvestRate, financeRate};
// MIRR should not failed with these parameters
mirrValue = mirr.evaluate(values);
- assertEquals("mirr", 0.18736225093, mirrValue, 0.0000000001);
+ assertEquals(0.18736225093, mirrValue, 0.0000000001);
reinvestRate = 0.065;
financeRate = 0.1;
values = new double[]{-10000, 3400d, 6500d, 1000d, reinvestRate, financeRate};
// MIRR should not failed with these parameters
mirrValue = mirr.evaluate(values);
- assertEquals("mirr", 0.07039493966, mirrValue, 0.0000000001);
+ assertEquals(0.07039493966, mirrValue, 0.0000000001);
reinvestRate = 0.07;
financeRate = 0.01;
values = new double[]{-10000d, -3400d, -6500d, -1000d, reinvestRate, financeRate};
// MIRR should not failed with these parameters
mirrValue = mirr.evaluate(values);
- assertEquals("mirr", -1, mirrValue, 0.0);
+ assertEquals(-1, mirrValue, 0.0);
}
@@ -83,13 +83,9 @@ public final class TestMirr {
double reinvestRate = 0.05;
double financeRate = 0.08;
double[] incomes = {120000d, 39000d, 30000d, 21000d, 37000d, 46000d, reinvestRate, financeRate};
- try {
- mirr.evaluate(incomes);
- } catch (EvaluationException e) {
- assertEquals(ErrorEval.DIV_ZERO, e.getErrorEval());
- return;
- }
- fail("MIRR should failed with all these positives values");
+
+ EvaluationException e = assertThrows(EvaluationException.class, () -> mirr.evaluate(incomes));
+ assertEquals(ErrorEval.DIV_ZERO, e.getErrorEval());
}
@Test
@@ -141,13 +137,13 @@ public final class TestMirr {
CellValue cv = fe.evaluate(cellA);
assertEquals(ErrorEval.DIV_ZERO.getErrorCode(), cv.getErrorValue());
- assertEquals("IRR assertions failed", 0, failureCount);
+ assertEquals(0, failureCount, "IRR assertions failed");
}
private static void assertFormulaResult(CellValue cv, HSSFCell cell) {
double actualValue = cv.getNumberValue();
double expectedValue = cell.getNumericCellValue(); // cached formula result calculated by Excel
- assertEquals("Invalid formula result: " + cv, CellType.NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType(), "Invalid formula result: " + cv);
assertEquals(expectedValue, actualValue, 1E-8);
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestMultiOperandNumericFunction.java b/src/testcases/org/apache/poi/ss/formula/functions/TestMultiOperandNumericFunction.java
index a03772086b..c077e47aaf 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestMultiOperandNumericFunction.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMultiOperandNumericFunction.java
@@ -17,15 +17,15 @@
package org.apache.poi.ss.formula.functions;
-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.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.MissingArgEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestMultiOperandNumericFunction {
@@ -36,7 +36,7 @@ public class TestMultiOperandNumericFunction {
protected double evaluate(double[] values) throws EvaluationException {
return 0;
}
-
+
};
assertEquals(SpreadsheetVersion.EXCEL2007.getMaxFunctionArgs(), fun.getMaxNumOperands());
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestNper.java b/src/testcases/org/apache/poi/ss/formula/functions/TestNper.java
index ec5553d84c..d2a82e2de1 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestNper.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestNper.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
@@ -29,7 +29,7 @@ import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.FormulaError;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link FinanceFunction#NPER}
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 4df5bc898d..c51158e959 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestNpv.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFCell;
@@ -26,7 +26,7 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
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 Npv}
@@ -91,7 +91,7 @@ public final class TestNpv {
}
}
- assertEquals("IRR evaluations failed", 0, failureCount);
+ assertEquals(0, failureCount, "IRR evaluations failed");
}
private static void assertFormulaResult(CellValue cv, HSSFCell cell){
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestOct2Dec.java b/src/testcases/org/apache/poi/ss/formula/functions/TestOct2Dec.java
index b496f26ef9..26cc445394 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestOct2Dec.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestOct2Dec.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
/**
* Tests for {@link org.apache.poi.ss.formula.functions.Oct2Dec}
@@ -40,13 +40,13 @@ public final class TestOct2Dec {
private static void confirmValue(String msg, String number1, String expected) {
ValueEval result = invokeValue(number1);
assertEquals(NumberEval.class, result.getClass());
- assertEquals(msg, expected, ((NumberEval) result).getStringValue());
+ assertEquals(expected, ((NumberEval) result).getStringValue(), msg);
}
private static void confirmValueError(String msg, String number1, ErrorEval numError) {
ValueEval result = invokeValue(number1);
assertEquals(ErrorEval.class, result.getClass());
- assertEquals(msg, numError, result);
+ assertEquals(numError, result, msg);
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java b/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java
index ff18f417da..293796867e 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java
@@ -17,10 +17,9 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
@@ -31,7 +30,9 @@ import org.apache.poi.ss.formula.functions.Offset.LinearOffsetRange;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Workbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
/**
* Tests for OFFSET function implementation
@@ -40,42 +41,21 @@ import org.junit.Test;
*/
public final class TestOffset {
- private static void confirmDoubleConvert(double doubleVal, int expected) {
- try {
- assertEquals(expected, Offset.evaluateIntArg(new NumberEval(doubleVal), -1, -1));
- } catch (EvaluationException e) {
- fail("Unexpected error '" + e.getErrorEval() + "'.");
- }
- }
/**
* Excel's double to int conversion (for function 'OFFSET()') behaves more like Math.floor().
* Note - negative values are not symmetrical
* Fractional values are silently truncated.
* Truncation is toward negative infinity.
*/
- @Test
- public void testDoubleConversion() {
-
- confirmDoubleConvert(100.09, 100);
- confirmDoubleConvert(100.01, 100);
- confirmDoubleConvert(100.00, 100);
- confirmDoubleConvert(99.99, 99);
-
- confirmDoubleConvert(+2.01, +2);
- confirmDoubleConvert(+2.00, +2);
- confirmDoubleConvert(+1.99, +1);
- confirmDoubleConvert(+1.01, +1);
- confirmDoubleConvert(+1.00, +1);
- confirmDoubleConvert(+0.99, 0);
- confirmDoubleConvert(+0.01, 0);
- confirmDoubleConvert( 0.00, 0);
- confirmDoubleConvert(-0.01, -1);
- confirmDoubleConvert(-0.99, -1);
- confirmDoubleConvert(-1.00, -1);
- confirmDoubleConvert(-1.01, -2);
- confirmDoubleConvert(-1.99, -2);
- confirmDoubleConvert(-2.00, -2);
- confirmDoubleConvert(-2.01, -3);
+ @ParameterizedTest
+ @CsvSource({
+ "100.09, 100", "100.01, 100", "100.00, 100", "99.99, 99", "+2.01, +2",
+ "+2.00, +2", "+1.99, +1", "+1.01, +1", "+1.00, +1", "+0.99, 0",
+ "+0.01, 0", "0.00, 0","-0.01, -1", "-0.99, -1", "-1.00, -1",
+ "-1.01, -2", "-1.99, -2", "-2.00, -2", "-2.01, -3"
+ })
+ public void testDoubleConversion(double doubleVal, int expected) throws EvaluationException {
+ assertEquals(expected, Offset.evaluateIntArg(new NumberEval(doubleVal), -1, -1));
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestPPMT.java b/src/testcases/org/apache/poi/ss/formula/functions/TestPPMT.java
index e18e87b417..3ecffc04c3 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestPPMT.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestPPMT.java
@@ -19,14 +19,14 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test cases for PPMT()
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestPmt.java b/src/testcases/org/apache/poi/ss/formula/functions/TestPmt.java
index 0e4bd8224b..8a251707a7 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestPmt.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestPmt.java
@@ -17,14 +17,16 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.FormulaError;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestPmt {
@@ -40,9 +42,7 @@ public final class TestPmt {
*/
private static NumberEval invokeNormal(ValueEval[] args) {
ValueEval ev = invoke(args);
- if(ev instanceof ErrorEval) {
- fail("Normal evaluation failed with error code: " + ev);
- }
+ assertFalse(ev instanceof ErrorEval, "Normal evaluation failed with error code: " + ev);
return (NumberEval) ev;
}
@@ -74,9 +74,7 @@ public final class TestPmt {
ValueEval ev = invoke(args);
if(ev instanceof ErrorEval) {
ErrorEval err = (ErrorEval) ev;
- if(err.getErrorCode() == FormulaError.VALUE.getCode()) {
- fail("Identified bug 44691");
- }
+ assertNotEquals(FormulaError.VALUE.getCode(), err.getErrorCode(), "Identified bug 44691");
}
confirm(-44.3206, invokeNormal(args));
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestPoisson.java b/src/testcases/org/apache/poi/ss/formula/functions/TestPoisson.java
index 9f21aa87f9..d8838e2c78 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestPoisson.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestPoisson.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for Excel function POISSON(x,mean,cumulative)
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestProduct.java b/src/testcases/org/apache/poi/ss/formula/functions/TestProduct.java
index e4af3bd866..9dce846c87 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestProduct.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestProduct.java
@@ -21,10 +21,10 @@ import org.apache.poi.ss.formula.eval.MissingArgEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
-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;
public class TestProduct {
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java b/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java
index fc4fa001d8..b636e30811 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestQuotient.java
@@ -16,13 +16,13 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
/**
* Tests for {@link Quotient}
@@ -38,13 +38,13 @@ public class TestQuotient {
private static void confirmValue(String msg, String numerator, String denominator, String expected) {
ValueEval result = invokeValue(numerator, denominator);
assertEquals(NumberEval.class, result.getClass());
- assertEquals(msg, expected, ((NumberEval) result).getStringValue());
+ assertEquals(expected, ((NumberEval) result).getStringValue(), msg);
}
private static void confirmValueError(String msg, String numerator, String denominator, ErrorEval numError) {
ValueEval result = invokeValue(numerator, denominator);
assertEquals(ErrorEval.class, result.getClass());
- assertEquals(msg, numError, result);
+ assertEquals(numError, result, msg);
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java
index 5f33111a34..0406d72ab8 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests QUOTIENT() as loaded from a test data spreadsheet.<p>
*/
public class TestQuotientFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestQuotientFunctionsFromSpreadsheet.class, "QuotientFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestRank.java b/src/testcases/org/apache/poi/ss/formula/functions/TestRank.java
index a83f8b8de8..70923618fa 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestRank.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestRank.java
@@ -19,7 +19,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFCell;
@@ -27,7 +27,7 @@ import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellReference;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test cases for RANK()
@@ -57,15 +57,15 @@ public final class TestRank {
for(int rownum = 1; rownum<= 10; rownum ++){
HSSFCell cellD = example3.getRow(rownum).getCell(3);
double cachedResultD = cellD.getNumericCellValue(); //cached formula result
- assertEquals(new CellReference(cellD).formatAsString(), cachedResultD, fe.evaluate(cellD).getNumberValue(), 0);
+ assertEquals(cachedResultD, fe.evaluate(cellD).getNumberValue(), 0, new CellReference(cellD).formatAsString());
HSSFCell cellE = example3.getRow(rownum).getCell(4);
double cachedResultE = cellE.getNumericCellValue(); //cached formula result
- assertEquals(new CellReference(cellE).formatAsString(), cachedResultE, fe.evaluate(cellE).getNumberValue(), 0);
+ assertEquals(cachedResultE, fe.evaluate(cellE).getNumberValue(), 0, new CellReference(cellE).formatAsString());
HSSFCell cellF = example3.getRow(rownum).getCell(5);
double cachedResultF = cellF.getNumericCellValue(); //cached formula result
- assertEquals(new CellReference(cellF).formatAsString(), cachedResultF, fe.evaluate(cellF).getNumberValue(), 0);
+ assertEquals(cachedResultF, fe.evaluate(cellF).getNumberValue(), 0, new CellReference(cellF).formatAsString());
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestRelationalOperations.java b/src/testcases/org/apache/poi/ss/formula/functions/TestRelationalOperations.java
index dc9f7673c5..b63b6e3dcc 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestRelationalOperations.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestRelationalOperations.java
@@ -16,7 +16,7 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.CacheAreaEval;
import org.apache.poi.ss.formula.eval.BoolEval;
@@ -25,7 +25,7 @@ import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.RelationalOperationEval;
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 TestRelationalOperations {
@@ -50,7 +50,7 @@ public class TestRelationalOperations {
RelationalOperationEval eq = (RelationalOperationEval)RelationalOperationEval.EqualEval;
ValueEval result = eq.evaluateArray(new ValueEval[]{ arg1, arg2}, 2, 5);
- assertEquals("expected CacheAreaEval", CacheAreaEval.class, result.getClass());
+ assertEquals(CacheAreaEval.class, result.getClass(), "expected CacheAreaEval");
CacheAreaEval ce = (CacheAreaEval)result;
assertEquals(2, ce.getWidth());
assertEquals(2, ce.getHeight());
@@ -73,7 +73,7 @@ public class TestRelationalOperations {
RelationalOperationEval eq = (RelationalOperationEval)RelationalOperationEval.EqualEval;
ValueEval result = eq.evaluateArray(new ValueEval[]{ arg1, arg2}, 2, 5);
- assertEquals("expected CacheAreaEval", CacheAreaEval.class, result.getClass());
+ assertEquals(CacheAreaEval.class, result.getClass(), "expected CacheAreaEval");
CacheAreaEval ce = (CacheAreaEval)result;
assertEquals(2, ce.getWidth());
assertEquals(2, ce.getHeight());
@@ -106,14 +106,14 @@ public class TestRelationalOperations {
RelationalOperationEval eq = (RelationalOperationEval)RelationalOperationEval.EqualEval;
ValueEval result = eq.evaluateArray(new ValueEval[]{ arg1, arg2}, 4, 5);
- assertEquals("expected CacheAreaEval", CacheAreaEval.class, result.getClass());
+ assertEquals(CacheAreaEval.class, result.getClass(), "expected CacheAreaEval");
CacheAreaEval ce = (CacheAreaEval)result;
assertEquals(3, ce.getWidth());
assertEquals(2, ce.getHeight());
int idx = 0;
for(int i =0; i < ce.getHeight(); i++){
for(int j = 0; j < ce.getWidth(); j++){
- assertEquals("[" + i + "," + j + "]", expected[idx++], ce.getRelativeValue(i, j));
+ assertEquals(expected[idx++], ce.getRelativeValue(i, j), "[" + i + "," + j + "]");
}
}
}
@@ -143,14 +143,14 @@ public class TestRelationalOperations {
RelationalOperationEval eq = (RelationalOperationEval)RelationalOperationEval.EqualEval;
ValueEval result = eq.evaluateArray(new ValueEval[]{ arg1, arg2}, 4, 6);
- assertEquals("expected CacheAreaEval", CacheAreaEval.class, result.getClass());
+ assertEquals(CacheAreaEval.class, result.getClass(), "expected CacheAreaEval");
CacheAreaEval ce = (CacheAreaEval)result;
assertEquals(2, ce.getWidth());
assertEquals(3, ce.getHeight());
int idx = 0;
for(int i =0; i < ce.getHeight(); i++){
for(int j = 0; j < ce.getWidth(); j++){
- assertEquals("[" + i + "," + j + "]", expected[idx++], ce.getRelativeValue(i, j));
+ assertEquals(expected[idx++], ce.getRelativeValue(i, j), "[" + i + "," + j + "]");
}
}
}
@@ -181,14 +181,14 @@ public class TestRelationalOperations {
RelationalOperationEval eq = (RelationalOperationEval)RelationalOperationEval.EqualEval;
ValueEval result = eq.evaluateArray(new ValueEval[]{ arg1, arg2}, 4, 6);
- assertEquals("expected CacheAreaEval", CacheAreaEval.class, result.getClass());
+ assertEquals(CacheAreaEval.class, result.getClass(), "expected CacheAreaEval");
CacheAreaEval ce = (CacheAreaEval)result;
assertEquals(3, ce.getWidth());
assertEquals(3, ce.getHeight());
int idx = 0;
for(int i =0; i < ce.getHeight(); i++){
for(int j = 0; j < ce.getWidth(); j++){
- assertEquals("[" + i + "," + j + "]", expected[idx++], ce.getRelativeValue(i, j));
+ assertEquals(expected[idx++], ce.getRelativeValue(i, j), "[" + i + "," + j + "]");
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestReptFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestReptFunctionsFromSpreadsheet.java
index f505cd556a..a2a62f8b65 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestReptFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestReptFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests REPT() as loaded from a test data spreadsheet.<p>
*/
public class TestReptFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestReptFunctionsFromSpreadsheet.class, "ReptFunctionTestCaseData.xls");
}
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestRomanFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestRomanFunctionsFromSpreadsheet.java
index 26b8745cf0..716dfc202b 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestRomanFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestRomanFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests Roman() as loaded from a test data spreadsheet.<p>
*/
public class TestRomanFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestRomanFunctionsFromSpreadsheet.class, "RomanFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java b/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java
index 6730cd2d9d..bee18ea272 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java
@@ -17,10 +17,10 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
-import org.junit.Ignore;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.ValueEval;
@@ -35,7 +35,7 @@ import org.apache.poi.ss.formula.eval.StringEval;
public final class TestRoundFuncs {
// github-43
// https://github.com/apache/poi/pull/43
- @Ignore("ROUNDUP(3987*0.2, 2) currently fails by returning 797.41")
+ @Disabled("ROUNDUP(3987*0.2, 2) currently fails by returning 797.41")
@Test
public void testRoundUp() {
assertRoundUpEquals(797.40, 3987*0.2, 2, 1e-10);
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestRowCol.java b/src/testcases/org/apache/poi/ss/formula/functions/TestRowCol.java
index 8b194bb8ae..0b73dc5b69 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestRowCol.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestRowCol.java
@@ -17,10 +17,10 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for ROW(), ROWS(), COLUMN(), COLUMNS()
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestSlope.java b/src/testcases/org/apache/poi/ss/formula/functions/TestSlope.java
index de3597e05d..a54d508f8d 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestSlope.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSlope.java
@@ -19,12 +19,12 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test for Excel function SLOPE()
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 9c4fdcb2f2..a462448097 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java
@@ -20,13 +20,14 @@
*/
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertNotNull;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.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;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
public class TestStatsLib extends BaseTestNumeric {
@@ -39,32 +40,32 @@ public class TestStatsLib extends BaseTestNumeric {
v = new double[] {1,2,3,4,5,6,7,8,9,10};
d = StatsLib.devsq(v);
x = 82.5;
- assertEquals("devsq ", x, d);
+ assertDouble("devsq ", x, d);
v = new double[] {1,1,1,1,1,1,1,1,1,1};
d = StatsLib.devsq(v);
x = 0;
- assertEquals("devsq ", x, d);
+ assertDouble("devsq ", x, d);
v = new double[] {0,0,0,0,0,0,0,0,0,0};
d = StatsLib.devsq(v);
x = 0;
- assertEquals("devsq ", x, d);
+ assertDouble("devsq ", x, d);
v = new double[] {1,2,1,2,1,2,1,2,1,2};
d = StatsLib.devsq(v);
x = 2.5;
- assertEquals("devsq ", x, d);
+ assertDouble("devsq ", x, d);
v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999};
d = StatsLib.devsq(v);
x = 10953.7416965767;
- assertEquals("devsq ", x, d);
+ assertDouble("devsq ", x, d);
v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10};
d = StatsLib.devsq(v);
x = 82.5;
- assertEquals("devsq ", x, d);
+ assertDouble("devsq ", x, d);
}
@Test
@@ -75,36 +76,36 @@ public class TestStatsLib extends BaseTestNumeric {
v = new double[] {1,2,3,4,5,6,7,8,9,10};
d = StatsLib.kthLargest(v, 3);
x = 8;
- assertEquals("kthLargest ", x, d);
+ assertDouble("kthLargest ", x, d);
v = new double[] {1,1,1,1,1,1,1,1,1,1};
d = StatsLib.kthLargest(v, 3);
x = 1;
- assertEquals("kthLargest ", x, d);
+ assertDouble("kthLargest ", x, d);
v = new double[] {0,0,0,0,0,0,0,0,0,0};
d = StatsLib.kthLargest(v, 3);
x = 0;
- assertEquals("kthLargest ", x, d);
+ assertDouble("kthLargest ", x, d);
v = new double[] {1,2,1,2,1,2,1,2,1,2};
d = StatsLib.kthLargest(v, 3);
x = 2;
- assertEquals("kthLargest ", x, d);
+ assertDouble("kthLargest ", x, d);
v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999};
d = StatsLib.kthLargest(v, 3);
x = 5.37828;
- assertEquals("kthLargest ", x, d);
+ assertDouble("kthLargest ", x, d);
v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10};
d = StatsLib.kthLargest(v, 3);
x = -3;
- assertEquals("kthLargest ", x, d);
+ assertDouble("kthLargest ", x, d);
}
@Test
- @Ignore("... implement ...")
+ @Disabled("... implement ...")
public void testKthSmallest() {
}
@@ -116,32 +117,32 @@ public class TestStatsLib extends BaseTestNumeric {
v = new double[] {1,2,3,4,5,6,7,8,9,10};
d = StatsLib.avedev(v);
x = 2.5;
- assertEquals("avedev ", x, d);
+ assertDouble("avedev ", x, d);
v = new double[] {1,1,1,1,1,1,1,1,1,1};
d = StatsLib.avedev(v);
x = 0;
- assertEquals("avedev ", x, d);
+ assertDouble("avedev ", x, d);
v = new double[] {0,0,0,0,0,0,0,0,0,0};
d = StatsLib.avedev(v);
x = 0;
- assertEquals("avedev ", x, d);
+ assertDouble("avedev ", x, d);
v = new double[] {1,2,1,2,1,2,1,2,1,2};
d = StatsLib.avedev(v);
x = 0.5;
- assertEquals("avedev ", x, d);
+ assertDouble("avedev ", x, d);
v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999};
d = StatsLib.avedev(v);
x = 36.42176053333;
- assertEquals("avedev ", x, d);
+ assertDouble("avedev ", x, d);
v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10};
d = StatsLib.avedev(v);
x = 2.5;
- assertEquals("avedev ", x, d);
+ assertDouble("avedev ", x, d);
}
@Test
@@ -152,42 +153,42 @@ public class TestStatsLib extends BaseTestNumeric {
v = new double[] {1,2,3,4,5,6,7,8,9,10};
d = StatsLib.median(v);
x = 5.5;
- assertEquals("median ", x, d);
+ assertDouble("median ", x, d);
v = new double[] {1,1,1,1,1,1,1,1,1,1};
d = StatsLib.median(v);
x = 1;
- assertEquals("median ", x, d);
+ assertDouble("median ", x, d);
v = new double[] {0,0,0,0,0,0,0,0,0,0};
d = StatsLib.median(v);
x = 0;
- assertEquals("median ", x, d);
+ assertDouble("median ", x, d);
v = new double[] {1,2,1,2,1,2,1,2,1,2};
d = StatsLib.median(v);
x = 1.5;
- assertEquals("median ", x, d);
+ assertDouble("median ", x, d);
v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999};
d = StatsLib.median(v);
x = 5.37828;
- assertEquals("median ", x, d);
+ assertDouble("median ", x, d);
v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10};
d = StatsLib.median(v);
x = -5.5;
- assertEquals("median ", x, d);
+ assertDouble("median ", x, d);
v = new double[] {-2,-3,-4,-5,-6,-7,-8,-9,-10};
d = StatsLib.median(v);
x = -6;
- assertEquals("median ", x, d);
+ assertDouble("median ", x, d);
v = new double[] {1,2,3,4,5,6,7,8,9};
d = StatsLib.median(v);
x = 5;
- assertEquals("median ", x, d);
+ assertDouble("median ", x, d);
}
@Test
@@ -227,15 +228,15 @@ public class TestStatsLib extends BaseTestNumeric {
double actual;
try {
actual = Mode.evaluate(v);
- assertNotNull("Expected N/A exception was not thrown", expectedResult);
+ assertNotNull(expectedResult, "Expected N/A exception was not thrown");
} catch (EvaluationException e) {
if (expectedResult == null) {
- Assert.assertEquals(ErrorEval.NA, e.getErrorEval());
+ assertEquals(ErrorEval.NA, e.getErrorEval());
return;
}
throw new RuntimeException(e);
}
- assertEquals("mode", expectedResult.doubleValue(), actual);
+ assertDouble("mode", expectedResult, actual);
}
@Test
@@ -246,32 +247,32 @@ public class TestStatsLib extends BaseTestNumeric {
v = new double[] {1,2,3,4,5,6,7,8,9,10};
d = StatsLib.stdev(v);
x = 3.02765035410;
- assertEquals("stdev ", x, d);
+ assertDouble("stdev ", x, d);
v = new double[] {1,1,1,1,1,1,1,1,1,1};
d = StatsLib.stdev(v);
x = 0;
- assertEquals("stdev ", x, d);
+ assertDouble("stdev ", x, d);
v = new double[] {0,0,0,0,0,0,0,0,0,0};
d = StatsLib.stdev(v);
x = 0;
- assertEquals("stdev ", x, d);
+ assertDouble("stdev ", x, d);
v = new double[] {1,2,1,2,1,2,1,2,1,2};
d = StatsLib.stdev(v);
x = 0.52704627669;
- assertEquals("stdev ", x, d);
+ assertDouble("stdev ", x, d);
v = new double[] {123.12,33.3333,2d/3d,5.37828,0.999};
d = StatsLib.stdev(v);
x = 52.33006233652;
- assertEquals("stdev ", x, d);
+ assertDouble("stdev ", x, d);
v = new double[] {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10};
d = StatsLib.stdev(v);
x = 3.02765035410;
- assertEquals("stdev ", x, d);
+ assertDouble("stdev ", x, d);
}
@Test
@@ -282,22 +283,22 @@ public class TestStatsLib extends BaseTestNumeric {
v = new double[] {3.50, 5.00, 7.23, 2.99};
d = StatsLib.var(v);
x = 3.6178;
- assertEquals("var ", x, d);
+ assertDouble("var ", x, d);
v = new double[] {34.5, 2.0, 8.9, -4.0};
d = StatsLib.var(v);
x = 286.99;
- assertEquals("var ", x, d);
+ assertDouble("var ", x, d);
v = new double[] {7.0, 25.0, 21.69};
d = StatsLib.var(v);
x = 91.79203333;
- assertEquals("var ", x, d);
+ assertDouble("var ", x, d);
v = new double[] {1345,1301,1368,1322,1310,1370,1318,1350,1303,1299};
d = StatsLib.var(v);
x = 754.2666667;
- assertEquals("var ", x, d);
+ assertDouble("var ", x, d);
}
@Test
@@ -308,21 +309,21 @@ public class TestStatsLib extends BaseTestNumeric {
v = new double[] {3.50, 5.00, 7.23, 2.99};
d = StatsLib.varp(v);
x = 2.71335;
- assertEquals("varp ", x, d);
+ assertDouble("varp ", x, d);
v = new double[] {34.5, 2.0, 8.9, -4.0};
d = StatsLib.varp(v);
x = 215.2425;
- assertEquals("varp ", x, d);
+ assertDouble("varp ", x, d);
v = new double[] {7.0, 25.0, 21.69};
d = StatsLib.varp(v);
x = 61.19468889;
- assertEquals("varp ", x, d);
+ assertDouble("varp ", x, d);
v = new double[] {1345,1301,1368,1322,1310,1370,1318,1350,1303,1299};
d = StatsLib.varp(v);
x = 678.84;
- assertEquals("varp ", x, d);
+ assertDouble("varp ", x, d);
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestSubstitute.java b/src/testcases/org/apache/poi/ss/formula/functions/TestSubstitute.java
index 68c868865b..9a076e9336 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestSubstitute.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSubstitute.java
@@ -22,9 +22,9 @@ import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.StringValueEval;
import org.apache.poi.ss.usermodel.FormulaError;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestSubstitute {
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestSubtotal.java b/src/testcases/org/apache/poi/ss/formula/functions/TestSubtotal.java
index aa16314379..240d48b05a 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestSubtotal.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSubtotal.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.formula.functions;
-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 java.io.IOException;
@@ -37,7 +37,7 @@ import org.apache.poi.ss.usermodel.FormulaError;
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;
/**
* Tests for {@link Subtotal}
@@ -345,7 +345,7 @@ public final class TestSubtotal {
CellValue value = evaluator.evaluate(cell);
if (value.getErrorValue() != 0)
throw new RuntimeException(msg + ": " + value.formatAsString());
- assertEquals(msg, expected, value.getNumberValue(), 0);
+ assertEquals(expected, value.getNumberValue(), 0, msg);
}
@Test
@@ -354,16 +354,16 @@ public final class TestSubtotal {
HSSFSheet sheet = workbook.getSheetAt(0);
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
- assertEquals("B2", 10.0, sheet.getRow(1).getCell(1).getNumericCellValue(), 0);
- assertEquals("B3", 20.0, sheet.getRow(2).getCell(1).getNumericCellValue(), 0);
+ assertEquals(10.0, sheet.getRow(1).getCell(1).getNumericCellValue(), 0, "B2");
+ assertEquals(20.0, sheet.getRow(2).getCell(1).getNumericCellValue(), 0, "B3");
//Test simple subtotal over one area
Cell cellA3 = sheet.getRow(3).getCell(1);
confirmExpectedResult(evaluator, "B4", cellA3, 30.0);
//Test existence of the second area
- assertNotNull("C2 must not be null", sheet.getRow(1).getCell(2));
- assertEquals("C2", 7.0, sheet.getRow(1).getCell(2).getNumericCellValue(), 0);
+ assertNotNull(sheet.getRow(1).getCell(2), "C2 must not be null");
+ assertEquals(7.0, sheet.getRow(1).getCell(2).getNumericCellValue(), 0, "C2");
Cell cellC1 = sheet.getRow(1).getCell(3);
Cell cellC2 = sheet.getRow(2).getCell(3);
@@ -375,7 +375,7 @@ public final class TestSubtotal {
confirmExpectedResult(evaluator, "SUBTOTAL(SUM;B2:B8;C2:C8)", cellC1, 37.0);
confirmExpectedResult(evaluator, "SUBTOTAL(COUNT;B2:B8,C2:C8)", cellC2, 3.0);
confirmExpectedResult(evaluator, "SUBTOTAL(COUNTA;B2:B8,C2:C8)", cellC3, 5.0);
-
+
// test same functions ignoring hidden rows over a copy of the same data
cellC1 = sheet.getRow(11).getCell(3);
cellC2 = sheet.getRow(12).getCell(3);
@@ -383,8 +383,8 @@ public final class TestSubtotal {
confirmExpectedResult(evaluator, "SUBTOTAL(SUM NO HIDDEN;B22:B28;C22:C28)", cellC1, 17.0);
confirmExpectedResult(evaluator, "SUBTOTAL(COUNT NO HIDDEN;B22:B28,C22:C28)", cellC2, 2.0);
confirmExpectedResult(evaluator, "SUBTOTAL(COUNTA NO HIDDEN;B22:B28,C22:C28)", cellC3, 4.0);
-
-
+
+
workbook.close();
}
@@ -396,7 +396,7 @@ public final class TestSubtotal {
Sheet sh = wb.createSheet();
Cell a3 = sh.createRow(3).createCell(1);
-
+
// formula, throws NotImplemnted?
String[][] formulas = {
{ "SUBTOTAL(8,B2:B3)", NotImplementedException.class.getName() },
@@ -406,25 +406,25 @@ public final class TestSubtotal {
{ "SUBTOTAL(9)", FormulaParseException.class.getName() },
{ "SUBTOTAL()", FormulaParseException.class.getName() },
};
-
+
for (String[] f : formulas) {
Exception actualEx = null;
try {
a3.setCellFormula(f[0]);
fe.evaluateAll();
- assertEquals(f[0], FormulaError.VALUE.getCode(), a3.getErrorCellValue());
+ assertEquals(FormulaError.VALUE.getCode(), a3.getErrorCellValue(), f[0]);
} catch (Exception e) {
actualEx = e;
}
String msg =
"Check "+(f[1] == null ? "unexpected exception" : f[1])+" here, "+
"adjust these tests if it was actually implemented - "+f[0];
- assertEquals(msg, f[1], (actualEx == null ? null : actualEx.getClass().getName()));
+ assertEquals(f[1], (actualEx == null ? null : actualEx.getClass().getName()), msg);
}
Subtotal subtotal = new Subtotal();
assertEquals(ErrorEval.VALUE_INVALID, subtotal.evaluate(new ValueEval[] {}, 0, 0));
-
+
wb.close();
}
}
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 7f5aabcbd5..894c93609a 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java
@@ -17,9 +17,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 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.eval.AreaEval;
import org.apache.poi.ss.formula.eval.BlankEval;
@@ -28,7 +28,7 @@ import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.NumericValueEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test cases for SUMPRODUCT()
@@ -44,7 +44,7 @@ public final class TestSumif {
}
private static void confirmDouble(double expected, ValueEval actualEval) {
- assertTrue("Expected numeric result", actualEval instanceof NumericValueEval);
+ assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result");
NumericValueEval nve = (NumericValueEval)actualEval;
assertEquals(expected, nve.getNumberValue(), 0);
}
@@ -96,7 +96,7 @@ public final class TestSumif {
ve = invokeSumif(0, 2, arg0, arg1); // invoking from cell C1
if (ve instanceof NumberEval) {
NumberEval ne = (NumberEval) ve;
- assertNotEquals("identified error in SUMIF - criteria arg not evaluated properly", 30.0, ne.getNumberValue());
+ assertNotEquals(30.0, ne.getNumberValue(), "identified error in SUMIF - criteria arg not evaluated properly");
}
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 4e441a066e..135cd1f1a6 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSumifs.java
@@ -19,8 +19,8 @@
package org.apache.poi.ss.formula.functions;
-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.hssf.usermodel.HSSFCell;
@@ -33,7 +33,7 @@ import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.NumericValueEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test cases for SUMIFS()
@@ -47,7 +47,7 @@ public final class TestSumifs {
}
private static void confirmDouble(double expected, ValueEval actualEval) {
- assertTrue("Expected numeric result", actualEval instanceof NumericValueEval);
+ assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result");
NumericValueEval nve = (NumericValueEval)actualEval;
assertEquals(expected, nve.getNumberValue(), 0);
}
@@ -297,7 +297,7 @@ public final class TestSumifs {
};
ValueEval result = invokeSumifs(args);
- assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval);
+ assertTrue(result instanceof ErrorEval, "Expect to have an error when an input is an invalid value, but had: " + result.getClass());
args = new ValueEval[]{
EvalFactory.createAreaEval("A2:A9", a2a9),
@@ -306,7 +306,7 @@ public final class TestSumifs {
};
result = invokeSumifs(args);
- assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval);
+ assertTrue(result instanceof ErrorEval, "Expect to have an error when an input is an invalid value, but had: " + result.getClass());
}
@Test
@@ -330,7 +330,7 @@ public final class TestSumifs {
};
ValueEval result = invokeSumifs(args);
- assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval);
+ assertTrue(result instanceof ErrorEval, "Expect to have an error when an input is an invalid value, but had: " + result.getClass());
assertEquals(ErrorEval.VALUE_INVALID, result);
}
@@ -355,7 +355,7 @@ public final class TestSumifs {
};
ValueEval result = invokeSumifs(args);
- assertTrue("Expect to have an error when an input is an invalid value, but had: " + result.getClass(), result instanceof ErrorEval);
+ assertTrue(result instanceof ErrorEval, "Expect to have an error when an input is an invalid value, but had: " + result.getClass());
assertEquals(ErrorEval.NAME_INVALID, result);
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestSumproduct.java b/src/testcases/org/apache/poi/ss/formula/functions/TestSumproduct.java
index 422b154a04..47b1751ae9 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestSumproduct.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestSumproduct.java
@@ -17,8 +17,9 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+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 org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
@@ -26,7 +27,7 @@ import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.NumericValueEval;
import org.apache.poi.ss.formula.eval.RefEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test cases for SUMPRODUCT()
@@ -41,9 +42,7 @@ public final class TestSumproduct {
}
private static void confirmDouble(double expected, ValueEval actualEval) {
- if(!(actualEval instanceof NumericValueEval)) {
- fail("Expected numeric result");
- }
+ assertTrue(actualEval instanceof NumericValueEval, "Expected numeric result");
NumericValueEval nve = (NumericValueEval)actualEval;
assertEquals(expected, nve.getNumberValue(), 0);
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestTFunc.java b/src/testcases/org/apache/poi/ss/formula/functions/TestTFunc.java
index a89a213091..efadacf610 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestTFunc.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestTFunc.java
@@ -17,10 +17,10 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-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.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.BlankEval;
@@ -29,7 +29,7 @@ import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
/**
* Test cases for Excel function T()
@@ -44,7 +44,7 @@ public final class TestTFunc {
private static ValueEval invokeT(ValueEval arg) {
ValueEval[] args = { arg, };
ValueEval result = new T().evaluate(args, -1, (short)-1);
- assertNotNull("result may never be null", result);
+ assertNotNull(result, "result may never be null");
return result;
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestText.java b/src/testcases/org/apache/poi/ss/formula/functions/TestText.java
index 0e6521ef23..4bde9abb10 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestText.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestText.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.text.DateFormatSymbols;
import java.text.DecimalFormatSymbols;
@@ -29,7 +29,7 @@ import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test case for TEXT()
@@ -104,28 +104,28 @@ public final class TestText {
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
ValueEval testResult = new StringEval("16:11:1900 07:42:14");
assertEquals(testResult.toString(), result.toString());
-
+
// Excel also supports "m before h is month"
formatArg = new StringEval("dd:mm:yyyy hh:mm:ss");
args[1] = formatArg;
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
testResult = new StringEval("16:11:1900 07:42:14");
assertEquals(testResult.toString(), result.toString());
-
+
// this line is intended to compute how "November" would look like in the current locale
// update: now the locale will be (if not set otherwise) always Locale.getDefault() (see LocaleUtil)
DateFormatSymbols dfs = DateFormatSymbols.getInstance(LocaleUtil.getUserLocale());
SimpleDateFormat sdf = new SimpleDateFormat("MMMM", dfs);
sdf.setTimeZone(LocaleUtil.getUserTimeZone());
String november = sdf.format(LocaleUtil.getLocaleCalendar(2015,10,1).getTime());
-
+
// Again with Java style
formatArg = new StringEval("MMMM dd, yyyy");
args[1] = formatArg;
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
testResult = new StringEval(november + " 16, 1900");
assertEquals(testResult.toString(), result.toString());
-
+
// And Excel style
formatArg = new StringEval("mmmm dd, yyyy");
args[1] = formatArg;
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestTime.java b/src/testcases/org/apache/poi/ss/formula/functions/TestTime.java
index 7f12c136aa..87b049585f 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestTime.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestTime.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.regex.Pattern;
@@ -28,8 +28,8 @@ import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link TimeFunc}
@@ -44,8 +44,8 @@ public final class TestTime {
private HSSFWorkbook wb;
private HSSFDataFormatter form;
private HSSFCellStyle style;
-
- @Before
+
+ @BeforeEach
public void setUp() {
wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestTrendFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestTrendFunctionsFromSpreadsheet.java
index 51871d16e5..49f9a714f7 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestTrendFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestTrendFunctionsFromSpreadsheet.java
@@ -16,16 +16,15 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests TREND() as loaded from a test data spreadsheet.
*/
public class TestTrendFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestTrendFunctionsFromSpreadsheet.class, "Trend.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestTrim.java b/src/testcases/org/apache/poi/ss/formula/functions/TestTrim.java
index d18c044d15..4d889116ae 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestTrim.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestTrim.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.BoolEval;
@@ -25,7 +25,7 @@ import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
/**
* Tests for Excel function TRIM()
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java b/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java
index 50d0adabc9..ba137bdd28 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java
@@ -17,12 +17,13 @@
package org.apache.poi.ss.formula.functions;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test case for TRUNC()
@@ -38,7 +39,7 @@ public final class TestTrunc extends BaseTestNumeric {
ValueEval strArg = new StringEval("abc");
ValueEval[] args = { strArg, new NumberEval(2) };
ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1);
- Assert.assertEquals(ErrorEval.VALUE_INVALID, result);
+ assertEquals(ErrorEval.VALUE_INVALID, result);
}
@Test
@@ -46,7 +47,7 @@ public final class TestTrunc extends BaseTestNumeric {
ValueEval[] args = { new NumberEval(200), new NumberEval(2) };
@SuppressWarnings("static-access")
ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1);
- assertEquals("TRUNC", (new NumberEval(200d)).getNumberValue(), ((NumberEval)result).getNumberValue());
+ assertDouble("TRUNC", (new NumberEval(200d)).getNumberValue(), ((NumberEval)result).getNumberValue());
}
@Test
@@ -54,14 +55,14 @@ public final class TestTrunc extends BaseTestNumeric {
ValueEval[] args = { new NumberEval(2.612777), new NumberEval(3) };
@SuppressWarnings("static-access")
ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1);
- assertEquals("TRUNC", (new NumberEval(2.612d)).getNumberValue(), ((NumberEval)result).getNumberValue());
+ assertDouble("TRUNC", (new NumberEval(2.612d)).getNumberValue(), ((NumberEval)result).getNumberValue());
}
@Test
public void testTruncWithProblematicDecimalNumber() {
ValueEval[] args = { new NumberEval(0.29), new NumberEval(2) };
ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1);
- assertEquals("TRUNC", (new NumberEval(0.29d)).getNumberValue(), ((NumberEval)result).getNumberValue());
+ assertDouble("TRUNC", (new NumberEval(0.29d)).getNumberValue(), ((NumberEval)result).getNumberValue());
}
@Test
@@ -69,14 +70,14 @@ public final class TestTrunc extends BaseTestNumeric {
ValueEval[] args = { new NumberEval(21.624d / 24d + .009d), new NumberEval(2) };
ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1);
- assertEquals("TRUNC", (new NumberEval(0.91d)).getNumberValue(), ((NumberEval)result).getNumberValue());
+ assertDouble("TRUNC", (new NumberEval(0.91d)).getNumberValue(), ((NumberEval)result).getNumberValue());
}
@Test
public void testTruncWithDecimalNumberOneArg() {
ValueEval[] args = { new NumberEval(2.612777) };
ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1);
- assertEquals("TRUNC", (new NumberEval(2d)).getNumberValue(), ((NumberEval)result).getNumberValue());
+ assertDouble("TRUNC", (new NumberEval(2d)).getNumberValue(), ((NumberEval)result).getNumberValue());
}
@Test
@@ -84,6 +85,6 @@ public final class TestTrunc extends BaseTestNumeric {
ValueEval[] args = { new NumberEval(-8.9), new NumberEval(0) };
@SuppressWarnings("static-access")
ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1);
- assertEquals("TRUNC", (new NumberEval(-8)).getNumberValue(), ((NumberEval)result).getNumberValue());
+ assertDouble("TRUNC", (new NumberEval(-8)).getNumberValue(), ((NumberEval)result).getNumberValue());
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestTwoOperandNumericFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestTwoOperandNumericFunctionsFromSpreadsheet.java
index f630af5cab..389d2bb5a0 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestTwoOperandNumericFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestTwoOperandNumericFunctionsFromSpreadsheet.java
@@ -17,17 +17,16 @@
package org.apache.poi.ss.formula.functions;
-import org.junit.runners.Parameterized.Parameters;
+import java.util.stream.Stream;
-import java.util.Collection;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests for numeric functions with two arguments such aqs +, -, *, POWER
* as loaded from a test data spreadsheet.
*/
public class TestTwoOperandNumericFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestTwoOperandNumericFunctionsFromSpreadsheet.class, "TwoOperandNumericFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java b/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java
index bed69af15f..701d1eafd3 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
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;
/**
* Tests for {@link Value}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java
index 8fd8cef82b..10b6f4c773 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests WeekNum() as loaded from a test data spreadsheet.<p>
*/
public class TestWeekNumFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
return data(TestWeekNumFunctionsFromSpreadsheet.class, "WeekNumFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet2013.java b/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet2013.java
index ccffa6f59e..92bf8dc217 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet2013.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet2013.java
@@ -17,16 +17,15 @@
package org.apache.poi.ss.formula.functions;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests WeekNum() as loaded from a test data 2013 excel spreadsheet.<p>
*/
public class TestWeekNumFunctionsFromSpreadsheet2013 extends BaseTestFunctionsFromSpreadsheet {
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
//Only open this file with Excel 2013 to keep binary specific to that version
return data(TestWeekNumFunctionsFromSpreadsheet2013.class, "WeekNumFunctionTestCaseData2013.xls");
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestWeekdayFunc.java b/src/testcases/org/apache/poi/ss/formula/functions/TestWeekdayFunc.java
index a3d9511d19..dbcd5439b8 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestWeekdayFunc.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestWeekdayFunc.java
@@ -19,9 +19,9 @@ package org.apache.poi.ss.formula.functions;
import org.apache.poi.ss.formula.eval.*;
import org.apache.poi.util.StringUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests WEEKDAY(serial_number[, return_type]) excep function
@@ -29,58 +29,58 @@ import static org.junit.Assert.*;
*/
public class TestWeekdayFunc {
private static final double TOLERANCE = 0.001;
-
+
private void assertEvaluateEquals(double expected, double serial_number) {
String formula = "WEEKDAY(" + serial_number + ")";
ValueEval[] args = new ValueEval[] { new NumberEval(serial_number) };
NumberEval result = (NumberEval) WeekdayFunc.instance.evaluate(args, 0, 0);
- assertEquals(formula, expected, result.getNumberValue(), TOLERANCE);
+ assertEquals(expected, result.getNumberValue(), TOLERANCE, formula);
}
private void assertEvaluateEquals(double expected, double serial_number, double return_type) {
String formula = "WEEKDAY(" + serial_number + ", " + return_type + ")";
ValueEval[] args = new ValueEval[] { new NumberEval(serial_number), new NumberEval(return_type) };
NumberEval result = (NumberEval) WeekdayFunc.instance.evaluate(args, 0, 0);
- assertEquals(formula, expected, result.getNumberValue(), TOLERANCE);
+ assertEquals(expected, result.getNumberValue(), TOLERANCE, formula);
}
-
+
@Test
- public void testEvaluate() throws Exception {
+ public void testEvaluate() {
assertEvaluateEquals(2.0, 1.0);
assertEvaluateEquals(2.0, 1.0, 1.0);
assertEvaluateEquals(1.0, 1.0, 2.0);
assertEvaluateEquals(0.0, 1.0, 3.0);
assertEvaluateEquals(1.0, 1.0, 11.0);
- assertEvaluateEquals(7.0, 1.0, 12.0);
- assertEvaluateEquals(6.0, 1.0, 13.0);
- assertEvaluateEquals(5.0, 1.0, 14.0);
- assertEvaluateEquals(4.0, 1.0, 15.0);
- assertEvaluateEquals(3.0, 1.0, 16.0);
- assertEvaluateEquals(2.0, 1.0, 17.0);
+ assertEvaluateEquals(7.0, 1.0, 12.0);
+ assertEvaluateEquals(6.0, 1.0, 13.0);
+ assertEvaluateEquals(5.0, 1.0, 14.0);
+ assertEvaluateEquals(4.0, 1.0, 15.0);
+ assertEvaluateEquals(3.0, 1.0, 16.0);
+ assertEvaluateEquals(2.0, 1.0, 17.0);
+
-
- assertEvaluateEquals(3.0, 39448.0);
- assertEvaluateEquals(3.0, 39448.0, 1.0);
- assertEvaluateEquals(2.0, 39448.0, 2.0);
- assertEvaluateEquals(1.0, 39448.0, 3.0);
- assertEvaluateEquals(2.0, 39448.0, 11.0);
- assertEvaluateEquals(1.0, 39448.0, 12.0);
- assertEvaluateEquals(7.0, 39448.0, 13.0);
- assertEvaluateEquals(6.0, 39448.0, 14.0);
- assertEvaluateEquals(5.0, 39448.0, 15.0);
- assertEvaluateEquals(4.0, 39448.0, 16.0);
- assertEvaluateEquals(3.0, 39448.0, 17.0);
+ assertEvaluateEquals(3.0, 39448.0);
+ assertEvaluateEquals(3.0, 39448.0, 1.0);
+ assertEvaluateEquals(2.0, 39448.0, 2.0);
+ assertEvaluateEquals(1.0, 39448.0, 3.0);
+ assertEvaluateEquals(2.0, 39448.0, 11.0);
+ assertEvaluateEquals(1.0, 39448.0, 12.0);
+ assertEvaluateEquals(7.0, 39448.0, 13.0);
+ assertEvaluateEquals(6.0, 39448.0, 14.0);
+ assertEvaluateEquals(5.0, 39448.0, 15.0);
+ assertEvaluateEquals(4.0, 39448.0, 16.0);
+ assertEvaluateEquals(3.0, 39448.0, 17.0);
}
// for testing invalid invocations
private void assertEvaluateEquals(String message, ErrorEval expected, ValueEval... args) {
String formula = "WEEKDAY(" + StringUtil.join(args, ", ") + ")";
ValueEval result = WeekdayFunc.instance.evaluate(args, 0, 0);
- assertEquals(formula + ": " + message, expected, result);
+ assertEquals(expected, result, formula + ": " + message);
}
@Test
- public void testEvaluateInvalid() throws Exception {
+ public void testEvaluateInvalid() {
assertEvaluateEquals("no args", ErrorEval.VALUE_INVALID);
assertEvaluateEquals("too many args", ErrorEval.VALUE_INVALID, new NumberEval(1.0), new NumberEval(1.0), new NumberEval(1.0));
assertEvaluateEquals("negative date", ErrorEval.NUM_ERROR, new NumberEval(-1.0));
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestXYNumericFunction.java b/src/testcases/org/apache/poi/ss/formula/functions/TestXYNumericFunction.java
index 1c8f439ce8..b191bb4cfd 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestXYNumericFunction.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestXYNumericFunction.java
@@ -17,12 +17,12 @@
package org.apache.poi.ss.formula.functions;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for Excel functions SUMX2MY2(), SUMX2PY2(), SUMXMY2()
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/AllFormulaTests.java b/src/testcases/org/apache/poi/ss/formula/ptg/AllFormulaTests.java
deleted file mode 100644
index 93797a74f5..0000000000
--- a/src/testcases/org/apache/poi/ss/formula/ptg/AllFormulaTests.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula.ptg;
-
-import org.apache.poi.ss.formula.TestSheetNameFormatter;
-import org.apache.poi.ss.formula.eval.AllFormulaEvalTests;
-import org.apache.poi.ss.formula.function.AllFormulaFunctionTests;
-import org.apache.poi.ss.formula.functions.AllIndividualFunctionEvaluationTests;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for <tt>org.apache.poi.hssf.record.formula</tt>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- AllFormulaEvalTests.class,
- AllFormulaFunctionTests.class,
- AllIndividualFunctionEvaluationTests.class,
- TestArea3DPtg.class,
- TestAreaErrPtg.class,
- TestAreaPtg.class,
- TestArrayPtg.class,
- TestAttrPtg.class,
- TestErrPtg.class,
- TestExternalFunctionFormulas.class,
- //TestFormulaShifter.class, //converted to junit4
- TestFuncPtg.class,
- TestFuncVarPtg.class,
- TestIntersectionPtg.class,
- TestPercentPtg.class,
- TestRangePtg.class,
- TestRef3DPtg.class,
- TestReferencePtg.class,
- TestSheetNameFormatter.class,
- TestUnionPtg.class
-})
-public class AllFormulaTests {
-}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java
index e4b73a3de4..c7a618812f 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java
@@ -17,10 +17,11 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.poi.util.LittleEndianOutput;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestAbstractFunctionPtg {
@@ -32,14 +33,14 @@ public class TestAbstractFunctionPtg {
assertEquals(255, ptg.getNumberOfOperands());
}
- @Test(expected=RuntimeException.class)
+ @Test
public void testInvalidFunctionIndex() {
- new FunctionPtg(40000, 2, null, 255);
+ assertThrows(RuntimeException.class, () -> new FunctionPtg(40000, 2, null, 255));
}
- @Test(expected=RuntimeException.class)
+ @Test
public void testInvalidRuntimeClass() {
- new FunctionPtg(1, 300, null, 255);
+ assertThrows(RuntimeException.class, () -> new FunctionPtg(1, 300, null, 255));
}
private static class FunctionPtg extends AbstractFunctionPtg {
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestArea3DPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestArea3DPtg.java
index 481d7c5051..9e89a4e9f0 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestArea3DPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestArea3DPtg.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for Area3DPtg
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaErrPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaErrPtg.java
index 3d04da1db5..ab946e5953 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaErrPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaErrPtg.java
@@ -17,12 +17,12 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link AreaErrPtg}.
@@ -34,8 +34,8 @@ public final class TestAreaErrPtg extends BaseTestPtg {
@Test
public void testReading() throws IOException {
try (HSSFWorkbook workbook = loadWorkbook("AreaErrPtg.xls")) {
- assertEquals("Wrong formula string for area error", "SUM(#REF!)",
- workbook.getSheetAt(0).getRow(0).getCell(2).getCellFormula());
+ assertEquals("SUM(#REF!)", workbook.getSheetAt(0).getRow(0).getCell(2).getCellFormula(),
+ "Wrong formula string for area error");
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java
index d0cdb507c1..7c09db8f89 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java
@@ -18,14 +18,13 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.model.HSSFFormulaParser;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.AreaReference;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link AreaPtg}.
@@ -35,7 +34,7 @@ public final class TestAreaPtg {
AreaPtg relative;
AreaPtg absolute;
- @Before
+ @BeforeEach
public void setUp() {
short firstRow=5;
short lastRow=13;
@@ -50,11 +49,11 @@ public final class TestAreaPtg {
AreaPtg ptg = new AreaPtg(new AreaReference("A$1:$B5", SpreadsheetVersion.EXCEL2007));
assertEquals("A$1:$B5", ptg.toFormulaString());
ptg.setFirstColumn(3);
- assertEquals("Area Ptg should not implicitly re-sort itself (except during construction)",
- "D$1:$B5", ptg.toFormulaString());
+ assertEquals("D$1:$B5", ptg.toFormulaString(),
+ "Area Ptg should not implicitly re-sort itself (except during construction)");
ptg.sortTopLeftToBottomRight();
- assertEquals("Area Ptg should restore itself to top-left to lower-right order when explicitly asked",
- "$B$1:D5", ptg.toFormulaString());
+ assertEquals("$B$1:D5", ptg.toFormulaString(),
+ "Area Ptg should restore itself to top-left to lower-right order when explicitly asked");
}
@Test
@@ -70,10 +69,11 @@ public final class TestAreaPtg {
}
private void validateReference(boolean abs, AreaPtg ref) {
- assertEquals("First column reference is not "+(abs?"absolute":"relative"),abs,!ref.isFirstColRelative());
- assertEquals("Last column reference is not "+(abs?"absolute":"relative"),abs,!ref.isLastColRelative());
- assertEquals("First row reference is not "+(abs?"absolute":"relative"),abs,!ref.isFirstRowRelative());
- assertEquals("Last row reference is not "+(abs?"absolute":"relative"),abs,!ref.isLastRowRelative());
+ String isWrong = " reference is not "+(abs?"absolute":"relative");
+ assertEquals(abs,!ref.isFirstColRelative(),"First column" + isWrong);
+ assertEquals(abs,!ref.isLastColRelative(), "Last column" + isWrong);
+ assertEquals(abs,!ref.isFirstRowRelative(),"First row" + isWrong);
+ assertEquals(abs,!ref.isLastRowRelative(), "Last row" + isWrong);
}
@@ -93,20 +93,20 @@ public final class TestAreaPtg {
AreaPtg sca3 = new AreaPtg(5, 5, 7, 7, true, false, true, false);
AreaPtg sca4 = new AreaPtg(5, 5, 7, 7, false, true, false, true);
- assertEquals("first rel., last abs.", "G5:$H$6", sca1.toFormulaString());
- assertEquals("first abs., last rel.", "$G$5:H6", sca2.toFormulaString());
- assertEquals("first rel., last abs.", "H6:$H$6", sca3.toFormulaString());
- assertEquals("first abs., last rel.", "$H$6:H6", sca4.toFormulaString());
+ assertEquals("G5:$H$6", sca1.toFormulaString(), "first rel., last abs.");
+ assertEquals("$G$5:H6", sca2.toFormulaString(), "first abs., last rel.");
+ assertEquals("H6:$H$6", sca3.toFormulaString(), "first rel., last abs.");
+ assertEquals("$H$6:H6", sca4.toFormulaString(), "first abs., last rel.");
AreaPtg cla1 = cloneArea(sca1);
AreaPtg cla2 = cloneArea(sca2);
AreaPtg cla3 = cloneArea(sca3);
AreaPtg cla4 = cloneArea(sca4);
- assertEquals("first rel., last abs.", "G5:$H$6", cla1.toFormulaString());
- assertEquals("first abs., last rel.", "$G$5:H6", cla2.toFormulaString());
- assertEquals("first rel., last abs.", "H6:$H$6", cla3.toFormulaString());
- assertEquals("first abs., last rel.", "$H$6:H6", cla4.toFormulaString());
+ assertEquals("G5:$H$6", cla1.toFormulaString(), "first rel., last abs.");
+ assertEquals("$G$5:H6", cla2.toFormulaString(), "first abs., last rel.");
+ assertEquals("H6:$H$6", cla3.toFormulaString(), "first rel., last abs.");
+ assertEquals("$H$6:H6", cla4.toFormulaString(), "first abs., last rel.");
}
private AreaPtg cloneArea(AreaPtg a) {
@@ -121,18 +121,17 @@ public final class TestAreaPtg {
String formula1="SUM($E$5:$E$6)";
String expectedFormula1="SUM($F$5:$F$6)";
String newFormula1 = shiftAllColumnsBy1(formula1);
- assertEquals("Absolute references changed", expectedFormula1, newFormula1);
+ assertEquals(expectedFormula1, newFormula1, "Absolute references changed");
String formula2="SUM(E5:E6)";
String expectedFormula2="SUM(F5:F6)";
String newFormula2 = shiftAllColumnsBy1(formula2);
- assertEquals("Relative references changed", expectedFormula2, newFormula2);
+ assertEquals(expectedFormula2, newFormula2, "Relative references changed");
}
private static String shiftAllColumnsBy1(String formula) {
int letUsShiftColumn1By1Column=1;
- HSSFWorkbook wb = null;
- Ptg[] ptgs = HSSFFormulaParser.parse(formula, wb);
+ Ptg[] ptgs = HSSFFormulaParser.parse(formula, null);
for (Ptg ptg : ptgs) {
if (ptg instanceof AreaPtg )
{
@@ -141,6 +140,6 @@ public final class TestAreaPtg {
aptg.setLastColumn((short)(aptg.getLastColumn()+letUsShiftColumn1By1Column));
}
}
- return HSSFFormulaParser.toFormulaString(wb, ptgs);
+ return HSSFFormulaParser.toFormulaString(null, ptgs);
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java
index 170c06719b..79114a6f8a 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java
@@ -17,16 +17,16 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
import org.apache.poi.util.LittleEndianInput;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for <tt>ArrayPtg</tt>
@@ -74,7 +74,7 @@ public final class TestArrayPtg {
byte[] outBuf = new byte[ENCODED_CONSTANT_DATA.length];
ptg.writeTokenValueBytes(new LittleEndianByteArrayOutputStream(outBuf, 0));
- assertNotEquals("Identified bug 42564b", 4, outBuf[0]);
+ assertNotEquals(4, outBuf[0], "Identified bug 42564b");
assertArrayEquals(ENCODED_CONSTANT_DATA, outBuf);
}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestAttrPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestAttrPtg.java
index d957a956aa..5d96832181 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestAttrPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestAttrPtg.java
@@ -17,12 +17,12 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndianInput;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link AttrPtg}.
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestErrPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestErrPtg.java
index 0ff6ad78b6..c9cf488736 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestErrPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestErrPtg.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link ErrPtg}.
@@ -36,8 +36,8 @@ public final class TestErrPtg extends BaseTestPtg {
public void testReading() throws IOException {
try (HSSFWorkbook workbook = loadWorkbook("ErrPtg.xls")) {
HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(0);
- assertEquals("Wrong cell value", 4.0, cell.getNumericCellValue(), 0.0);
- assertEquals("Wrong cell formula", "ERROR.TYPE(#REF!)", cell.getCellFormula());
+ assertEquals(4.0, cell.getNumericCellValue(), 0.0, "Wrong cell value");
+ assertEquals("ERROR.TYPE(#REF!)", cell.getCellFormula(), "Wrong cell formula");
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalFunctionFormulas.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalFunctionFormulas.java
index bb3220743c..8cc8014a32 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalFunctionFormulas.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalFunctionFormulas.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.HSSFFormulaParser;
@@ -26,7 +26,7 @@ import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
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 functions from external workbooks (e.g. YEARFRAC).
@@ -34,27 +34,27 @@ import org.junit.Test;
public final class TestExternalFunctionFormulas {
/**
- * tests <tt>NameXPtg.toFormulaString(Workbook)</tt> and logic in Workbook below that
+ * tests <tt>NameXPtg.toFormulaString(Workbook)</tt> and logic in Workbook below that
*/
@Test
public void testReadFormulaContainingExternalFunction() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
-
+
String expectedFormula = "YEARFRAC(B1,C1)";
HSSFSheet sht = wb.getSheetAt(0);
String cellFormula = sht.getRow(0).getCell(0).getCellFormula();
assertEquals(expectedFormula, cellFormula);
-
+
wb.close();
}
-
+
@Test
public void testParse() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
Ptg[] ptgs = HSSFFormulaParser.parse("YEARFRAC(B1,C1)", wb);
assertEquals(4, ptgs.length);
assertEquals(NameXPtg.class, ptgs[0].getClass());
-
+
wb.getSheetAt(0).getRow(0).createCell(6).setCellFormula("YEARFRAC(C1,B1)");
// if (false) {
// // In case you fancy checking in excel
@@ -70,7 +70,7 @@ public final class TestExternalFunctionFormulas {
// }
wb.close();
}
-
+
@Test
public void testEvaluate() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
@@ -84,7 +84,7 @@ public final class TestExternalFunctionFormulas {
wb.close();
}
- private static void confirmCellEval(HSSFSheet sheet, int rowIx, int colIx,
+ private static void confirmCellEval(HSSFSheet sheet, int rowIx, int colIx,
HSSFFormulaEvaluator fe, String expectedFormula, double expectedResult) {
HSSFCell cell = sheet.getRow(rowIx).getCell(colIx);
assertEquals(expectedFormula, cell.getCellFormula());
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java
index c70e5d63c9..7974f57a01 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java
@@ -18,8 +18,8 @@
package org.apache.poi.ss.formula.ptg;
-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.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFCell;
@@ -27,7 +27,7 @@ import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFName;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellReference;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for proper calculation of named ranges from external workbooks.
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncPtg.java
index fdd9a8c574..2b3b9415a0 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncPtg.java
@@ -17,10 +17,10 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Make sure the FuncPtg performs as expected
@@ -33,10 +33,10 @@ public final class TestFuncPtg {
byte[] fakeData = { 0x20, 0x00,};
FuncPtg ptg = FuncPtg.create(TestcaseRecordInputStream.createLittleEndian(fakeData) );
- assertEquals( "Len formula index is not 32(20H)", 0x20, ptg.getFunctionIndex() );
- assertEquals( "Number of operands in the len formula", 1, ptg.getNumberOfOperands() );
- assertEquals( "Function Name", "LEN", ptg.getName() );
- assertEquals( "Ptg Size", 3, ptg.getSize() );
+ assertEquals( 0x20, ptg.getFunctionIndex(), "Len formula index is not 32(20H)" );
+ assertEquals( 1, ptg.getNumberOfOperands(), "Number of operands in the len formula" );
+ assertEquals( "LEN", ptg.getName(), "Function Name" );
+ assertEquals( 3, ptg.getSize(), "Ptg Size" );
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncVarPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncVarPtg.java
index 62c5a125f0..9b5891bb90 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncVarPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestFuncVarPtg.java
@@ -17,12 +17,12 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* @author Josh Micich
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestIntersectionPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestIntersectionPtg.java
index 729920cb8a..a022c935b7 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestIntersectionPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestIntersectionPtg.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link IntersectionPtg}.
@@ -36,8 +36,8 @@ public final class TestIntersectionPtg extends BaseTestPtg {
public void testReading() throws IOException {
try (HSSFWorkbook workbook = loadWorkbook("IntersectionPtg.xls")) {
HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2);
- assertEquals("Wrong cell value", 5.0, cell.getNumericCellValue(), 0.0);
- assertEquals("Wrong cell formula", "SUM(A1:B2 B2:C3)", cell.getCellFormula());
+ assertEquals(5.0, cell.getNumericCellValue(), 0.0, "Wrong cell value");
+ assertEquals("SUM(A1:B2 B2:C3)", cell.getCellFormula(), "Wrong cell formula");
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestPercentPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestPercentPtg.java
index 4b69d0743b..f6e658c162 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestPercentPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestPercentPtg.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link PercentPtg}.
@@ -37,12 +37,12 @@ public final class TestPercentPtg extends BaseTestPtg {
try (HSSFWorkbook workbook = loadWorkbook("PercentPtg.xls")) {
HSSFSheet sheet = workbook.getSheetAt(0);
- assertEquals("Wrong numeric value for original number", 53000.0,
- sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0);
- assertEquals("Wrong numeric value for percent formula result", 5300.0,
- sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0);
- assertEquals("Wrong formula string for percent formula", "A1*10%",
- sheet.getRow(1).getCell(0).getCellFormula());
+ assertEquals(53000.0, sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0,
+ "Wrong numeric value for original number");
+ assertEquals(5300.0, sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0,
+ "Wrong numeric value for percent formula result");
+ assertEquals("A1*10%", sheet.getRow(1).getCell(0).getCellFormula(),
+ "Wrong formula string for percent formula");
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestRangePtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestRangePtg.java
index 5389538ab2..8d9b41d555 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestRangePtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestRangePtg.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link RangePtg}.
@@ -36,8 +36,8 @@ public final class TestRangePtg extends BaseTestPtg {
public void testReading() throws IOException {
try (HSSFWorkbook workbook = loadWorkbook("RangePtg.xls")) {
HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(1);
- assertEquals("Wrong cell value", 10.0, cell.getNumericCellValue(), 0.0);
- assertEquals("Wrong cell formula", "SUM(pineapple:B2)", cell.getCellFormula());
+ assertEquals(10.0, cell.getNumericCellValue(), 0.0, "Wrong cell value");
+ assertEquals("SUM(pineapple:B2)", cell.getCellFormula(), "Wrong cell formula");
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestRef3DPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestRef3DPtg.java
index 04de2cb6e3..b510cab68c 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestRef3DPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestRef3DPtg.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for Ref3DPtg
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java
index 00c225be15..acc2d6cf50 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+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.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.LittleEndianInput;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link RefPtg}.
@@ -43,42 +43,29 @@ public final class TestReferencePtg {
HSSFSheet sheet = workbook.getSheetAt(0);
// First row
- assertEquals("Wrong numeric value for original number", 55.0,
- sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0);
- assertEquals("Wrong numeric value for referemce", 55.0,
- sheet.getRow(0).getCell(1).getNumericCellValue(), 0.0);
- assertEquals("Wrong formula string for reference", "A1",
- sheet.getRow(0).getCell(1).getCellFormula());
+ assertEquals(55.0, sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0,
+ "Wrong numeric value for original number");
+ assertEquals(55.0, sheet.getRow(0).getCell(1).getNumericCellValue(), 0.0,
+ "Wrong numeric value for referemce");
+ assertEquals("A1", sheet.getRow(0).getCell(1).getCellFormula(), "Wrong formula string for reference");
// Now moving over the 2**15 boundary
// (Remember that excel row (n) is poi row (n-1)
- assertEquals("Wrong numeric value for original number", 32767.0,
- sheet.getRow(32766).getCell(0).getNumericCellValue(), 0.0);
- assertEquals("Wrong numeric value for referemce", 32767.0,
- sheet.getRow(32766).getCell(1).getNumericCellValue(), 0.0);
- assertEquals("Wrong formula string for reference", "A32767",
- sheet.getRow(32766).getCell(1).getCellFormula());
-
- assertEquals("Wrong numeric value for original number", 32768.0,
- sheet.getRow(32767).getCell(0).getNumericCellValue(), 0.0);
- assertEquals("Wrong numeric value for referemce", 32768.0,
- sheet.getRow(32767).getCell(1).getNumericCellValue(), 0.0);
- assertEquals("Wrong formula string for reference", "A32768",
- sheet.getRow(32767).getCell(1).getCellFormula());
-
- assertEquals("Wrong numeric value for original number", 32769.0,
- sheet.getRow(32768).getCell(0).getNumericCellValue(), 0.0);
- assertEquals("Wrong numeric value for referemce", 32769.0,
- sheet.getRow(32768).getCell(1).getNumericCellValue(), 0.0);
- assertEquals("Wrong formula string for reference", "A32769",
- sheet.getRow(32768).getCell(1).getCellFormula());
-
- assertEquals("Wrong numeric value for original number", 32770.0,
- sheet.getRow(32769).getCell(0).getNumericCellValue(), 0.0);
- assertEquals("Wrong numeric value for referemce", 32770.0,
- sheet.getRow(32769).getCell(1).getNumericCellValue(), 0.0);
- assertEquals("Wrong formula string for reference", "A32770",
- sheet.getRow(32769).getCell(1).getCellFormula());
+ assertEquals(32767.0, sheet.getRow(32766).getCell(0).getNumericCellValue(), 0.0, "Wrong numeric value for original number");
+ assertEquals(32767.0, sheet.getRow(32766).getCell(1).getNumericCellValue(), 0.0, "Wrong numeric value for referemce");
+ assertEquals("A32767", sheet.getRow(32766).getCell(1).getCellFormula(), "Wrong formula string for reference");
+
+ assertEquals(32768.0, sheet.getRow(32767).getCell(0).getNumericCellValue(), 0.0, "Wrong numeric value for original number");
+ assertEquals(32768.0, sheet.getRow(32767).getCell(1).getNumericCellValue(), 0.0, "Wrong numeric value for referemce");
+ assertEquals("A32768", sheet.getRow(32767).getCell(1).getCellFormula(), "Wrong formula string for reference");
+
+ assertEquals(32769.0, sheet.getRow(32768).getCell(0).getNumericCellValue(), 0.0, "Wrong numeric value for original number");
+ assertEquals(32769.0, sheet.getRow(32768).getCell(1).getNumericCellValue(), 0.0, "Wrong numeric value for referemce");
+ assertEquals("A32769", sheet.getRow(32768).getCell(1).getCellFormula(), "Wrong formula string for reference");
+
+ assertEquals(32770.0, sheet.getRow(32769).getCell(0).getNumericCellValue(), 0.0, "Wrong numeric value for original number");
+ assertEquals(32770.0, sheet.getRow(32769).getCell(1).getNumericCellValue(), 0.0, "Wrong numeric value for referemce");
+ assertEquals("A32770", sheet.getRow(32769).getCell(1).getCellFormula(), "Wrong formula string for reference");
}
@Test
@@ -98,7 +85,7 @@ public final class TestReferencePtg {
Ptg[] ptgs = Ptg.readTokens(tRefN_data.length, in);
byte[] outData = new byte[5];
Ptg.serializePtgs(ptgs, outData, 0);
- assertNotEquals("Identified bug 45091", 0x24, outData[0]);
+ assertNotEquals(0x24, outData[0], "Identified bug 45091");
assertArrayEquals(tRefN_data, outData);
}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestUnionPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestUnionPtg.java
index 446700f78d..dd2c423230 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestUnionPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestUnionPtg.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.ptg;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link UnionPtg}.
@@ -36,8 +36,8 @@ public final class TestUnionPtg extends BaseTestPtg {
public void testReading() throws IOException {
try (HSSFWorkbook workbook = loadWorkbook("UnionPtg.xls")) {
HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2);
- assertEquals("Wrong cell value", 24.0, cell.getNumericCellValue(), 0.0);
- assertEquals("Wrong cell formula", "SUM(A1:B2,B2:C3)", cell.getCellFormula());
+ assertEquals(24.0, cell.getNumericCellValue(), 0.0, "Wrong cell value");
+ assertEquals("SUM(A1:B2,B2:C3)", cell.getCellFormula(), "Wrong cell formula");
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/udf/BaseTestUDFFinder.java b/src/testcases/org/apache/poi/ss/formula/udf/BaseTestUDFFinder.java
index ab3aa987c7..207e196ae3 100644
--- a/src/testcases/org/apache/poi/ss/formula/udf/BaseTestUDFFinder.java
+++ b/src/testcases/org/apache/poi/ss/formula/udf/BaseTestUDFFinder.java
@@ -16,11 +16,11 @@
==================================================================== */
package org.apache.poi.ss.formula.udf;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.apache.poi.ss.formula.functions.FreeRefFunction;
-import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.ss.formula.functions.FreeRefFunction;
public class BaseTestUDFFinder {
diff --git a/src/testcases/org/apache/poi/ss/formula/udf/TestAggregatingUDFFinder.java b/src/testcases/org/apache/poi/ss/formula/udf/TestAggregatingUDFFinder.java
index 88d7e84fff..93b90a9f1b 100644
--- a/src/testcases/org/apache/poi/ss/formula/udf/TestAggregatingUDFFinder.java
+++ b/src/testcases/org/apache/poi/ss/formula/udf/TestAggregatingUDFFinder.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.udf;
import org.apache.poi.ss.formula.atp.AnalysisToolPak;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestAggregatingUDFFinder extends BaseTestUDFFinder {
diff --git a/src/testcases/org/apache/poi/ss/formula/udf/TestDefaultUDFFinder.java b/src/testcases/org/apache/poi/ss/formula/udf/TestDefaultUDFFinder.java
index 010b19d4e2..0b166e8509 100644
--- a/src/testcases/org/apache/poi/ss/formula/udf/TestDefaultUDFFinder.java
+++ b/src/testcases/org/apache/poi/ss/formula/udf/TestDefaultUDFFinder.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.formula.udf;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestDefaultUDFFinder extends BaseTestUDFFinder {
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBorderStyle.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBorderStyle.java
index 4a7c3e1784..ca30b3eb8d 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBorderStyle.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBorderStyle.java
@@ -16,23 +16,23 @@
2012 - Alfresco Software, Ltd.
Alfresco Software has modified source of this file
- The details of changes as svn diff can be found in svn at location root/projects/3rd-party/src
+ The details of changes as svn diff can be found in svn at location root/projects/3rd-party/src
==================================================================== */
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.ss.ITestDataProvider;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests of {@link BorderStyle}
*/
public abstract class BaseTestBorderStyle {
-
+
private final ITestDataProvider _testDataProvider;
protected BaseTestBorderStyle(ITestDataProvider testDataProvider) {
@@ -48,7 +48,7 @@ public abstract class BaseTestBorderStyle {
String ext = _testDataProvider.getStandardFileNameExtension();
Workbook wb = _testDataProvider.openSampleWorkbook("59264."+ext);
Sheet sh = wb.getSheetAt(0);
-
+
assertBorderStyleEquals(BorderStyle.NONE, getDiagonalCell(sh, 0));
assertBorderStyleEquals(BorderStyle.THIN, getDiagonalCell(sh, 1));
assertBorderStyleEquals(BorderStyle.MEDIUM, getDiagonalCell(sh, 2));
@@ -63,14 +63,14 @@ public abstract class BaseTestBorderStyle {
assertBorderStyleEquals(BorderStyle.DASH_DOT_DOT, getDiagonalCell(sh, 11));
assertBorderStyleEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, getDiagonalCell(sh, 12));
assertBorderStyleEquals(BorderStyle.SLANTED_DASH_DOT, getDiagonalCell(sh, 13));
-
+
wb.close();
}
-
+
private Cell getDiagonalCell(Sheet sheet, int n) {
return sheet.getRow(n).getCell(n);
}
-
+
protected void assertBorderStyleEquals(BorderStyle expected, Cell cell) {
CellStyle style = cell.getCellStyle();
assertEquals(expected, style.getBorderTop());
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
index cb026e2ff5..91325fee38 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
@@ -17,12 +17,13 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.awt.font.FontRenderContext;
import java.awt.font.TextAttribute;
@@ -44,9 +45,8 @@ import org.apache.poi.ss.util.PaneInformation;
import org.apache.poi.ss.util.SheetUtil;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-import org.junit.Assume;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* A base class for bugzilla issues that can be described in terms of common ss interfaces.
@@ -74,9 +74,7 @@ public abstract class BaseTestBugzillaIssues {
private static void assertAlmostEquals(double expected, double actual, float factor) {
double diff = Math.abs(expected - actual);
double fuzz = expected * factor;
- if (diff > fuzz) {
- fail(actual + " not within " + fuzz + " of " + expected);
- }
+ assertTrue(diff <= fuzz, actual + " not within " + fuzz + " of " + expected);
}
/**
@@ -160,14 +158,14 @@ public abstract class BaseTestBugzillaIssues {
Sheet clone = wb.cloneSheet(0);
int originalMerged = template.getNumMergedRegions();
- assertEquals("2 merged regions", 2, originalMerged);
+ assertEquals(2, originalMerged, "2 merged regions");
//remove merged regions from clone
for (int i = template.getNumMergedRegions() - 1; i >= 0; i--) {
clone.removeMergedRegion(i);
}
- assertEquals("Original Sheet's Merged Regions were removed", originalMerged, template.getNumMergedRegions());
+ assertEquals(originalMerged, template.getNumMergedRegions(), "Original Sheet's Merged Regions were removed");
//check if template's merged regions are OK
if (template.getNumMergedRegions() > 0) {
// fetch the first merged region...EXCEPTION OCCURS HERE
@@ -352,13 +350,11 @@ public abstract class BaseTestBugzillaIssues {
fmla = createFunction(name, ssVersion.getMaxFunctionArgs());
cell.setCellFormula(fmla);
- try {
- fmla = createFunction(name, ssVersion.getMaxFunctionArgs() + 1);
- cell.setCellFormula(fmla);
- fail("Expected FormulaParseException");
- } catch (FormulaParseException e) {
- assertTrue(e.getMessage().startsWith("Too many arguments to function '" + name + "'"));
- }
+ FormulaParseException e = assertThrows(FormulaParseException.class, () -> {
+ String fmla2 = createFunction(name, ssVersion.getMaxFunctionArgs() + 1);
+ cell.setCellFormula(fmla2);
+ });
+ assertTrue(e.getMessage().startsWith("Too many arguments to function '" + name + "'"));
}
}
}
@@ -396,13 +392,11 @@ public abstract class BaseTestBugzillaIssues {
// autoSize will fail if required fonts are not installed, skip this test then
Font font = wb.getFontAt(cell0.getCellStyle().getFontIndex());
- Assume.assumeTrue("Cannot verify autoSizeColumn() because the necessary Fonts are not installed on this machine: " + font,
- SheetUtil.canComputeColumnWidth(font));
+ assumeTrue(SheetUtil.canComputeColumnWidth(font),
+ "Cannot verify autoSizeColumn() because the necessary Fonts are not installed on this machine: " + font);
- assertEquals("Expecting no indentation in this test",
- 0, cell0.getCellStyle().getIndention());
- assertEquals("Expecting no rotation in this test",
- 0, cell0.getCellStyle().getRotation());
+ assertEquals(0, cell0.getCellStyle().getIndention(), "Expecting no indentation in this test");
+ assertEquals(0, cell0.getCellStyle().getRotation(), "Expecting no rotation in this test");
// check computing size up to a large size
// StringBuilder b = new StringBuilder();
@@ -417,16 +411,16 @@ public abstract class BaseTestBugzillaIssues {
String info = widthManual + "/" + widthBeforeCell + "/" + widthBeforeCol + "/" +
SheetUtil.canComputeColumnWidth(font) + "/" + computeCellWidthFixed(font, "1") + "/" + computeCellWidthFixed(font, "w") + "/" +
computeCellWidthFixed(font, "1w") + "/" + computeCellWidthFixed(font, "0000") + "/" + computeCellWidthFixed(font, longValue);
- assertTrue("Expected to have cell width > 0 when computing manually, but had " + info, widthManual > 0);
- assertTrue("Expected to have cell width > 0 BEFORE auto-size, but had " + info, widthBeforeCell > 0);
- assertTrue("Expected to have column width > 0 BEFORE auto-size, but had " + info, widthBeforeCol > 0);
+ assertTrue(widthManual > 0, "Expected to have cell width > 0 when computing manually, but had " + info);
+ assertTrue(widthBeforeCell > 0, "Expected to have cell width > 0 BEFORE auto-size, but had " + info);
+ assertTrue(widthBeforeCol > 0, "Expected to have column width > 0 BEFORE auto-size, but had " + info);
sheet.autoSizeColumn(0);
double width = SheetUtil.getColumnWidth(sheet, 0, false);
- assertTrue("Expected to have column width > 0 AFTER auto-size, but had " + width, width > 0);
+ assertTrue(width > 0, "Expected to have column width > 0 AFTER auto-size, but had " + width);
width = SheetUtil.getCellWidth(cell0, 8, null, false);
- assertTrue("Expected to have cell width > 0 AFTER auto-size, but had " + width, width > 0);
+ assertTrue(width > 0, "Expected to have cell width > 0 AFTER auto-size, but had " + width);
assertEquals(255 * 256, sheet.getColumnWidth(0)); // maximum column width is 255 characters
sheet.setColumnWidth(0, sheet.getColumnWidth(0)); // Bug 50681 reports exception at this point
@@ -466,11 +460,11 @@ public abstract class BaseTestBugzillaIssues {
double trailingWhitespaceRatio = ((double) leadingWhitespaceColWidth) / noWhitespaceColWidth;
assertGreaterThan("leading whitespace is longer than no whitespace",
- leadingWhitespaceRatio, expectedRatioThreshold);
+ leadingWhitespaceRatio, expectedRatioThreshold);
assertGreaterThan("trailing whitespace is longer than no whitespace",
- trailingWhitespaceRatio, expectedRatioThreshold);
- assertEquals("cells with equal leading and trailing whitespace have equal width",
- leadingWhitespaceColWidth, trailingWhitespaceColWidth);
+ trailingWhitespaceRatio, expectedRatioThreshold);
+ assertEquals(leadingWhitespaceColWidth, trailingWhitespaceColWidth,
+ "cells with equal leading and trailing whitespace have equal width");
}
}
@@ -479,10 +473,7 @@ public abstract class BaseTestBugzillaIssues {
* Test if a > b. Fails if false.
*/
private void assertGreaterThan(String message, double a, double b) {
- if (a <= b) {
- String msg = "Expected: " + a + " > " + b;
- fail(message + ": " + msg);
- }
+ assertTrue(a > b, message + ": " + "Expected: " + a + " > " + b);
}
// FIXME: this function is a self-fulfilling prophecy: this test will always pass as long
@@ -503,7 +494,7 @@ public abstract class BaseTestBugzillaIssues {
TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
double frameWidth = getFrameWidth(layout);
- return ((frameWidth / 1) / 8);
+ return (frameWidth / 8);
}
private double getFrameWidth(TextLayout layout) {
@@ -878,82 +869,67 @@ public abstract class BaseTestBugzillaIssues {
* TODO Fix this to evaluate for XSSF
* TODO Fix this to work at all for HSSF
*/
- @Ignore("Fix this to evaluate for XSSF, Fix this to work at all for HSSF")
+ @Disabled("Fix this to evaluate for XSSF, Fix this to work at all for HSSF")
@Test
public void bug46670() throws IOException {
- Workbook wb1 = _testDataProvider.createWorkbook();
- Sheet s = wb1.createSheet();
- Row r1 = s.createRow(0);
-
-
- // References to try
- String ext = _testDataProvider.getStandardFileNameExtension();
- String refLocal = "'[test."+ext+"]Sheet1'!$A$2";
- String refHttp = "'[http://example.com/test."+ext+"]Sheet1'!$A$2";
- String otherCellText = "In Another Workbook";
-
-
- // Create the references
- Cell c1 = r1.createCell(0, CellType.FORMULA);
- c1.setCellFormula(refLocal);
-
- Cell c2 = r1.createCell(1, CellType.FORMULA);
- c2.setCellFormula(refHttp);
+ try (Workbook wb1 = _testDataProvider.createWorkbook()) {
+ Sheet s = wb1.createSheet();
+ Row r1 = s.createRow(0);
- // Check they were set correctly
- assertEquals(refLocal, c1.getCellFormula());
- assertEquals(refHttp, c2.getCellFormula());
+ // References to try
+ String ext = _testDataProvider.getStandardFileNameExtension();
+ String refLocal = "'[test." + ext + "]Sheet1'!$A$2";
+ String refHttp = "'[http://example.com/test." + ext + "]Sheet1'!$A$2";
+ String otherCellText = "In Another Workbook";
- // Reload, and ensure they were serialised and read correctly
- Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
- wb1.close();
- s = wb2.getSheetAt(0);
- r1 = s.getRow(0);
+ // Create the references
+ r1.createCell(0, CellType.FORMULA).setCellFormula(refLocal);
+ r1.createCell(1, CellType.FORMULA).setCellFormula(refHttp);
- c1 = r1.getCell(0);
- c2 = r1.getCell(1);
- assertEquals(refLocal, c1.getCellFormula());
- assertEquals(refHttp, c2.getCellFormula());
+ // Check they were set correctly
+ assertEquals(refLocal, r1.getCell(0).getCellFormula());
+ assertEquals(refHttp, r1.getCell(1).getCellFormula());
- // Try to evaluate, without giving a way to get at the other file
- try {
- evaluateCell(wb2, c1);
- fail("Shouldn't be able to evaluate without the other file");
- } catch (Exception e) {
- // expected here
- }
- try {
- evaluateCell(wb2, c2);
- fail("Shouldn't be able to evaluate without the other file");
- } catch (Exception e) {
- // expected here
- }
+ // Reload, and ensure they were serialised and read correctly
+ try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
+ s = wb2.getSheetAt(0);
+ r1 = s.getRow(0);
- // Set up references to the other file
- Workbook wb3 = _testDataProvider.createWorkbook();
- wb3.createSheet().createRow(1).createCell(0).setCellValue(otherCellText);
+ final Cell c1 = r1.getCell(0);
+ final Cell c2 = r1.getCell(1);
+ assertEquals(refLocal, c1.getCellFormula());
+ assertEquals(refHttp, c2.getCellFormula());
- Map<String,FormulaEvaluator> evaluators = new HashMap<>();
- evaluators.put(refLocal, wb3.getCreationHelper().createFormulaEvaluator());
- evaluators.put(refHttp, wb3.getCreationHelper().createFormulaEvaluator());
+ // Try to evaluate, without giving a way to get at the other file
+ assertThrows(Exception.class, () -> evaluateCell(wb2, c1),
+ "Shouldn't be able to evaluate without the other file");
+ assertThrows(Exception.class, () -> evaluateCell(wb2, c2),
+ "Shouldn't be able to evaluate without the other file");
- FormulaEvaluator evaluator = wb2.getCreationHelper().createFormulaEvaluator();
- evaluator.setupReferencedWorkbooks(evaluators);
+ // Set up references to the other file
+ try (Workbook wb3 = _testDataProvider.createWorkbook()) {
+ wb3.createSheet().createRow(1).createCell(0).setCellValue(otherCellText);
+ Map<String, FormulaEvaluator> evaluators = new HashMap<>();
+ evaluators.put(refLocal, wb3.getCreationHelper().createFormulaEvaluator());
+ evaluators.put(refHttp, wb3.getCreationHelper().createFormulaEvaluator());
- // Try to evaluate, with the other file
- evaluator.evaluateFormulaCell(c1);
- evaluator.evaluateFormulaCell(c2);
+ FormulaEvaluator evaluator = wb2.getCreationHelper().createFormulaEvaluator();
+ evaluator.setupReferencedWorkbooks(evaluators);
- assertEquals(otherCellText, c1.getStringCellValue());
- assertEquals(otherCellText, c2.getStringCellValue());
+ // Try to evaluate, with the other file
+ evaluator.evaluateFormulaCell(c1);
+ evaluator.evaluateFormulaCell(c2);
- wb3.close();
- wb2.close();
+ assertEquals(otherCellText, c1.getStringCellValue());
+ assertEquals(otherCellText, c2.getStringCellValue());
+ }
+ }
+ }
}
@Test
@@ -1159,36 +1135,16 @@ public abstract class BaseTestBugzillaIssues {
// Different ways of retrieving
assertEquals(1.2, cn.getNumericCellValue(), 0);
- try {
- cn.getRichStringCellValue();
- fail();
- } catch (IllegalStateException e) {
- // expected here
- }
+ assertThrows(IllegalStateException.class, cn::getRichStringCellValue);
assertEquals("Testing", cs.getStringCellValue());
- try {
- cs.getNumericCellValue();
- fail();
- } catch (IllegalStateException e) {
- // expected here
- }
+ assertThrows(IllegalStateException.class, cs::getNumericCellValue);
assertEquals(1.2, cfn.getNumericCellValue(), 0);
- try {
- cfn.getRichStringCellValue();
- fail();
- } catch (IllegalStateException e) {
- // expected here
- }
+ assertThrows(IllegalStateException.class, cfn::getRichStringCellValue);
assertEquals("Testing", cfs.getStringCellValue());
- try {
- cfs.getNumericCellValue();
- fail();
- } catch (IllegalStateException e) {
- // expected here
- }
+ assertThrows(IllegalStateException.class, cfs::getNumericCellValue);
}
}
@@ -1203,8 +1159,8 @@ public abstract class BaseTestBugzillaIssues {
// verify that null-values can be set, this was possible up to 3.11, but broken in 3.12
cell.setCellValue((String) null);
String value = cell.getStringCellValue();
- assertTrue("HSSF will currently return empty string, XSSF/SXSSF will return null, but had: " + value,
- value == null || value.length() == 0);
+ assertTrue(value == null || value.length() == 0,
+ "HSSF will currently return empty string, XSSF/SXSSF will return null, but had: " + value);
cell = row.createCell(1);
cell.setCellFormula("0");
@@ -1213,20 +1169,20 @@ public abstract class BaseTestBugzillaIssues {
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
value = cell.getStringCellValue();
- assertTrue("HSSF will currently return empty string, XSSF/SXSSF will return null, but had: " + value,
- value == null || value.length() == 0);
+ assertTrue(value == null || value.length() == 0,
+ "HSSF will currently return empty string, XSSF/SXSSF will return null, but had: " + value);
// set some value
cell.setCellValue("somevalue");
value = cell.getStringCellValue();
- assertEquals("can set value afterwards: " + value, "somevalue", value);
+ assertEquals("somevalue", value, "can set value afterwards: " + value);
// verify that the null-value is actually set even if there was some value in the cell before
cell.setCellValue((String) null);
value = cell.getStringCellValue();
- assertTrue("HSSF will currently return empty string, XSSF/SXSSF will return null, but had: " + value,
- value == null || value.length() == 0);
+ assertTrue(value == null || value.length() == 0,
+ "HSSF will currently return empty string, XSSF/SXSSF will return null, but had: " + value);
}
}
@@ -1312,12 +1268,7 @@ public abstract class BaseTestBugzillaIssues {
//Row row = worksheet.createRow(i);
//Create cell style
- CellStyle style = null;
- try {
- style = wb.createCellStyle();
- } catch (IllegalStateException e) {
- fail("Failed for row " + i);
- }
+ CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.RIGHT);
if ((wb instanceof HSSFWorkbook)) {
// there are some predefined styles
@@ -1340,12 +1291,8 @@ public abstract class BaseTestBugzillaIssues {
}
// should fail if we try to add more now
- try {
- wb.createCellStyle();
- fail("Should fail after " + maxStyles + " styles, but did not fail");
- } catch (IllegalStateException e) {
- // expected here
- }
+ assertThrows(IllegalStateException.class, wb::createCellStyle,
+ "Should fail after " + maxStyles + " styles, but did not fail");
/*//add column width for appearance sake
worksheet.setColumnWidth(0, 5000);
@@ -1499,7 +1446,7 @@ public abstract class BaseTestBugzillaIssues {
return time() - startTimeMillis;
}
- @Ignore("bug 59393")
+ @Disabled("bug 59393")
@Test
public void bug59393_commentsCanHaveSameAnchor() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
@@ -1580,7 +1527,7 @@ public abstract class BaseTestBugzillaIssues {
}
}
- @Ignore
+ @Disabled
@Test
public void test57929() throws IOException {
// Create a workbook with print areas on 2 sheets
@@ -1599,13 +1546,14 @@ public abstract class BaseTestBugzillaIssues {
wb.setPrintArea(1, "$A$1:$A$1");
// Verify that the changes were made
- assertNull("Sheet0 before write", wb.getPrintArea(0));
- assertEquals("Sheet1 before write", "Sheet1!$A$1:$A$1", wb.getPrintArea(1));
+ assertNull(wb.getPrintArea(0), "Sheet0 before write");
+ assertEquals(wb.getPrintArea(1), "Sheet1 before write", "Sheet1!$A$1:$A$1");
// Verify that the changes are non-volatile
try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb)) {
- assertNull("Sheet0 after write", wb2.getPrintArea(0)); // CURRENTLY FAILS with "Sheet0!$A$1:$C$6"
- assertEquals("Sheet1 after write", "Sheet1!$A$1:$A$1", wb2.getPrintArea(1));
+ // CURRENTLY FAILS with "Sheet0!$A$1:$C$6"
+ assertNull(wb2.getPrintArea(0), "Sheet0 after write");
+ assertEquals(wb2.getPrintArea(1), "Sheet1 after write", "Sheet1!$A$1:$A$1");
}
}
}
@@ -1657,18 +1605,13 @@ public abstract class BaseTestBugzillaIssues {
assertEquals(10, row.getRowNum());
for (Cell cell : row) {
- String cellValue;
- switch (cell.getCellType()) {
- case STRING:
- cellValue = cell.getRichStringCellValue().getString();
- break;
- case FORMULA:
- cellValue = cell.getCellFormula();
- break;
- default:
- fail("unexpected cell type");
- return;
- }
+ CellType ctype = cell.getCellType();
+ assertTrue(ctype == CellType.STRING || ctype == CellType.FORMULA, "unexpected cell type");
+
+ String cellValue = (ctype == CellType.STRING)
+ ? cell.getRichStringCellValue().getString()
+ : cell.getCellFormula();
+
assertNotNull(cellValue);
cellValue = cellValue.isEmpty() ? null : cellValue;
assertNotNull(cellValue);
@@ -1729,11 +1672,11 @@ public abstract class BaseTestBugzillaIssues {
// The name should still refer to the same sheet after the sheets are re-ordered
assertEquals(i % 3, wb.getSheetIndex("Sheet3"));
- assertEquals(nameOnSheet1.getNameName(), "Sheet1", nameOnSheet1.getSheetName());
- assertEquals(nameOnSheet2.getNameName(), "Sheet2", nameOnSheet2.getSheetName());
- assertEquals(nameOnSheet3.getNameName(), "Sheet3", nameOnSheet3.getSheetName());
- assertEquals(name.getNameName(), -1, name.getSheetIndex());
- assertEquals(name.getNameName(), "Sheet2!A1", name.getRefersToFormula());
+ assertEquals("Sheet1", nameOnSheet1.getSheetName());
+ assertEquals("Sheet2", nameOnSheet2.getSheetName());
+ assertEquals("Sheet3", nameOnSheet3.getSheetName());
+ assertEquals(-1, name.getSheetIndex());
+ assertEquals("Sheet2!A1", name.getRefersToFormula());
// make sure the changes to the names stick after writing out the workbook
try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb)) {
@@ -1747,11 +1690,11 @@ public abstract class BaseTestBugzillaIssues {
// Saving the workbook should not change the sheet names
assertEquals(i % 3, wb2.getSheetIndex("Sheet3"));
- assertEquals(nameOnSheet1.getNameName(), "Sheet1", nameOnSheet1.getSheetName());
- assertEquals(nameOnSheet2.getNameName(), "Sheet2", nameOnSheet2.getSheetName());
- assertEquals(nameOnSheet3.getNameName(), "Sheet3", nameOnSheet3.getSheetName());
- assertEquals(name.getNameName(), -1, name.getSheetIndex());
- assertEquals(name.getNameName(), "Sheet2!A1", name.getRefersToFormula());
+ assertEquals("Sheet1", nameOnSheet1.getSheetName());
+ assertEquals("Sheet2", nameOnSheet2.getSheetName());
+ assertEquals("Sheet3", nameOnSheet3.getSheetName());
+ assertEquals(-1, name.getSheetIndex());
+ assertEquals("Sheet2!A1", name.getRefersToFormula());
// Verify names in wb2
nameOnSheet1 = wb2.getName("NameOnSheet1");
@@ -1760,11 +1703,11 @@ public abstract class BaseTestBugzillaIssues {
name = wb2.getName("WorkbookScopedName");
assertEquals(i % 3, wb2.getSheetIndex("Sheet3"));
- assertEquals(nameOnSheet1.getNameName(), "Sheet1", nameOnSheet1.getSheetName());
- assertEquals(nameOnSheet2.getNameName(), "Sheet2", nameOnSheet2.getSheetName());
- assertEquals(nameOnSheet3.getNameName(), "Sheet3", nameOnSheet3.getSheetName());
- assertEquals(name.getNameName(), -1, name.getSheetIndex());
- assertEquals(name.getNameName(), "Sheet2!A1", name.getRefersToFormula());
+ assertEquals("Sheet1", nameOnSheet1.getSheetName());
+ assertEquals("Sheet2", nameOnSheet2.getSheetName());
+ assertEquals("Sheet3", nameOnSheet3.getSheetName());
+ assertEquals(-1, name.getSheetIndex());
+ assertEquals("Sheet2!A1", name.getRefersToFormula());
}
}
}
@@ -1783,20 +1726,24 @@ public abstract class BaseTestBugzillaIssues {
// HSSF has 32/255 limits as part of the Spec, XSSF has no limit in the spec, but Excel applies a 255 length limit!
// more than 255 fail for all
- checkFailures(dataValidation, TEST_256, TEST_32, true);
- checkFailures(dataValidation, TEST_32, TEST_256, true);
+ checkFails(dataValidation, TEST_256, TEST_32);
+ checkFails(dataValidation, TEST_32, TEST_256);
// null does work
- checkFailures(dataValidation, null, null, false);
+ checkPasses(dataValidation, null, null);
// more than 32 title fail for HSSFWorkbook
- checkFailures(dataValidation, TEST_255, TEST_32, wb instanceof HSSFWorkbook);
+ if (wb instanceof HSSFWorkbook) {
+ checkFails(dataValidation, TEST_255, TEST_32);
+ } else {
+ checkPasses(dataValidation, TEST_255, TEST_32);
+ }
// special characters work
- checkFailures(dataValidation, TEST_SPECIAL_TITLE, TEST_SPECIAL, false);
+ checkPasses(dataValidation, TEST_SPECIAL_TITLE, TEST_SPECIAL);
// 32 length title and 255 length text work for both
- checkFailures(dataValidation, TEST_32, TEST_255, false);
+ checkPasses(dataValidation, TEST_32, TEST_255);
dataValidation.setShowErrorBox(false);
sheet.addValidationData(dataValidation);
@@ -1810,20 +1757,14 @@ public abstract class BaseTestBugzillaIssues {
}
}
- private void checkFailures(DataValidation dataValidation, String title, String text, boolean shouldFail) {
- try {
- dataValidation.createPromptBox(title, text);
- assertFalse("Should fail in a length-check, had " + (title == null ? null : title.length()) + " and " + (text == null ? null : text.length()), shouldFail);
- } catch (IllegalStateException e) {
- assertTrue("Should not fail in a length-check, had " + (title == null ? null : title.length()) + " and " + (text == null ? null : text.length()), shouldFail);
- // expected here
- }
- try {
- dataValidation.createErrorBox(title, text);
- assertFalse("Should fail in a length-check, had " + (title == null ? null : title.length()) + " and " + (text == null ? null : text.length()), shouldFail);
- } catch (IllegalStateException e) {
- assertTrue("Should not fail in a length-check, had " + (title == null ? null : title.length()) + " and " + (text == null ? null : text.length()), shouldFail);
- }
+ private void checkFails(DataValidation dataValidation, String title, String text) {
+ assertThrows(IllegalStateException.class, () -> dataValidation.createPromptBox(title, text));
+ assertThrows(IllegalStateException.class, () -> dataValidation.createErrorBox(title, text));
+ }
+
+ private void checkPasses(DataValidation dataValidation, String title, String text) {
+ dataValidation.createPromptBox(title, text);
+ dataValidation.createErrorBox(title, text);
}
@Test
@@ -1836,7 +1777,7 @@ public abstract class BaseTestBugzillaIssues {
DataValidationConstraint constraint = sheet.getDataValidationHelper().createCustomConstraint("A1<>\"\"");
dataValidation = sheet.getDataValidationHelper().createValidation(constraint, headerCell);
- checkFailures(dataValidation, TEST_SPECIAL_TITLE, TEST_SPECIAL, false);
+ checkPasses(dataValidation, TEST_SPECIAL_TITLE, TEST_SPECIAL);
dataValidation.setShowErrorBox(true);
dataValidation.setShowPromptBox(true);
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
index caf976b4f9..d4545857d7 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
@@ -18,12 +18,13 @@
package org.apache.poi.ss.usermodel;
import static org.apache.poi.ss.usermodel.FormulaError.forInt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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 static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -42,9 +43,10 @@ import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
+import org.apache.poi.ss.formula.eval.NotImplementedException;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing implementations of
@@ -198,32 +200,32 @@ public abstract class BaseTestCell {
assertEquals(0, c.getRowIndex());
assertEquals(1, c.getColumnIndex());
c.setCellValue(true);
- assertTrue("B1 value", c.getBooleanCellValue());
+ assertTrue(c.getBooleanCellValue(), "B1 value");
// C1
c = r.createCell(2);
assertEquals(0, c.getRowIndex());
assertEquals(2, c.getColumnIndex());
c.setCellValue(false);
- assertFalse("C1 value", c.getBooleanCellValue());
+ assertFalse(c.getBooleanCellValue(), "C1 value");
// Make sure values are saved and re-read correctly.
try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
s = wb2.getSheet("testSheet1");
r = s.getRow(0);
- assertEquals("Row 1 should have 2 cells", 2, r.getPhysicalNumberOfCells());
+ assertEquals(2, r.getPhysicalNumberOfCells(), "Row 1 should have 2 cells");
c = r.getCell(1);
assertEquals(0, c.getRowIndex());
assertEquals(1, c.getColumnIndex());
assertEquals(CellType.BOOLEAN, c.getCellType());
- assertTrue("B1 value", c.getBooleanCellValue());
+ assertTrue(c.getBooleanCellValue(), "B1 value");
c = r.getCell(2);
assertEquals(0, c.getRowIndex());
assertEquals(2, c.getColumnIndex());
assertEquals(CellType.BOOLEAN, c.getCellType());
- assertFalse("C1 value", c.getBooleanCellValue());
+ assertFalse(c.getBooleanCellValue(), "C1 value");
}
}
}
@@ -246,32 +248,32 @@ public abstract class BaseTestCell {
assertEquals(0, c.getRowIndex());
assertEquals(1, c.getColumnIndex());
c.setCellErrorValue(FormulaError.NULL.getCode());
- assertEquals("B1 value == #NULL!", FormulaError.NULL.getCode(), c.getErrorCellValue());
+ assertEquals(FormulaError.NULL.getCode(), c.getErrorCellValue(), "B1 value == #NULL!");
// C1
c = r.createCell(2);
assertEquals(0, c.getRowIndex());
assertEquals(2, c.getColumnIndex());
c.setCellErrorValue(FormulaError.DIV0.getCode());
- assertEquals("C1 value == #DIV/0!", FormulaError.DIV0.getCode(), c.getErrorCellValue());
+ assertEquals(FormulaError.DIV0.getCode(), c.getErrorCellValue(), "C1 value == #DIV/0!");
try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
s = wb2.getSheet("testSheet1");
r = s.getRow(0);
- assertEquals("Row 1 should have 2 cells", 2, r.getPhysicalNumberOfCells());
+ assertEquals(2, r.getPhysicalNumberOfCells(), "Row 1 should have 2 cells");
c = r.getCell(1);
assertEquals(0, c.getRowIndex());
assertEquals(1, c.getColumnIndex());
assertEquals(CellType.ERROR, c.getCellType());
- assertEquals("B1 value == #NULL!", FormulaError.NULL.getCode(), c.getErrorCellValue());
+ assertEquals(FormulaError.NULL.getCode(), c.getErrorCellValue(), "B1 value == #NULL!");
c = r.getCell(2);
assertEquals(0, c.getRowIndex());
assertEquals(2, c.getColumnIndex());
assertEquals(CellType.ERROR, c.getCellType());
- assertEquals("C1 value == #DIV/0!", FormulaError.DIV0.getCode(), c.getErrorCellValue());
+ assertEquals(FormulaError.DIV0.getCode(), c.getErrorCellValue(), "C1 value == #DIV/0!");
}
}
}
@@ -308,15 +310,15 @@ public abstract class BaseTestCell {
r = s.getRow(0);
c = r.getCell(0);
- assertEquals("Formula Cell at 0,0", CellType.FORMULA, c.getCellType());
+ assertEquals(CellType.FORMULA, c.getCellType(), "Formula Cell at 0,0");
cs = c.getCellStyle();
- assertNotNull("Formula Cell Style", cs);
- assertEquals("Font Index Matches", f.getIndex(), cs.getFontIndex());
- assertEquals("Top Border", BorderStyle.THIN, cs.getBorderTop());
- assertEquals("Left Border", BorderStyle.THIN, cs.getBorderLeft());
- assertEquals("Right Border", BorderStyle.THIN, cs.getBorderRight());
- assertEquals("Bottom Border", BorderStyle.THIN, cs.getBorderBottom());
+ assertNotNull(cs, "Formula Cell Style");
+ assertEquals(f.getIndex(), cs.getFontIndex(), "Font Index Matches");
+ assertEquals(BorderStyle.THIN, cs.getBorderTop(), "Top Border");
+ assertEquals(BorderStyle.THIN, cs.getBorderLeft(), "Left Border");
+ assertEquals(BorderStyle.THIN, cs.getBorderRight(), "Right Border");
+ assertEquals(BorderStyle.THIN, cs.getBorderBottom(), "Bottom Border");
}
}
}
@@ -345,31 +347,31 @@ public abstract class BaseTestCell {
dateStyle.setDataFormat(formatId);
r.getCell(7).setCellStyle(dateStyle);
- assertEquals("Boolean", "FALSE", r.getCell(0).toString());
- assertEquals("Boolean", "TRUE", r.getCell(1).toString());
- assertEquals("Numeric", "1.5", r.getCell(2).toString());
- assertEquals("String", "Astring", r.getCell(3).toString());
- assertEquals("Error", "#DIV/0!", r.getCell(4).toString());
- assertEquals("Formula", "A1+B1", r.getCell(5).toString());
- assertEquals("Blank", "", r.getCell(6).toString());
+ assertEquals("FALSE", r.getCell(0).toString(), "Boolean");
+ assertEquals("TRUE", r.getCell(1).toString(), "Boolean");
+ assertEquals("1.5", r.getCell(2).toString(), "Numeric");
+ assertEquals("Astring", r.getCell(3).toString(), "String");
+ assertEquals("#DIV/0!", r.getCell(4).toString(), "Error");
+ assertEquals("A1+B1", r.getCell(5).toString(), "Formula");
+ assertEquals("", r.getCell(6).toString(), "Blank");
// toString on a date-formatted cell displays dates as dd-MMM-yyyy, which has locale problems with the month
String dateCell1 = r.getCell(7).toString();
- assertTrue("Date (Day)", dateCell1.startsWith("02-"));
- assertTrue("Date (Year)", dateCell1.endsWith("-2010"));
+ assertTrue(dateCell1.startsWith("02-"), "Date (Day)");
+ assertTrue(dateCell1.endsWith("-2010"), "Date (Year)");
//Write out the file, read it in, and then check cell values
try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
r = wb2.getSheetAt(0).getRow(0);
- assertEquals("Boolean", "FALSE", r.getCell(0).toString());
- assertEquals("Boolean", "TRUE", r.getCell(1).toString());
- assertEquals("Numeric", "1.5", r.getCell(2).toString());
- assertEquals("String", "Astring", r.getCell(3).toString());
- assertEquals("Error", "#DIV/0!", r.getCell(4).toString());
- assertEquals("Formula", "A1+B1", r.getCell(5).toString());
- assertEquals("Blank", "", r.getCell(6).toString());
+ assertEquals("FALSE", r.getCell(0).toString(), "Boolean");
+ assertEquals("TRUE", r.getCell(1).toString(), "Boolean");
+ assertEquals("1.5", r.getCell(2).toString(), "Numeric");
+ assertEquals("Astring", r.getCell(3).toString(), "String");
+ assertEquals("#DIV/0!", r.getCell(4).toString(), "Error");
+ assertEquals("A1+B1", r.getCell(5).toString(), "Formula");
+ assertEquals("", r.getCell(6).toString(), "Blank");
String dateCell2 = r.getCell(7).toString();
- assertEquals("Date", dateCell1, dateCell2);
+ assertEquals(dateCell1, dateCell2, "Date");
}
}
}
@@ -436,12 +438,7 @@ public abstract class BaseTestCell {
private static void confirmFormulaWithUnknownUDF(String expectedFormula, Cell cell, FormulaEvaluator evaluator) {
assertEquals(expectedFormula, cell.getCellFormula());
- try {
- evaluator.evaluate(cell);
- fail("Expected NotImplementedFunctionException/NotImplementedException");
- } catch (final org.apache.poi.ss.formula.eval.NotImplementedException e) {
- // expected
- }
+ assertThrows(NotImplementedException.class, () -> evaluator.evaluate(cell));
}
@Test
@@ -525,7 +522,7 @@ public abstract class BaseTestCell {
assertEquals("abc", cellA1.getStringCellValue());
fe.evaluateInCell(cellA1);
- assertFalse("Identified bug with writing back formula result of type string", cellA1.getStringCellValue().isEmpty());
+ assertFalse(cellA1.getStringCellValue().isEmpty(), "Identified bug with writing back formula result of type string");
assertEquals("abc", cellA1.getStringCellValue());
}
}
@@ -587,7 +584,7 @@ public abstract class BaseTestCell {
cell.setCellFormula("1=1");
cell.setCellValue(true);
cell.setCellType(CellType.BOOLEAN);
- assertTrue("Identified bug 46479d", cell.getBooleanCellValue());
+ assertTrue(cell.getBooleanCellValue(), "Identified bug 46479d");
assertTrue(cell.getBooleanCellValue());
}
}
@@ -690,18 +687,18 @@ public abstract class BaseTestCell {
Cell cell0 = row.createCell(0);
cell0.setCellValue(Double.NaN);
- assertEquals("Double.NaN should change cell type to CellType#ERROR", CellType.ERROR, cell0.getCellType());
- assertEquals("Double.NaN should change cell value to #NUM!", FormulaError.NUM, forInt(cell0.getErrorCellValue()));
+ assertEquals(CellType.ERROR, cell0.getCellType(), "Double.NaN should change cell type to CellType#ERROR");
+ assertEquals(FormulaError.NUM, forInt(cell0.getErrorCellValue()), "Double.NaN should change cell value to #NUM!");
Cell cell1 = row.createCell(1);
cell1.setCellValue(Double.POSITIVE_INFINITY);
- assertEquals("Double.POSITIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell1.getCellType());
- assertEquals("Double.POSITIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell1.getErrorCellValue()));
+ assertEquals(CellType.ERROR, cell1.getCellType(), "Double.POSITIVE_INFINITY should change cell type to CellType#ERROR");
+ assertEquals(FormulaError.DIV0, forInt(cell1.getErrorCellValue()), "Double.POSITIVE_INFINITY should change cell value to #DIV/0!");
Cell cell2 = row.createCell(2);
cell2.setCellValue(Double.NEGATIVE_INFINITY);
- assertEquals("Double.NEGATIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell2.getCellType());
- assertEquals("Double.NEGATIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell2.getErrorCellValue()));
+ assertEquals(CellType.ERROR, cell2.getCellType(), "Double.NEGATIVE_INFINITY should change cell type to CellType#ERROR");
+ assertEquals(FormulaError.DIV0, forInt(cell2.getErrorCellValue()), "Double.NEGATIVE_INFINITY should change cell value to #DIV/0!");
try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
row = wb2.getSheetAt(0).getRow(0);
@@ -965,12 +962,8 @@ public abstract class BaseTestCell {
b.append("X");
// 32768 produces an invalid XLS file
- try {
- cell.setCellValue(b.toString());
- fail("Expected exception");
- } catch (IllegalArgumentException e) {
- assertEquals("The maximum length of cell contents (text) is 32767 characters", e.getMessage());
- }
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> cell.setCellValue(b.toString()));
+ assertEquals("The maximum length of cell contents (text) is 32767 characters", e.getMessage());
}
}
@@ -1032,35 +1025,14 @@ public abstract class BaseTestCell {
cell.setCellFormula("A2");
cell.setCellErrorValue(FormulaError.NAME.getCode());
- assertEquals("Should still be a formula even after we set an error value",
- CellType.FORMULA, cell.getCellType());
- assertEquals("Should still be a formula even after we set an error value",
- CellType.ERROR, cell.getCachedFormulaResultType());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "Should still be a formula even after we set an error value");
+ assertEquals(CellType.ERROR, cell.getCachedFormulaResultType(), "Should still be a formula even after we set an error value");
assertEquals("A2", cell.getCellFormula());
- try {
- cell.getNumericCellValue();
- fail("Should catch exception here");
- } catch (IllegalStateException e) {
- // expected here
- }
- try {
- cell.getStringCellValue();
- fail("Should catch exception here");
- } catch (IllegalStateException e) {
- // expected here
- }
- try {
- cell.getRichStringCellValue();
- fail("Should catch exception here");
- } catch (IllegalStateException e) {
- // expected here
- }
- try {
- cell.getDateCellValue();
- fail("Should catch exception here");
- } catch (IllegalStateException e) {
- // expected here
- }
+ assertThrows(IllegalStateException.class, cell::getNumericCellValue);
+ assertThrows(IllegalStateException.class, cell::getStringCellValue);
+ assertThrows(IllegalStateException.class, cell::getRichStringCellValue);
+ assertThrows(IllegalStateException.class, cell::getDateCellValue);
+
assertEquals(FormulaError.NAME.getCode(), cell.getErrorCellValue());
assertNull(cell.getHyperlink());
}
@@ -1214,19 +1186,19 @@ public abstract class BaseTestCell {
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void setCellType_null_throwsIAE() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
Cell cell = getInstance(wb);
- cell.setCellType(null);
+ assertThrows(IllegalArgumentException.class, () -> cell.setCellType(null));
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void setCellType_NONE_throwsIAE() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
Cell cell = getInstance(wb);
- cell.setCellType(CellType._NONE);
+ assertThrows(IllegalArgumentException.class, () -> cell.setCellType(CellType._NONE));
}
}
@@ -1248,17 +1220,17 @@ public abstract class BaseTestCell {
}
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void setBlank_throwsISE_ifCellIsPartOfAnArrayFormulaGroupContainingOtherCells() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
Cell cell = getInstance(wb);
cell.getSheet().setArrayFormula("1", CellRangeAddress.valueOf("A1:B1"));
cell.setCellValue("foo");
- cell.setBlank();
+ assertThrows(IllegalStateException.class, cell::setBlank);
}
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void setCellFormula_throwsISE_ifCellIsPartOfAnArrayFormulaGroupContainingOtherCells() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
Cell cell = getInstance(wb);
@@ -1267,7 +1239,7 @@ public abstract class BaseTestCell {
assertTrue(cell.isPartOfArrayFormulaGroup());
assertEquals(CellType.FORMULA, cell.getCellType());
- cell.setCellFormula("1");
+ assertThrows(IllegalStateException.class, () -> cell.setCellFormula("1"));
}
}
@@ -1349,8 +1321,7 @@ public abstract class BaseTestCell {
cell.setCellFormula("\"foo\"");
assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType());
- assertTrue("Expected a boolean cell-value, but had 'false'",
- cell.getBooleanCellValue());
+ assertTrue(cell.getBooleanCellValue(), "Expected a boolean cell-value, but had 'false'");
}
}
@@ -1367,8 +1338,7 @@ public abstract class BaseTestCell {
cell.setCellFormula("\"bar\"");
assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType());
- assertTrue("Expected a boolean cell-value, but had 'false'",
- cell.getBooleanCellValue());
+ assertTrue(cell.getBooleanCellValue(), "Expected a boolean cell-value, but had 'false'");
}
}
@@ -1386,18 +1356,18 @@ public abstract class BaseTestCell {
cell.getSheet().setArrayFormula("\"bar\"", CellRangeAddress.valueOf("A1"));
assertEquals(CellType.FORMULA, cell.getCellType());
- assertEquals("Expected a boolean cell-value, but had " + cell.getCachedFormulaResultType(),
- CellType.BOOLEAN, cell.getCachedFormulaResultType());
- assertTrue("Expected a boolean cell-value, but had 'false'",
- cell.getBooleanCellValue());
+ assertEquals(CellType.BOOLEAN, cell.getCachedFormulaResultType(),
+ "Expected a boolean cell-value, but had " + cell.getCachedFormulaResultType());
+ assertTrue(cell.getBooleanCellValue(),
+ "Expected a boolean cell-value, but had 'false'");
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void setCellType_FORMULA_onANonFormulaCell_throwsIllegalArgumentException() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
Cell cell = getInstance(wb);
- cell.setCellType(CellType.FORMULA);
+ assertThrows(IllegalArgumentException.class, () -> cell.setCellType(CellType.FORMULA));
}
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java
index 852c989009..c2cca1244f 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java
@@ -18,20 +18,21 @@
package org.apache.poi.ss.usermodel;
import static org.apache.poi.util.Units.EMU_PER_PIXEL;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.util.Units;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing implementations of
@@ -102,7 +103,7 @@ public abstract class BaseTestCellComment {
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
wb1.close();
-
+
sheet = wb2.getSheetAt(0);
cell = sheet.getRow(cellRow).getCell(cellColumn);
comment = cell.getCellComment();
@@ -135,7 +136,7 @@ public abstract class BaseTestCellComment {
// Test Comment.equals and Comment.hashCode
assertEquals(comment, cell.getCellComment());
assertEquals(comment.hashCode(), cell.getCellComment().hashCode());
-
+
wb3.close();
}
@@ -157,7 +158,7 @@ public abstract class BaseTestCellComment {
row = sheet.getRow(rownum);
cell = row.getCell(0);
comment = cell.getCellComment();
- assertNull("Cells in the first column are not commented", comment);
+ assertNull(comment, "Cells in the first column are not commented");
assertNull(sheet.getCellComment(new CellAddress(rownum, 0)));
}
@@ -165,15 +166,15 @@ public abstract class BaseTestCellComment {
row = sheet.getRow(rownum);
cell = row.getCell(1);
comment = cell.getCellComment();
- assertNotNull("Cells in the second column have comments", comment);
- assertNotNull("Cells in the second column have comments", sheet.getCellComment(new CellAddress(rownum, 1)));
+ assertNotNull(comment, "Cells in the second column have comments");
+ assertNotNull(sheet.getCellComment(new CellAddress(rownum, 1)), "Cells in the second column have comments");
assertEquals("Yegor Kozlov", comment.getAuthor());
assertFalse(comment.getString().getString().isEmpty());
assertEquals(rownum, comment.getRow());
assertEquals(cell.getColumnIndex(), comment.getColumn());
}
-
+
wb.close();
}
@@ -212,7 +213,7 @@ public abstract class BaseTestCellComment {
assertEquals("Mofified[" + rownum + "] by Yegor", comment.getAuthor());
assertEquals("Modified comment at row " + rownum, comment.getString().getString());
}
-
+
wb2.close();
}
@@ -242,7 +243,7 @@ public abstract class BaseTestCellComment {
assertNull(sheet.getRow(0).getCell(1).getCellComment());
assertNotNull(sheet.getRow(1).getCell(1).getCellComment());
assertNull(sheet.getRow(2).getCell(1).getCellComment());
-
+
wb2.close();
}
@@ -280,24 +281,24 @@ public abstract class BaseTestCellComment {
assertEquals("Apache POI", comment.getAuthor());
assertEquals(3, comment.getRow());
assertEquals(5, comment.getColumn());
-
+
wb2.close();
}
@Test
public void getClientAnchor() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
-
+
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(10);
Cell cell = row.createCell(5);
CreationHelper factory = wb.getCreationHelper();
-
+
Drawing<?> drawing = sheet.createDrawingPatriarch();
-
+
double r_mul, c_mul;
if (sheet instanceof HSSFSheet) {
- double rowheight = Units.toEMU(row.getHeightInPoints())/EMU_PER_PIXEL;
+ double rowheight = Units.toEMU(row.getHeightInPoints())/(double)EMU_PER_PIXEL;
r_mul = 256.0/rowheight;
double colwidth = sheet.getColumnWidthInPixels(2);
c_mul = 1024.0/colwidth;
@@ -313,12 +314,12 @@ public abstract class BaseTestCellComment {
int row1 = row.getRowNum();
int col2 = cell.getColumnIndex()+2;
int row2 = row.getRowNum()+1;
-
+
ClientAnchor anchor = drawing.createAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
Comment comment = drawing.createCellComment(anchor);
comment.setVisible(true);
cell.setCellComment(comment);
-
+
anchor = comment.getClientAnchor();
assertEquals(dx1, anchor.getDx1());
assertEquals(dy1, anchor.getDy1());
@@ -333,7 +334,7 @@ public abstract class BaseTestCellComment {
comment = drawing.createCellComment(anchor);
cell.setCellComment(comment);
anchor = comment.getClientAnchor();
-
+
if (sheet instanceof HSSFSheet) {
assertEquals(0, anchor.getCol1());
assertEquals(0, anchor.getDx1());
@@ -342,7 +343,7 @@ public abstract class BaseTestCellComment {
assertEquals(0, anchor.getCol2());
assertEquals(0, anchor.getDx2());
assertEquals(0, anchor.getRow2());
- assertEquals(0, anchor.getDy2());
+ assertEquals(0, anchor.getDy2());
} else {
// when anchor is initialized without parameters, the comment anchor attributes default to
// "1, 15, 0, 2, 3, 15, 3, 16" ... see XSSFVMLDrawing.newCommentShape()
@@ -355,33 +356,35 @@ public abstract class BaseTestCellComment {
assertEquals( 3, anchor.getRow2());
assertEquals(16*EMU_PER_PIXEL, anchor.getDy2());
}
-
+
wb.close();
}
-
+
@Test
public void attemptToSave2CommentsWithSameCoordinates() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet sh = wb.createSheet();
- CreationHelper factory = wb.getCreationHelper();
- Drawing<?> patriarch = sh.createDrawingPatriarch();
- patriarch.createCellComment(factory.createClientAnchor());
-
- try {
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet sh = wb.createSheet();
+ CreationHelper factory = wb.getCreationHelper();
+ Drawing<?> patriarch = sh.createDrawingPatriarch();
patriarch.createCellComment(factory.createClientAnchor());
- _testDataProvider.writeOutAndReadBack(wb);
- fail("Should not be able to create a corrupted workbook with multiple cell comments in one cell");
- } catch (IllegalStateException e) {
- // HSSFWorkbooks fail when writing out workbook
- assertEquals("found multiple cell comments for cell $A$1", e.getMessage());
- } catch (IllegalArgumentException e) {
- // XSSFWorkbooks fail when creating and setting the cell address of the comment
- assertEquals("Multiple cell comments in one cell are not allowed, cell: A1", e.getMessage());
- } finally {
- wb.close();
+
+ RuntimeException e = assertThrows(RuntimeException.class, () -> {
+ patriarch.createCellComment(factory.createClientAnchor());
+ _testDataProvider.writeOutAndReadBack(wb);
+ }, "Should not be able to create a corrupted workbook with multiple cell comments in one cell");
+
+ if (wb instanceof HSSFWorkbook) {
+ // HSSFWorkbooks fail when writing out workbook
+ assertTrue(e instanceof IllegalStateException);
+ assertEquals("found multiple cell comments for cell $A$1", e.getMessage());
+ } else {
+ // XSSFWorkbooks fail when creating and setting the cell address of the comment
+ assertTrue(e instanceof IllegalArgumentException);
+ assertEquals("Multiple cell comments in one cell are not allowed, cell: A1", e.getMessage());
+ }
}
}
-
+
@Test
public void getAddress() {
Workbook wb = _testDataProvider.createWorkbook();
@@ -389,13 +392,13 @@ public abstract class BaseTestCellComment {
CreationHelper factory = wb.getCreationHelper();
Drawing<?> patriarch = sh.createDrawingPatriarch();
Comment comment = patriarch.createCellComment(factory.createClientAnchor());
-
+
assertEquals(CellAddress.A1, comment.getAddress());
Cell C2 = sh.createRow(1).createCell(2);
C2.setCellComment(comment);
assertEquals(new CellAddress("C2"), comment.getAddress());
}
-
+
@Test
public void setAddress() {
Workbook wb = _testDataProvider.createWorkbook();
@@ -403,13 +406,13 @@ public abstract class BaseTestCellComment {
CreationHelper factory = wb.getCreationHelper();
Drawing<?> patriarch = sh.createDrawingPatriarch();
Comment comment = patriarch.createCellComment(factory.createClientAnchor());
-
+
assertEquals(CellAddress.A1, comment.getAddress());
CellAddress C2 = new CellAddress("C2");
assertEquals("C2", C2.formatAsString());
comment.setAddress(C2);
assertEquals(C2, comment.getAddress());
-
+
CellAddress E10 = new CellAddress(9, 4);
assertEquals("E10", E10.formatAsString());
comment.setAddress(9, 4);
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCloneSheet.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCloneSheet.java
index f3970ff46c..22c5743628 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCloneSheet.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCloneSheet.java
@@ -17,13 +17,15 @@
package org.apache.poi.ss.usermodel;
-import org.apache.poi.ss.ITestDataProvider;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
-import static org.junit.Assert.*;
+import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing implementations of
@@ -44,7 +46,7 @@ public abstract class BaseTestCloneSheet {
assertEquals(0, s.addMergedRegion(new CellRangeAddress(0, 1, 0, 1)));
Sheet clonedSheet = b.cloneSheet(0);
- assertEquals("One merged area", 1, clonedSheet.getNumMergedRegions());
+ assertEquals(1, clonedSheet.getNumMergedRegions(), "One merged area");
b.close();
}
@@ -60,12 +62,12 @@ public abstract class BaseTestCloneSheet {
s.setColumnBreak((short) 6);
Sheet clone = b.cloneSheet(0);
- assertTrue("Row 3 not broken", clone.isRowBroken(3));
- assertTrue("Column 6 not broken", clone.isColumnBroken((short) 6));
+ assertTrue(clone.isRowBroken(3), "Row 3 not broken");
+ assertTrue(clone.isColumnBroken((short) 6), "Column 6 not broken");
s.removeRowBreak(3);
- assertTrue("Row 3 still should be broken", clone.isRowBroken(3));
+ assertTrue(clone.isRowBroken(3), "Row 3 still should be broken");
b.close();
}
@@ -76,24 +78,14 @@ public abstract class BaseTestCloneSheet {
wb.createSheet("Sheet01");
wb.cloneSheet(0);
assertEquals(2, wb.getNumberOfSheets());
- try {
- wb.cloneSheet(2);
- fail("ShouldFail");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> wb.cloneSheet(2));
}
@Test
public void testCloneSheetIntInvalid() {
Workbook wb = _testDataProvider.createWorkbook();
wb.createSheet("Sheet01");
- try {
- wb.cloneSheet(1);
- fail("Should Fail");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> wb.cloneSheet(1));
assertEquals(1, wb.getNumberOfSheets());
}
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestColumnShifting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestColumnShifting.java
index b0944ee27e..8127d8e4d7 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestColumnShifting.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestColumnShifting.java
@@ -18,21 +18,20 @@
*/
package org.apache.poi.ss.usermodel;
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.poi.ss.usermodel.helpers.ColumnShifter;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public abstract class BaseTestColumnShifting {
protected Workbook wb;
protected Sheet sheet1;
protected ColumnShifter columnShifter;
- @Before
+ @BeforeEach
public void init() {
int rowIndex = 0;
sheet1 = wb.createSheet("sheet1");
@@ -63,7 +62,7 @@ public abstract class BaseTestColumnShifting {
@Test
public void testShift3ColumnsRight() {
columnShifter.shiftColumns(1, 2, 3);
-
+
Cell cell = sheet1.getRow(0).getCell(4);
assertNull(cell);
cell = sheet1.getRow(1).getCell(4);
@@ -76,12 +75,7 @@ public abstract class BaseTestColumnShifting {
@Test
public void testShiftLeft() {
- try {
- columnShifter.shiftColumns(1, 2, -3);
- fail("Shift to negative indices should throw exception");
- }
- catch(IllegalStateException e){
- assertTrue(true);
- }
+ assertThrows(IllegalStateException.class, () -> columnShifter.shiftColumns(1, 2, -3),
+ "Shift to negative indices should throw exception");
}
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
index 646b0bb4ad..3d972cd49c 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
@@ -19,12 +19,12 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
@@ -34,7 +34,8 @@ import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.function.Executable;
/**
* Base tests for Conditional Formatting, for both HSSF and XSSF
@@ -50,70 +51,47 @@ public abstract class BaseTestConditionalFormatting {
return true;
}
- protected abstract void assertColour(String hexExpected, Color actual);
+ protected abstract void assertColor(String hexExpected, Color actual);
@Test
- public void testBasic() throws IOException {
+ public void testBasic() throws Throwable {
try (Workbook wb = _testDataProvider.createWorkbook()) {
Sheet sh = wb.createSheet();
SheetConditionalFormatting sheetCF = sh.getSheetConditionalFormatting();
assertEquals(0, sheetCF.getNumConditionalFormattings());
- try {
- assertNull(sheetCF.getConditionalFormattingAt(0));
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
- }
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> sheetCF.getConditionalFormattingAt(0));
+ assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
- try {
- sheetCF.removeConditionalFormatting(0);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
- }
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.removeConditionalFormatting(0));
+ assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("1");
ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule("2");
ConditionalFormattingRule rule3 = sheetCF.createConditionalFormattingRule("3");
ConditionalFormattingRule rule4 = sheetCF.createConditionalFormattingRule("4");
- try {
- sheetCF.addConditionalFormatting(null, rule1);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("regions must not be null"));
- }
- try {
- sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
- (ConditionalFormattingRule) null);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("cfRules must not be null"));
- }
- try {
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.addConditionalFormatting(null, rule1));
+ assertTrue(e.getMessage().startsWith("regions must not be null"));
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.addConditionalFormatting(
+ new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")}, (ConditionalFormattingRule) null));
+ assertTrue(e.getMessage().startsWith("cfRules must not be null"));
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.addConditionalFormatting(
+ new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")}, new ConditionalFormattingRule[0]));
+ assertTrue(e.getMessage().startsWith("cfRules must not be empty"));
+
+ Executable exec = () ->
sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
- new ConditionalFormattingRule[0]);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("cfRules must not be empty"));
- }
+ new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
+ new ConditionalFormattingRule[]{rule1, rule2, rule3, rule4});
if (applyLimitOf3()) {
- try {
- sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
- new ConditionalFormattingRule[]{rule1, rule2, rule3, rule4});
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Number of rules must not exceed 3"));
- }
+ e = assertThrows(IllegalArgumentException.class, exec);
+ assertTrue(e.getMessage().startsWith("Number of rules must not exceed 3"));
} else {
- sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
- new ConditionalFormattingRule[]{rule1, rule2, rule3, rule4});
+ exec.execute();
}
}
}
@@ -273,34 +251,25 @@ public abstract class BaseTestConditionalFormatting {
// adjacent address are merged
int formatIndex = sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{
- CellRangeAddress.valueOf("A1:A5")
- }, rule1);
+ new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A5")}, rule1);
assertEquals(0, formatIndex);
assertEquals(1, sheetCF.getNumConditionalFormattings());
sheetCF.removeConditionalFormatting(0);
assertEquals(0, sheetCF.getNumConditionalFormattings());
- try {
- assertNull(sheetCF.getConditionalFormattingAt(0));
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
- }
+
+ IllegalArgumentException e;
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.getConditionalFormattingAt(0));
+ assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
formatIndex = sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{
- CellRangeAddress.valueOf("A1:A5")
- }, rule1);
+ new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A5")}, rule1);
assertEquals(0, formatIndex);
assertEquals(1, sheetCF.getNumConditionalFormattings());
sheetCF.removeConditionalFormatting(0);
assertEquals(0, sheetCF.getNumConditionalFormattings());
- try {
- assertNull(sheetCF.getConditionalFormattingAt(0));
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
- }
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.getConditionalFormattingAt(0));
+ assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
}
}
@@ -611,11 +580,11 @@ public abstract class BaseTestConditionalFormatting {
// Sets the background colour to lighter green
// TODO Should the colours be slightly different between formats? Would CFEX support help for HSSF?
if (cr instanceof HSSFConditionalFormattingRule) {
- assertColour("0:8080:0", cr.getFontFormatting().getFontColor());
- assertColour("CCCC:FFFF:CCCC", cr.getPatternFormatting().getFillBackgroundColorColor());
+ assertColor("0:8080:0", cr.getFontFormatting().getFontColor());
+ assertColor("CCCC:FFFF:CCCC", cr.getPatternFormatting().getFillBackgroundColorColor());
} else {
- assertColour("006100", cr.getFontFormatting().getFontColor());
- assertColour("C6EFCE", cr.getPatternFormatting().getFillBackgroundColorColor());
+ assertColor("006100", cr.getFontFormatting().getFontColor());
+ assertColor("C6EFCE", cr.getPatternFormatting().getFillBackgroundColorColor());
}
@@ -635,11 +604,11 @@ public abstract class BaseTestConditionalFormatting {
// Sets the background colour to lighter red
// TODO Should the colours be slightly different between formats? Would CFEX support help for HSSF?
if (cr instanceof HSSFConditionalFormattingRule) {
- assertColour("8080:0:8080", cr.getFontFormatting().getFontColor());
- assertColour("FFFF:9999:CCCC", cr.getPatternFormatting().getFillBackgroundColorColor());
+ assertColor("8080:0:8080", cr.getFontFormatting().getFontColor());
+ assertColor("FFFF:9999:CCCC", cr.getPatternFormatting().getFillBackgroundColorColor());
} else {
- assertColour("9C0006", cr.getFontFormatting().getFontColor());
- assertColour("FFC7CE", cr.getPatternFormatting().getFillBackgroundColorColor());
+ assertColor("9C0006", cr.getFontFormatting().getFontColor());
+ assertColor("FFC7CE", cr.getPatternFormatting().getFillBackgroundColorColor());
}
@@ -798,7 +767,7 @@ public abstract class BaseTestConditionalFormatting {
assertEquals(0, databar.getWidthMin());
assertEquals(100, databar.getWidthMax());
- assertColour(color, databar.getColor());
+ assertColor(color, databar.getColor());
ConditionalFormattingThreshold th;
th = databar.getMinThreshold();
@@ -877,7 +846,7 @@ public abstract class BaseTestConditionalFormatting {
// Colors should match
for (int i=0; i<colors.length; i++) {
- assertColour(colors[i], color.getColors()[i]);
+ assertColor(colors[i], color.getColors()[i]);
}
}
@@ -1210,7 +1179,7 @@ public abstract class BaseTestConditionalFormatting {
assertTrue(dbFmt.isLeftToRight());
assertEquals(0, dbFmt.getWidthMin());
assertEquals(100, dbFmt.getWidthMax());
- assertColour(colorHex, dbFmt.getColor());
+ assertColor(colorHex, dbFmt.getColor());
dbFmt.getMinThreshold().setRangeType(RangeType.MIN);
dbFmt.getMaxThreshold().setRangeType(RangeType.MAX);
@@ -1234,7 +1203,7 @@ public abstract class BaseTestConditionalFormatting {
assertTrue(dbFmt.isLeftToRight());
assertEquals(0, dbFmt.getWidthMin());
assertEquals(100, dbFmt.getWidthMax());
- assertColour(colorHex, dbFmt.getColor());
+ assertColor(colorHex, dbFmt.getColor());
assertEquals(RangeType.MIN, dbFmt.getMinThreshold().getRangeType());
assertEquals(RangeType.MAX, dbFmt.getMaxThreshold().getRangeType());
@@ -1319,7 +1288,7 @@ public abstract class BaseTestConditionalFormatting {
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSetCellRangeAddressWithNullRanges() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
final Sheet sheet = wb.createSheet("S1");
@@ -1332,7 +1301,7 @@ public abstract class BaseTestConditionalFormatting {
assertEquals(1, cf.getNumConditionalFormattings());
ConditionalFormatting readCf = cf.getConditionalFormattingAt(0);
- readCf.setFormattingRanges(null);
+ assertThrows(IllegalArgumentException.class, () -> readCf.setFormattingRanges(null));
}
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java
index 2208cf5f49..4f6d4b6aa9 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java
@@ -17,14 +17,14 @@
package org.apache.poi.ss.usermodel;
-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.io.IOException;
import org.apache.poi.ss.ITestDataProvider;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests of implementation of {@link DataFormat}
@@ -116,7 +116,7 @@ public abstract class BaseTestDataFormat {
DataFormat dataFormat = wb.createDataFormat();
short fmtIdx = dataFormat.getFormat(fmt);
String readbackFmt = dataFormat.getFormat(fmtIdx);
- assertEquals(msg, fmt, readbackFmt);
+ assertEquals(fmt, readbackFmt, msg);
}
}
@@ -158,10 +158,10 @@ public abstract class BaseTestDataFormat {
String expWhole = r.getCell(2).getStringCellValue();
String exp3dp = r.getCell(4).getStringCellValue();
- assertEquals("Wrong formatting of " + value + " for row " + rn,
- expWhole, fmt.formatCellValue(r.getCell(1), eval));
- assertEquals("Wrong formatting of " + value + " for row " + rn,
- exp3dp, fmt.formatCellValue(r.getCell(3), eval));
+ assertEquals(expWhole, fmt.formatCellValue(r.getCell(1), eval),
+ "Wrong formatting of " + value + " for row " + rn);
+ assertEquals(exp3dp, fmt.formatCellValue(r.getCell(3), eval),
+ "Wrong formatting of " + value + " for row " + rn);
}
}
@@ -198,7 +198,7 @@ public abstract class BaseTestDataFormat {
assertEquals("-"+pound+" 12,345", formatter.formatCellValue(nve));
// TODO Fix this to not have an extra 0 at the end
//assertEquals(pound+" - ", formatter.formatCellValue(zero));
-
+
wb.close();
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java
index 5b8bdc84cc..162deac99f 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java
@@ -25,7 +25,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class for testing Excel's data validation mechanism
@@ -492,7 +492,7 @@ public abstract class BaseTestDataValidation {
log("done !");
_testDataProvider.writeOutAndReadBack(wb).close();
-
+
wb.close();
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java
index 5044bdcf34..501225aedc 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java
@@ -17,18 +17,18 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.apache.poi.ss.ITestDataProvider;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* @author Yegor Kozlov
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
index 61d3f41e33..68dee47f29 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
@@ -17,15 +17,20 @@
package org.apache.poi.ss.usermodel;
+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 static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.io.IOException;
import java.util.Locale;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellRangeAddressList;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing implementation of {@link FormulaEvaluator}
@@ -62,7 +67,7 @@ public abstract class BaseTestFormulaEvaluator {
assertEquals(6.0, c1.getNumericCellValue(), 0.0001);
assertEquals(5.0, c2.getNumericCellValue(), 0.0001);
-
+
wb.close();
}
@@ -107,7 +112,7 @@ public abstract class BaseTestFormulaEvaluator {
assertEquals(17.5, c2.getNumericCellValue(), 0.0001);
assertEquals(1, c3.getNumericCellValue(), 0.0001);
assertEquals(4, c4.getNumericCellValue(), 0.0001);
-
+
wb.close();
}
@@ -134,7 +139,7 @@ public abstract class BaseTestFormulaEvaluator {
cell = sheet.getRow(4).getCell(0);
assertEquals("B5", cell.getCellFormula());
assertEquals("UniqueDocumentNumberID", evaluator.evaluate(cell).getStringValue());
-
+
wb.close();
}
@@ -173,7 +178,7 @@ public abstract class BaseTestFormulaEvaluator {
assertEquals(5.0, evaluator.evaluate(sh2.getRow(0).getCell(1)).getNumberValue(), 0.0);
assertEquals(15.0, evaluator.evaluate(sh2.getRow(0).getCell(2)).getNumberValue(), 0.0);
-
+
wb.close();
}
@@ -207,10 +212,10 @@ public abstract class BaseTestFormulaEvaluator {
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
assertEquals(26.0, fe.evaluate(cell0).getNumberValue(), 0.0);
assertEquals(56.0, fe.evaluate(cell1).getNumberValue(), 0.0);
-
+
wb.close();
}
-
+
@Test
public void testRepeatedEvaluation() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
@@ -218,37 +223,37 @@ public abstract class BaseTestFormulaEvaluator {
Sheet sheet = wb.createSheet("Sheet1");
Row r = sheet.createRow(0);
Cell c = r.createCell(0, CellType.FORMULA);
-
+
// Create a value and check it
c.setCellFormula("Date(2011,10,6)");
CellValue cellValue = fe.evaluate(c);
assertEquals(40822.0, cellValue.getNumberValue(), 0.0);
cellValue = fe.evaluate(c);
assertEquals(40822.0, cellValue.getNumberValue(), 0.0);
-
+
// Change it
c.setCellFormula("Date(2011,10,4)");
-
+
// Evaluate it, no change as the formula evaluator
// won't know to clear the cache
cellValue = fe.evaluate(c);
assertEquals(40822.0, cellValue.getNumberValue(), 0.0);
-
+
// Manually flush for this cell, and check
fe.notifySetFormula(c);
cellValue = fe.evaluate(c);
assertEquals(40820.0, cellValue.getNumberValue(), 0.0);
-
+
// Change again, without notifying
c.setCellFormula("Date(2010,10,4)");
cellValue = fe.evaluate(c);
assertEquals(40820.0, cellValue.getNumberValue(), 0.0);
-
+
// Now manually clear all, will see the new value
fe.clearAllCachedResultValues();
cellValue = fe.evaluate(c);
assertEquals(40455.0, cellValue.getNumberValue(), 0.0);
-
+
wb.close();
}
@@ -323,10 +328,10 @@ public abstract class BaseTestFormulaEvaluator {
assertEquals(2162.62, fe.evaluateInCell(cellB1).getNumericCellValue(), 0.0);
assertEquals(2162.62, fe.evaluateInCell(cellC1).getNumericCellValue(), 0.0);
assertEquals(2162.61, fe.evaluateInCell(cellD1).getNumericCellValue(), 0.0);
-
+
wb.close();
}
-
+
@Test
public void evaluateInCellReturnsSameCell() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
@@ -638,8 +643,8 @@ public abstract class BaseTestFormulaEvaluator {
double result = a3.getNumericCellValue();
// result is correct
- assertTrue(String.format(Locale.ROOT, "Expected %f to be greater than %f", result, 2.0), result > 2.0);
- assertTrue(String.format(Locale.ROOT, "Expected %f to be less than %f", result, 4.0), result < 4.0);
+ assertTrue(result > 2.0, String.format(Locale.ROOT, "Expected %f to be greater than %f", result, 2.0));
+ assertTrue(result < 4.0, String.format(Locale.ROOT, "Expected %f to be less than %f", result, 4.0));
// ensure that this works for SUM
assertEquals(CellType.FORMULA, a3.getCellType());
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java
index 54b306e039..c269e2e6ea 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java
@@ -17,16 +17,16 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
import java.io.IOException;
import java.util.List;
-import org.junit.Test;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.ITestDataProvider;
+import org.junit.jupiter.api.Test;
/**
* Test diffrent types of Excel hyperlinks
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
index e458a3e778..2c35c79302 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
@@ -17,12 +17,12 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.Arrays;
@@ -34,7 +34,7 @@ import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests of implementations of {@link org.apache.poi.ss.usermodel.Name}.
@@ -51,159 +51,130 @@ public abstract class BaseTestNamedRange {
@Test
public final void testCreate() throws Exception {
- // Create a new workbook
- Workbook wb = _testDataProvider.createWorkbook();
- wb.createSheet("Test1");
- wb.createSheet("Testing Named Ranges");
-
- Name name1 = wb.createName();
- name1.setNameName("testOne");
-
- //setting a duplicate name should throw IllegalArgumentException
- Name name2 = wb.createName();
- try {
- name2.setNameName("testOne");
- fail("expected exception");
- } catch (IllegalArgumentException e){
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ wb.createSheet("Test1");
+ wb.createSheet("Testing Named Ranges");
+
+ Name name1 = wb.createName();
+ name1.setNameName("testOne");
+
+ //setting a duplicate name should throw IllegalArgumentException
+ Name name2 = wb.createName();
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> name2.setNameName("testOne"));
assertEquals("The workbook already contains this name: testOne", e.getMessage());
- }
- //the check for duplicates is case-insensitive
- try {
- name2.setNameName("TESTone");
- fail("expected exception");
- } catch (IllegalArgumentException e){
+
+ //the check for duplicates is case-insensitive
+ e = assertThrows(IllegalArgumentException.class, () -> name2.setNameName("TESTone"));
assertEquals("The workbook already contains this name: TESTone", e.getMessage());
- }
- name2.setNameName("testTwo");
-
- String ref1 = "Test1!$A$1:$B$1";
- name1.setRefersToFormula(ref1);
- assertEquals(ref1, name1.getRefersToFormula());
- assertEquals("Test1", name1.getSheetName());
-
- String ref2 = "'Testing Named Ranges'!$A$1:$B$1";
- name1.setRefersToFormula(ref2);
- assertEquals("'Testing Named Ranges'!$A$1:$B$1", name1.getRefersToFormula());
- assertEquals("Testing Named Ranges", name1.getSheetName());
-
- assertEquals(-1, name1.getSheetIndex());
- name1.setSheetIndex(-1);
- assertEquals(-1, name1.getSheetIndex());
- try {
- name1.setSheetIndex(2);
- fail("should throw IllegalArgumentException");
- } catch(IllegalArgumentException e){
+ name2.setNameName("testTwo");
+
+ String ref1 = "Test1!$A$1:$B$1";
+ name1.setRefersToFormula(ref1);
+ assertEquals(ref1, name1.getRefersToFormula());
+ assertEquals("Test1", name1.getSheetName());
+
+ String ref2 = "'Testing Named Ranges'!$A$1:$B$1";
+ name1.setRefersToFormula(ref2);
+ assertEquals("'Testing Named Ranges'!$A$1:$B$1", name1.getRefersToFormula());
+ assertEquals("Testing Named Ranges", name1.getSheetName());
+
+ assertEquals(-1, name1.getSheetIndex());
+ name1.setSheetIndex(-1);
+ assertEquals(-1, name1.getSheetIndex());
+ e = assertThrows(IllegalArgumentException.class, () -> name1.setSheetIndex(2));
assertEquals("Sheet index (2) is out of range (0..1)", e.getMessage());
- }
- name1.setSheetIndex(1);
- assertEquals(1, name1.getSheetIndex());
-
- //-1 means the name applies to the entire workbook
- name1.setSheetIndex(-1);
- assertEquals(-1, name1.getSheetIndex());
-
- //names cannot be blank and must begin with a letter or underscore and not contain spaces
- String[] invalidNames = {"", "123", "1Name", "Named Range"};
- for (String name : invalidNames) {
- try {
- name1.setNameName(name);
- fail("should have thrown exceptiuon due to invalid name: " + name);
- } catch (IllegalArgumentException e) {
- // expected during successful test
+ name1.setSheetIndex(1);
+ assertEquals(1, name1.getSheetIndex());
+
+ //-1 means the name applies to the entire workbook
+ name1.setSheetIndex(-1);
+ assertEquals(-1, name1.getSheetIndex());
+
+ //names cannot be blank and must begin with a letter or underscore and not contain spaces
+ String[] invalidNames = {"", "123", "1Name", "Named Range"};
+ for (String name : invalidNames) {
+ assertThrows(IllegalArgumentException.class, () -> name1.setNameName(name),
+ "should have thrown exceptiuon due to invalid name: " + name);
}
}
-
- wb.close();
}
@Test
public final void testUnicodeNamedRange() throws Exception {
- HSSFWorkbook wb1 = new HSSFWorkbook();
- wb1.createSheet("Test");
- Name name = wb1.createName();
- name.setNameName("\u03B1");
- name.setRefersToFormula("Test!$D$3:$E$8");
+ try (HSSFWorkbook wb1 = new HSSFWorkbook()) {
+ wb1.createSheet("Test");
+ Name name = wb1.createName();
+ name.setNameName("\u03B1");
+ name.setRefersToFormula("Test!$D$3:$E$8");
+ try (HSSFWorkbook wb2 = HSSFITestDataProvider.instance.writeOutAndReadBack(wb1)) {
+ Name name2 = wb2.getName("\u03B1");
- HSSFWorkbook wb2 = HSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
- Name name2 = wb2.getName("\u03B1");
+ assertNotNull(name2);
+ assertEquals("\u03B1", name2.getNameName());
+ assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
- assertEquals("\u03B1", name2.getNameName());
- assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
-
- wb2.close();
- wb1.close();
+ }
+ }
}
@Test
public final void testAddRemove() throws Exception {
- Workbook wb = _testDataProvider.createWorkbook();
- assertEquals(0, wb.getNumberOfNames());
- Name name1 = wb.createName();
- name1.setNameName("name1");
- assertEquals(1, wb.getNumberOfNames());
-
- Name name2 = wb.createName();
- name2.setNameName("name2");
- assertEquals(2, wb.getNumberOfNames());
-
- Name name3 = wb.createName();
- name3.setNameName("name3");
- assertEquals(3, wb.getNumberOfNames());
-
- wb.removeName(wb.getName("name2"));
- assertEquals(2, wb.getNumberOfNames());
-
- wb.close();
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ assertEquals(0, wb.getNumberOfNames());
+ Name name1 = wb.createName();
+ name1.setNameName("name1");
+ assertEquals(1, wb.getNumberOfNames());
+
+ Name name2 = wb.createName();
+ name2.setNameName("name2");
+ assertEquals(2, wb.getNumberOfNames());
+
+ Name name3 = wb.createName();
+ name3.setNameName("name3");
+ assertEquals(3, wb.getNumberOfNames());
+
+ wb.removeName(wb.getName("name2"));
+ assertEquals(2, wb.getNumberOfNames());
+ }
}
@Test
public final void testScope() throws Exception {
- Workbook wb = _testDataProvider.createWorkbook();
- wb.createSheet();
- wb.createSheet();
-
- Name name;
-
- name = wb.createName();
- name.setNameName("aaa");
- name = wb.createName();
- try {
- name.setNameName("aaa");
- fail("Expected exception");
- } catch(Exception e){
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ wb.createSheet();
+ wb.createSheet();
+
+ wb.createName().setNameName("aaa");
+ Exception e = assertThrows(Exception.class, () -> wb.createName().setNameName("aaa"));
assertEquals("The workbook already contains this name: aaa", e.getMessage());
- }
- name = wb.createName();
- name.setSheetIndex(0);
- name.setNameName("aaa");
- name = wb.createName();
- name.setSheetIndex(0);
- try {
- name.setNameName("aaa");
- fail("Expected exception");
- } catch(Exception e){
+ Name name1 = wb.createName();
+ name1.setSheetIndex(0);
+ name1.setNameName("aaa");
+
+ e = assertThrows(Exception.class, () -> {
+ Name name2 = wb.createName();
+ name2.setSheetIndex(0);
+ name2.setNameName("aaa");
+ });
assertEquals("The sheet already contains this name: aaa", e.getMessage());
- }
- name = wb.createName();
- name.setSheetIndex(1);
- name.setNameName("aaa");
- name = wb.createName();
- name.setSheetIndex(1);
- try {
- name.setNameName("aaa");
- fail("Expected exception");
- } catch(Exception e){
+ name1 = wb.createName();
+ name1.setSheetIndex(1);
+ name1.setNameName("aaa");
+
+ e = assertThrows(Exception.class, () -> {
+ Name name2 = wb.createName();
+ name2.setSheetIndex(1);
+ name2.setNameName("aaa");
+ });
assertEquals("The sheet already contains this name: aaa", e.getMessage());
- }
- assertEquals(3, wb.getNames("aaa").size());
-
- wb.close();
+ assertEquals(3, wb.getNames("aaa").size());
+ }
}
/**
@@ -247,13 +218,13 @@ public abstract class BaseTestNamedRange {
// Read the Excel file and verify its content
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
Name nm1 = wb2.getName("RangeTest1");
- assertEquals("Name is " + nm1.getNameName(), "RangeTest1", nm1.getNameName());
- assertEquals("Reference is " + nm1.getRefersToFormula(), (wb2.getSheetName(0) + "!$A$1:$L$41"), nm1.getRefersToFormula());
+ assertEquals("RangeTest1", nm1.getNameName(), "Name is " + nm1.getNameName());
+ assertEquals((wb2.getSheetName(0) + "!$A$1:$L$41"), nm1.getRefersToFormula(), "Reference is " + nm1.getRefersToFormula());
Name nm2 = wb2.getName("RangeTest2");
- assertEquals("Name is " + nm2.getNameName(), "RangeTest2", nm2.getNameName());
- assertEquals("Reference is " + nm2.getRefersToFormula(), (wb2.getSheetName(1) + "!$A$1:$O$21"), nm2.getRefersToFormula());
-
+ assertEquals("RangeTest2", nm2.getNameName(), "Name is " + nm2.getNameName());
+ assertEquals((wb2.getSheetName(1) + "!$A$1:$O$21"), nm2.getRefersToFormula(), "Reference is " + nm2.getRefersToFormula());
+
wb2.close();
wb1.close();
}
@@ -272,9 +243,9 @@ public abstract class BaseTestNamedRange {
String retrievedPrintArea = workbook.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
-
+
workbook.close();
}
@@ -293,9 +264,9 @@ public abstract class BaseTestNamedRange {
String retrievedPrintArea = workbook.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
assertEquals("'" + sheetName + "'!" + reference, retrievedPrintArea);
-
+
workbook.close();
}
@@ -315,9 +286,9 @@ public abstract class BaseTestNamedRange {
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
String retrievedPrintArea = wb2.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
- assertEquals("References Match", "'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
-
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
+ assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
+
wb2.close();
wb1.close();
}
@@ -327,51 +298,50 @@ public abstract class BaseTestNamedRange {
*/
@Test
public final void testMultiplePrintAreaFile() throws Exception {
- Workbook wb1 = _testDataProvider.createWorkbook();
+ try (Workbook wb1 = _testDataProvider.createWorkbook()) {
- wb1.createSheet("Sheet1");
- wb1.createSheet("Sheet2");
- wb1.createSheet("Sheet3");
- String reference1 = "$A$1:$B$1";
- String reference2 = "$B$2:$D$5";
- String reference3 = "$D$2:$F$5";
+ wb1.createSheet("Sheet1");
+ wb1.createSheet("Sheet2");
+ wb1.createSheet("Sheet3");
+ String reference1 = "$A$1:$B$1";
+ String reference2 = "$B$2:$D$5";
+ String reference3 = "$D$2:$F$5";
- wb1.setPrintArea(0, reference1);
- wb1.setPrintArea(1, reference2);
- wb1.setPrintArea(2, reference3);
+ wb1.setPrintArea(0, reference1);
+ wb1.setPrintArea(1, reference2);
+ wb1.setPrintArea(2, reference3);
- //Check created print areas
- String retrievedPrintArea;
+ //Check created print areas
+ String retrievedPrintArea;
- retrievedPrintArea = wb1.getPrintArea(0);
- assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
- assertEquals("Sheet1!" + reference1, retrievedPrintArea);
+ retrievedPrintArea = wb1.getPrintArea(0);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 1)");
+ assertEquals("Sheet1!" + reference1, retrievedPrintArea);
- retrievedPrintArea = wb1.getPrintArea(1);
- assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
- assertEquals("Sheet2!" + reference2, retrievedPrintArea);
+ retrievedPrintArea = wb1.getPrintArea(1);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 2)");
+ assertEquals("Sheet2!" + reference2, retrievedPrintArea);
- retrievedPrintArea = wb1.getPrintArea(2);
- assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
- assertEquals("Sheet3!" + reference3, retrievedPrintArea);
+ retrievedPrintArea = wb1.getPrintArea(2);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 3)");
+ assertEquals("Sheet3!" + reference3, retrievedPrintArea);
- // Check print areas after re-reading workbook
- Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+ // Check print areas after re-reading workbook
+ try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
- retrievedPrintArea = wb2.getPrintArea(0);
- assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
- assertEquals("Sheet1!" + reference1, retrievedPrintArea);
+ retrievedPrintArea = wb2.getPrintArea(0);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 1)");
+ assertEquals("Sheet1!" + reference1, retrievedPrintArea);
- retrievedPrintArea = wb2.getPrintArea(1);
- assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
- assertEquals("Sheet2!" + reference2, retrievedPrintArea);
+ retrievedPrintArea = wb2.getPrintArea(1);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 2)");
+ assertEquals("Sheet2!" + reference2, retrievedPrintArea);
- retrievedPrintArea = wb2.getPrintArea(2);
- assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
- assertEquals("Sheet3!" + reference3, retrievedPrintArea);
-
- wb2.close();
- wb1.close();
+ retrievedPrintArea = wb2.getPrintArea(2);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 3)");
+ assertEquals("Sheet3!" + reference3, retrievedPrintArea);
+ }
+ }
}
/**
@@ -388,9 +358,9 @@ public abstract class BaseTestNamedRange {
String retrievedPrintArea = workbook.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
-
+
workbook.close();
}
@@ -407,9 +377,9 @@ public abstract class BaseTestNamedRange {
String reference = "$A$1:$B$1,$D$1:$F$2";
workbook.setPrintArea(0, reference);
String retrievedPrintArea = workbook.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
assertEquals("'Test Print Area'!$A$1:$B$1,'Test Print Area'!$D$1:$F$2", retrievedPrintArea);
-
+
workbook.close();
}
@@ -419,19 +389,19 @@ public abstract class BaseTestNamedRange {
*/
@Test
public final void testPrintAreaRemove() throws Exception {
- Workbook workbook = _testDataProvider.createWorkbook();
- workbook.createSheet("Test Print Area");
- workbook.getSheetName(0);
+ try (Workbook workbook = _testDataProvider.createWorkbook()) {
+ workbook.createSheet("Test Print Area");
+ workbook.getSheetName(0);
- workbook.setPrintArea(0, 0, 1, 0, 0);
+ workbook.setPrintArea(0, 0, 1, 0, 0);
- String retrievedPrintArea = workbook.getPrintArea(0);
+ String retrievedPrintArea = workbook.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
- workbook.removePrintArea(0);
- assertNull("PrintArea was not removed", workbook.getPrintArea(0));
- workbook.close();
+ workbook.removePrintArea(0);
+ assertNull(workbook.getPrintArea(0), "PrintArea was not removed");
+ }
}
/**
@@ -461,13 +431,13 @@ public abstract class BaseTestNamedRange {
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
Name nm = wb2.getName("RangeTest");
- assertEquals("Name is " + nm.getNameName(), "RangeTest", nm.getNameName());
- assertEquals("Reference is " + nm.getRefersToFormula(), (wb2.getSheetName(0) + "!$D$4:$E$8"), nm.getRefersToFormula());
+ assertEquals("RangeTest", nm.getNameName(), "Name is " + nm.getNameName());
+ assertEquals((wb2.getSheetName(0) + "!$D$4:$E$8"), nm.getRefersToFormula(), "Reference is " + nm.getRefersToFormula());
nm = wb2.getName("AnotherTest");
- assertEquals("Name is " + nm.getNameName(), "AnotherTest", nm.getNameName());
- assertEquals("Reference is " + nm.getRefersToFormula(), newNamedRange2.getRefersToFormula(), nm.getRefersToFormula());
-
+ assertEquals("AnotherTest", nm.getNameName(), "Name is " + nm.getNameName());
+ assertEquals(newNamedRange2.getRefersToFormula(), nm.getRefersToFormula(), "Reference is " + nm.getRefersToFormula());
+
wb2.close();
wb1.close();
}
@@ -499,7 +469,7 @@ public abstract class BaseTestNamedRange {
// retrieve the cell at the named range and test its contents
AreaReference aref = wb.getCreationHelper().createAreaReference(aNamedCell.getRefersToFormula());
- assertTrue("Should be exactly 1 cell in the named cell :'" +cellName+"'", aref.isSingleCell());
+ assertTrue(aref.isSingleCell(), "Should be exactly 1 cell in the named cell :'" +cellName+"'");
CellReference cref = aref.getFirstCell();
assertNotNull(cref);
@@ -508,7 +478,7 @@ public abstract class BaseTestNamedRange {
Row r = sheet.getRow(cref.getRow());
Cell c = r.getCell(cref.getCol());
String contents = c.getRichStringCellValue().getString();
- assertEquals("Contents of cell retrieved by its named reference", contents, cellValue);
+ assertEquals(contents, cellValue, "Contents of cell retrieved by its named reference");
wb.close();
}
@@ -543,8 +513,8 @@ public abstract class BaseTestNamedRange {
Row r = sheet.getRow(cref.getRow());
Cell c = r.getCell(cref.getCol());
String contents = c.getRichStringCellValue().getString();
- assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
-
+ assertEquals(contents, cvalue, "Contents of cell retrieved by its named reference");
+
wb.close();
}
@@ -571,7 +541,7 @@ public abstract class BaseTestNamedRange {
Name n = wb.createName();
n.setNameName("UPSState");
String formula = n.getRefersToFormula();
-
+
// bug 46973: fails here with IllegalArgumentException
// ptgs must not be null
@@ -589,8 +559,8 @@ public abstract class BaseTestNamedRange {
// contrived example to expose bug:
n.setRefersToFormula("if(A1,\"#REF!\", \"\")");
- assertFalse("Identified bug in recoginising formulas referring to deleted cells", n.isDeleted());
-
+ assertFalse(n.isDeleted(), "Identified bug in recoginising formulas referring to deleted cells");
+
wb.close();
}
@@ -608,35 +578,30 @@ public abstract class BaseTestNamedRange {
n.setFunction(false);
assertFalse(n.isFunctionName());
-
+
wb.close();
}
@Test
public final void testDefferedSetting() throws Exception {
- Workbook wb = _testDataProvider.createWorkbook();
- Name n1 = wb.createName();
- assertNull(n1.getRefersToFormula());
- assertEquals("", n1.getNameName());
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Name n1 = wb.createName();
+ assertNull(n1.getRefersToFormula());
+ assertEquals("", n1.getNameName());
- Name n2 = wb.createName();
- assertNull(n2.getRefersToFormula());
- assertEquals("", n2.getNameName());
+ Name n2 = wb.createName();
+ assertNull(n2.getRefersToFormula());
+ assertEquals("", n2.getNameName());
- n1.setNameName("sale_1");
- n1.setRefersToFormula("10");
+ n1.setNameName("sale_1");
+ n1.setRefersToFormula("10");
- n2.setNameName("sale_2");
- n2.setRefersToFormula("20");
+ n2.setNameName("sale_2");
+ n2.setRefersToFormula("20");
- try {
- n2.setNameName("sale_1");
- fail("Expected exception");
- } catch(Exception e){
+ Exception e = assertThrows(Exception.class, () -> n2.setNameName("sale_1"));
assertEquals("The workbook already contains this name: sale_1", e.getMessage());
}
-
- wb.close();
}
@Test
@@ -659,23 +624,23 @@ public abstract class BaseTestNamedRange {
x2.setSheetIndex(wb.getSheetIndex("sheet2"));
List<? extends Name> names = wb.getNames("x");
- assertEquals("Had: " + names, 2, names.size());
+ assertEquals(2, names.size(), "Had: " + names);
assertEquals("1", names.get(0).getRefersToFormula());
assertEquals("2", names.get(1).getRefersToFormula());
assertEquals("1", wb.getName("x").getRefersToFormula());
wb.removeName(wb.getName("x"));
assertEquals("2", wb.getName("x").getRefersToFormula());
-
+
wb.close();
}
-
+
// bug 56781: name validation only checks for first character's validity and presence of spaces
// bug 60246: validate name does not allow DOT in named ranges
@Test
public void testValid() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
-
+
Name name = wb.createName();
for (String valid : Arrays.asList(
"Hello",
@@ -688,63 +653,54 @@ public abstract class BaseTestNamedRange {
)) {
name.setNameName(valid);
}
-
+
wb.close();
}
-
+
@Test
public void testInvalid() {
Workbook wb = _testDataProvider.createWorkbook();
-
+
Name name = wb.createName();
- try {
- name.setNameName("");
- fail("expected exception: (blank)");
- } catch (final IllegalArgumentException e) {
- assertEquals("Name cannot be blank", e.getMessage());
- }
-
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> name.setNameName(""));
+ assertEquals("Name cannot be blank", e.getMessage());
+
for (String invalid : Arrays.asList(
- "1number",
- "Sheet1!A1",
- "Exclamation!",
- "Has Space",
- "Colon:",
- "A-Minus",
- "A+Plus",
- "Dollar$",
- ".periodAtBeginning",
- "R", //special shorthand
- "C", //special shorthand
- "A1", // A1-style cell reference
- "R1C1", // R1C1-style cell reference
- "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
- "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
- "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
- "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
- "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters"
- )) {
- try {
- name.setNameName(invalid);
- fail("expected exception: " + invalid);
- } catch (final IllegalArgumentException e) {
- assertTrue(invalid,
- e.getMessage().startsWith("Invalid name: '"+invalid+"'"));
- }
+ "1number",
+ "Sheet1!A1",
+ "Exclamation!",
+ "Has Space",
+ "Colon:",
+ "A-Minus",
+ "A+Plus",
+ "Dollar$",
+ ".periodAtBeginning",
+ "R", //special shorthand
+ "C", //special shorthand
+ "A1", // A1-style cell reference
+ "R1C1", // R1C1-style cell reference
+ "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
+ "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
+ "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
+ "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
+ "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters"
+ )) {
+ e = assertThrows(IllegalArgumentException.class, () -> name.setNameName(invalid));
+ assertTrue(e.getMessage().startsWith("Invalid name: '"+invalid+"'"));
}
-
+
}
-
+
// bug 60260: renaming a sheet with a named range referring to a unicode (non-ASCII) sheet name
@Test
public void renameSheetWithNamedRangeReferringToUnicodeSheetName() {
Workbook wb = _testDataProvider.createWorkbook();
wb.createSheet("Sheet\u30FB1");
-
+
Name name = wb.createName();
name.setNameName("test_named_range");
name.setRefersToFormula("'Sheet\u30FB201'!A1:A6");
-
+
wb.setSheetName(0, "Sheet 1");
IOUtils.closeQuietly(wb);
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
index b7cfac9000..09c673ccc3 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.awt.BasicStroke;
import java.awt.Color;
@@ -43,7 +43,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.ImageUtils;
import org.apache.poi.util.Units;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public abstract class BaseTestPicture {
@@ -64,12 +64,12 @@ public abstract class BaseTestPicture {
double emuPX = Units.EMU_PER_PIXEL;
- assertEquals("the image height differs", inpDim.getHeight(), cmpDim.getHeight(), emuPX*6);
- assertEquals("the image width differs", inpDim.getWidth(), cmpDim.getWidth(), emuPX*6);
- assertEquals("the starting column differs", inpCA.getCol1(), cmpCA.getCol1());
- assertEquals("the column x-offset differs", inpCA.getDx1(), cmpCA.getDx1(), 1);
- assertEquals("the column y-offset differs", inpCA.getDy1(), cmpCA.getDy1(), 1);
- assertEquals("the ending columns differs", inpCA.getCol2(), cmpCA.getCol2());
+ assertEquals(inpDim.getHeight(), cmpDim.getHeight(), emuPX*6, "the image height differs");
+ assertEquals(inpDim.getWidth(), cmpDim.getWidth(), emuPX*6, "the image width differs");
+ assertEquals(inpCA.getCol1(), cmpCA.getCol1(), "the starting column differs");
+ assertEquals(inpCA.getDx1(), cmpCA.getDx1(), 1, "the column x-offset differs");
+ assertEquals(inpCA.getDy1(), cmpCA.getDy1(), 1, "the column y-offset differs");
+ assertEquals(inpCA.getCol2(), cmpCA.getCol2(), "the ending columns differs");
// can't compare row heights because of variable test heights
input.resize();
@@ -77,8 +77,8 @@ public abstract class BaseTestPicture {
Dimension imgDim = input.getImageDimension();
- assertEquals("the image height differs", imgDim.getHeight(), inpDim.getHeight()/emuPX, 1);
- assertEquals("the image width differs", imgDim.getWidth(), inpDim.getWidth()/emuPX, 1);
+ assertEquals(imgDim.getHeight(), inpDim.getHeight()/emuPX, 1, "the image height differs");
+ assertEquals(imgDim.getWidth(), inpDim.getWidth()/emuPX, 1, "the image width differs");
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestRangeCopier.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestRangeCopier.java
index f044b6f0b7..f01f16a0e4 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestRangeCopier.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestRangeCopier.java
@@ -19,17 +19,17 @@
package org.apache.poi.ss.usermodel;
-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.ITestDataProvider;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-@Ignore
+@Disabled
public abstract class BaseTestRangeCopier {
protected Sheet sheet1;
protected Sheet sheet2;
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
index 1634330138..2579ac1e98 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
@@ -17,20 +17,21 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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 java.io.IOException;
import java.util.Iterator;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* A base class for testing implementations of
@@ -139,76 +140,56 @@ public abstract class BaseTestRow {
assertEquals(-1, row.getFirstCellNum());
assertEquals(0, row.getPhysicalNumberOfCells());
}
-
+
wb2.close();
}
protected void baseTestRowBounds(int maxRowNum) throws IOException {
- Workbook workbook = _testDataProvider.createWorkbook();
- Sheet sheet = workbook.createSheet();
- //Test low row bound
- sheet.createRow(0);
- //Test low row bound exception
- try {
- sheet.createRow(-1);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- assertTrue("Did not find expected error message, had: " + e,
- e.getMessage().startsWith("Invalid row number (-1)"));
+ try (Workbook workbook = _testDataProvider.createWorkbook()) {
+ Sheet sheet = workbook.createSheet();
+ //Test low row bound
+ sheet.createRow(0);
+ //Test low row bound exception
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> sheet.createRow(-1));
+ assertTrue(e.getMessage().startsWith("Invalid row number (-1)"));
+
+ //Test high row bound
+ sheet.createRow(maxRowNum);
+ //Test high row bound exception
+ e = assertThrows(IllegalArgumentException.class, () -> sheet.createRow(maxRowNum + 1));
+ assertEquals("Invalid row number (" + (maxRowNum + 1) + ") outside allowable range (0.." + maxRowNum + ")", e.getMessage());
}
-
- //Test high row bound
- sheet.createRow(maxRowNum);
- //Test high row bound exception
- try {
- sheet.createRow(maxRowNum + 1);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- assertEquals("Invalid row number ("+(maxRowNum + 1)+") outside allowable range (0.."+maxRowNum+")", e.getMessage());
- }
-
- workbook.close();
}
protected void baseTestCellBounds(int maxCellNum) throws IOException {
- Workbook wb1 = _testDataProvider.createWorkbook();
- Sheet sheet = wb1.createSheet();
+ try (Workbook wb1 = _testDataProvider.createWorkbook()) {
+ Sheet sheet = wb1.createSheet();
- Row row = sheet.createRow(0);
- //Test low cell bound
- try {
- row.createCell(-1);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- // expected during successful test
+ Row row1 = sheet.createRow(0);
+ //Test low cell bound
+ IllegalArgumentException e;
+ e = assertThrows(IllegalArgumentException.class, () -> row1.createCell(-1));
assertTrue(e.getMessage().startsWith("Invalid column index (-1)"));
- }
- //Test high cell bound
- try {
- row.createCell(maxCellNum + 1);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- assertTrue(e.getMessage().startsWith("Invalid column index ("+(maxCellNum+1)+")"));
- }
- for(int i=0; i < maxCellNum; i++){
- row.createCell(i);
- }
- assertEquals(maxCellNum, row.getPhysicalNumberOfCells());
- Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
- wb1.close();
-
- sheet = wb2.getSheetAt(0);
- row = sheet.getRow(0);
- assertEquals(maxCellNum, row.getPhysicalNumberOfCells());
- for(int i=0; i < maxCellNum; i++){
- Cell cell = row.getCell(i);
- assertEquals(i, cell.getColumnIndex());
+ //Test high cell bound
+ e = assertThrows(IllegalArgumentException.class, () -> row1.createCell(maxCellNum + 1));
+ assertTrue(e.getMessage().startsWith("Invalid column index (" + (maxCellNum + 1) + ")"));
+
+ for (int i = 0; i < maxCellNum; i++) {
+ row1.createCell(i);
+ }
+ assertEquals(maxCellNum, row1.getPhysicalNumberOfCells());
+
+ try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
+ sheet = wb2.getSheetAt(0);
+ Row row2 = sheet.getRow(0);
+ assertEquals(maxCellNum, row2.getPhysicalNumberOfCells());
+ for (int i = 0; i < maxCellNum; i++) {
+ Cell cell = row2.getCell(i);
+ assertEquals(i, cell.getColumnIndex());
+ }
+ }
}
- wb2.close();
}
/**
@@ -223,9 +204,7 @@ public abstract class BaseTestRow {
// New row has last col -1
assertEquals(-1, row.getLastCellNum());
- if(row.getLastCellNum() == 0) {
- fail("Identified bug 43901");
- }
+ assertNotEquals(0, row.getLastCellNum(), "Identified bug 43901");
// Create two cells, will return one higher
// than that for the last number
@@ -307,7 +286,7 @@ public abstract class BaseTestRow {
assertNull(row.getCell(3));
assertNull(row.getCell(4));
assertEquals(CellType.NUMERIC, row.getCell(5).getCellType());
-
+
workbook.close();
}
@@ -452,7 +431,7 @@ public abstract class BaseTestRow {
// Save, load and re-check
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
wb1.close();
-
+
sheet = wb2.getSheetAt(0);
row1 = sheet.getRow(0);
@@ -464,10 +443,10 @@ public abstract class BaseTestRow {
assertNull(row1.getRowStyle());
assertEquals(style, row2.getRowStyle());
assertEquals(4, style.getDataFormat());
-
+
wb2.close();
}
-
+
@Test
public void testCellShiftingRight() {
Workbook wb = _testDataProvider.createWorkbook();
@@ -480,26 +459,23 @@ public abstract class BaseTestRow {
row.createCell(4, CellType.NUMERIC).setCellValue(4);//E
row.createCell(5, CellType.NUMERIC).setCellValue(5);//F
row.createCell(6, CellType.NUMERIC).setCellValue(6);//G
- try {
- row.shiftCellsLeft(6, 4, 2); // range [6-4] is illegal
- fail("expected shiftLeft to fail");
- } catch (IllegalArgumentException e){
- row.shiftCellsRight(2, 4, 1);
- //should be [0.0, 1.0, null, 2.0, 3.0, 4.0, 6.0, null]
-
- Cell h1 = row.getCell(7);
- assertNull(h1);
- Cell g1 = row.getCell(6);
- assertEquals(6, g1.getNumericCellValue(), 0.01);
- Cell f1 = row.getCell(5);
- assertEquals(4, f1.getNumericCellValue(), 0.01);
- Cell e1 = row.getCell(4);
- assertEquals(3, e1.getNumericCellValue(), 0.01);
- Cell d1 = row.getCell(3);
- assertEquals(2, d1.getNumericCellValue(), 0.01);
- Cell c1 = row.getCell(2);
- assertNull(c1);
- }
+
+ assertThrows(IllegalArgumentException.class, () -> row.shiftCellsLeft(6, 4, 2), "range [6-4] is illegal");
+ row.shiftCellsRight(2, 4, 1);
+ //should be [0.0, 1.0, null, 2.0, 3.0, 4.0, 6.0, null]
+
+ Cell h1 = row.getCell(7);
+ assertNull(h1);
+ Cell g1 = row.getCell(6);
+ assertEquals(6, g1.getNumericCellValue(), 0.01);
+ Cell f1 = row.getCell(5);
+ assertEquals(4, f1.getNumericCellValue(), 0.01);
+ Cell e1 = row.getCell(4);
+ assertEquals(3, e1.getNumericCellValue(), 0.01);
+ Cell d1 = row.getCell(3);
+ assertEquals(2, d1.getNumericCellValue(), 0.01);
+ Cell c1 = row.getCell(2);
+ assertNull(c1);
}
@Test
public void testCellShiftingLeft() {
@@ -513,24 +489,21 @@ public abstract class BaseTestRow {
row.createCell(4, CellType.NUMERIC).setCellValue(4);//E
row.createCell(5, CellType.NUMERIC).setCellValue(5);//F
row.createCell(6, CellType.NUMERIC).setCellValue(6);//G
- try {
- row.shiftCellsLeft(4, 6, -2); // step = -1 is illegal
- fail("expected shiftLeft to fail");
- } catch (IllegalArgumentException e){
- row.shiftCellsLeft(4, 6, 2);
- //should be [0.0, 1.0, 4.0, 5.0, 6.0, null, null, null]
-
- Cell b1 = row.getCell(1);
- assertEquals(1, b1.getNumericCellValue(), 0.01);
- Cell c1 = row.getCell(2);
- assertEquals(4, c1.getNumericCellValue(), 0.01);
- Cell d1 = row.getCell(3);
- assertEquals(5, d1.getNumericCellValue(), 0.01);
- Cell e1 = row.getCell(4);
- assertEquals(6, e1.getNumericCellValue(), 0.01);
- Cell f1 = row.getCell(5);
- assertNull(f1);
- }
+
+ assertThrows(IllegalArgumentException.class, () -> row.shiftCellsLeft(4, 6, -2), "step = -1 is illegal");
+ row.shiftCellsLeft(4, 6, 2);
+ //should be [0.0, 1.0, 4.0, 5.0, 6.0, null, null, null]
+
+ Cell b1 = row.getCell(1);
+ assertEquals(1, b1.getNumericCellValue(), 0.01);
+ Cell c1 = row.getCell(2);
+ assertEquals(4, c1.getNumericCellValue(), 0.01);
+ Cell d1 = row.getCell(3);
+ assertEquals(5, d1.getNumericCellValue(), 0.01);
+ Cell e1 = row.getCell(4);
+ assertEquals(6, e1.getNumericCellValue(), 0.01);
+ Cell f1 = row.getCell(5);
+ assertNull(f1);
}
@Test
@@ -538,13 +511,11 @@ public abstract class BaseTestRow {
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet("sheet1");
- assertEquals("Sheet without rows should return -1 as lastRowNum",
- -1, sheet.getLastRowNum());
+ assertEquals(-1, sheet.getLastRowNum(), "Sheet without rows should return -1 as lastRowNum");
Row row = sheet.createRow(0);
assertNotNull(row);
- assertEquals("Sheet with one row should return 0 as lastRowNum",
- 0, sheet.getLastRowNum());
+ assertEquals(0, sheet.getLastRowNum(), "Sheet with one row should return 0 as lastRowNum");
}
@Test
@@ -552,12 +523,10 @@ public abstract class BaseTestRow {
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet("sheet1");
- assertEquals("Sheet without rows should return -1 as firstRowNum",
- -1, sheet.getFirstRowNum());
+ assertEquals(-1, sheet.getFirstRowNum(), "Sheet without rows should return -1 as firstRowNum");
Row row = sheet.createRow(0);
assertNotNull(row);
- assertEquals("Sheet with one row should return 0 as firstRowNum",
- 0, sheet.getFirstRowNum());
+ assertEquals(0, sheet.getFirstRowNum(), "Sheet with one row should return 0 as firstRowNum");
}
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
index 2af3022617..978c36c278 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
@@ -18,15 +18,15 @@
package org.apache.poi.ss.usermodel;
import static org.apache.poi.POITestCase.assertBetween;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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.Assumptions.assumeTrue;
import java.io.IOException;
import java.util.Arrays;
@@ -44,7 +44,7 @@ import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.PaneInformation;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing {@link org.apache.poi.hssf.usermodel.HSSFCell},
@@ -105,24 +105,24 @@ public abstract class BaseTestSheet {
}
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void createRowBeforeFirstRow() throws IOException {
try (Workbook workbook = _testDataProvider.createWorkbook()) {
final Sheet sh = workbook.createSheet();
sh.createRow(0);
// Negative rows not allowed
- sh.createRow(-1);
+ assertThrows(IllegalArgumentException.class, () -> sh.createRow(-1));
}
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void createRowAfterLastRow() throws IOException {
final SpreadsheetVersion version = _testDataProvider.getSpreadsheetVersion();
try (Workbook workbook = _testDataProvider.createWorkbook()) {
final Sheet sh = workbook.createSheet();
sh.createRow(version.getLastRowIndex());
// Row number must be between 0 and last row
- sh.createRow(version.getLastRowIndex() + 1);
+ assertThrows(IllegalArgumentException.class, () -> sh.createRow(version.getLastRowIndex() + 1));
}
}
@@ -189,12 +189,12 @@ public abstract class BaseTestSheet {
//Check that the cells are not somehow linked
cell.setCellValue(factory.createRichTextString("Difference Check"));
cell2.setCellFormula("cos(2)");
- if ("Difference Check".equals(clonedRow.getCell(0).getRichStringCellValue().getString())) {
- fail("string cell not properly cloned");
- }
- if ("COS(2)".equals(clonedRow.getCell(1).getCellFormula())) {
- fail("formula cell not properly cloned");
- }
+
+ assertNotEquals("Difference Check", clonedRow.getCell(0).getRichStringCellValue().getString(),
+ "string cell not properly cloned");
+
+ assertNotEquals("COS(2)", clonedRow.getCell(1).getCellFormula(), "formula cell not properly cloned");
+
assertEquals(clonedRow.getCell(0).getRichStringCellValue().getString(), "clone_test");
assertEquals(clonedRow.getCell(1).getCellFormula(), "SIN(1)");
}
@@ -281,34 +281,34 @@ public abstract class BaseTestSheet {
final CellRangeAddress duplicateRegion = new CellRangeAddress(0, 1, 0, 1); //A1:B2
assertThrows(
- "Should not be able to add a merged region (" + duplicateRegion.formatAsString() + ") " +
- "if sheet already contains the same merged region (" + baseRegion.formatAsString() + ")",
IllegalStateException.class,
- () -> sheet.addMergedRegion(duplicateRegion)
+ () -> sheet.addMergedRegion(duplicateRegion),
+ "Should not be able to add a merged region (" + duplicateRegion.formatAsString() + ") " +
+ "if sheet already contains the same merged region (" + baseRegion.formatAsString() + ")"
);
final CellRangeAddress partiallyOverlappingRegion = new CellRangeAddress(1, 2, 1, 2); //B2:C3
assertThrows(
- "Should not be able to add a merged region (" + partiallyOverlappingRegion.formatAsString() + ") " +
- "if it partially overlaps with an existing merged region (" + baseRegion.formatAsString() + ")",
IllegalStateException.class,
- () -> sheet.addMergedRegion(partiallyOverlappingRegion)
+ () -> sheet.addMergedRegion(partiallyOverlappingRegion),
+ "Should not be able to add a merged region (" + partiallyOverlappingRegion.formatAsString() + ") " +
+ "if it partially overlaps with an existing merged region (" + baseRegion.formatAsString() + ")"
);
final CellRangeAddress subsetRegion = new CellRangeAddress(0, 1, 0, 0); //A1:A2
assertThrows(
- "Should not be able to add a merged region (" + subsetRegion.formatAsString() + ") " +
- "if it is a formal subset of an existing merged region (" + baseRegion.formatAsString() + ")",
IllegalStateException.class,
- () -> sheet.addMergedRegion(subsetRegion)
+ () -> sheet.addMergedRegion(subsetRegion),
+ "Should not be able to add a merged region (" + subsetRegion.formatAsString() + ") " +
+ "if it is a formal subset of an existing merged region (" + baseRegion.formatAsString() + ")"
);
final CellRangeAddress supersetRegion = new CellRangeAddress(0, 2, 0, 2); //A1:C3
assertThrows(
- "Should not be able to add a merged region (" + supersetRegion.formatAsString() + ") " +
- "if it is a formal superset of an existing merged region (" + baseRegion.formatAsString() + ")",
IllegalStateException.class,
- () -> sheet.addMergedRegion(supersetRegion)
+ () -> sheet.addMergedRegion(supersetRegion),
+ "Should not be able to add a merged region (" + supersetRegion.formatAsString() + ") " +
+ "if it is a formal superset of an existing merged region (" + baseRegion.formatAsString() + ")"
);
final CellRangeAddress disjointRegion = new CellRangeAddress(10, 11, 10, 11);
@@ -326,9 +326,9 @@ public abstract class BaseTestSheet {
final Sheet sheet = wb.createSheet();
final CellRangeAddress region = CellRangeAddress.valueOf("A1:A1");
assertThrows(
- "Should not be able to add a single-cell merged region (" + region.formatAsString() + ")",
IllegalArgumentException.class,
- () -> sheet.addMergedRegion(region)
+ () -> sheet.addMergedRegion(region),
+ "Should not be able to add a single-cell merged region (" + region.formatAsString() + ")"
);
}
}
@@ -387,27 +387,27 @@ public abstract class BaseTestSheet {
sheet.removeMergedRegion(0);
region = sheet.getMergedRegion(0);
- assertEquals("Left over region should be starting at row 2", 2, region.getFirstRow());
+ assertEquals(2, region.getFirstRow(), "Left over region should be starting at row 2");
sheet.removeMergedRegion(0);
- assertEquals("there should be no merged regions left!", 0, sheet.getNumMergedRegions());
+ assertEquals(0, sheet.getNumMergedRegions(), "there should be no merged regions left!");
//an, add, remove, get(0) would null pointer
assertEquals(0, sheet.addMergedRegion(region));
- assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
+ assertEquals(1, sheet.getNumMergedRegions(), "there should now be one merged region!");
sheet.removeMergedRegion(0);
- assertEquals("there should now be zero merged regions!", 0, sheet.getNumMergedRegions());
+ assertEquals(0, sheet.getNumMergedRegions(), "there should now be zero merged regions!");
//add it again!
region.setLastRow(4);
assertEquals(0, sheet.addMergedRegion(region));
- assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
+ assertEquals(1, sheet.getNumMergedRegions(), "there should now be one merged region!");
//should exist now!
- assertTrue("there isn't more than one merged region in there", 1 <= sheet.getNumMergedRegions());
+ assertTrue(1 <= sheet.getNumMergedRegions(), "there isn't more than one merged region in there");
region = sheet.getMergedRegion(0);
- assertEquals("the merged row to doesn't match the one we put in ", 4, region.getLastRow());
+ assertEquals(4, region.getLastRow(), "the merged row to doesn't match the one we put in ");
}
}
@@ -461,7 +461,7 @@ public abstract class BaseTestSheet {
region = sheet.getMergedRegion(0);
CellRangeAddress expectedRegion = CellRangeAddress.valueOf("A3:B3");
- assertEquals("Merged region should shift down a row", expectedRegion, region);
+ assertEquals(expectedRegion, region, "Merged region should shift down a row");
}
}
@@ -493,9 +493,9 @@ public abstract class BaseTestSheet {
// the safe version of addMergedRegion should throw when trying to add a merged region that overlaps an existing region
assertTrue(sh.getMergedRegions().contains(region2));
assertThrows(
- "region3 overlaps already added merged region2.",
IllegalStateException.class,
- () -> sh.addMergedRegion(region3)
+ () -> sh.addMergedRegion(region3),
+ "region3 overlaps already added merged region2."
);
assertFalse(sh.getMergedRegions().contains(region3));
@@ -504,9 +504,9 @@ public abstract class BaseTestSheet {
// validation methods should detect a problem with previously added merged regions (runs in O(n^2) time)
assertThrows(
- "Sheet contains merged regions A1:B2 and B2:C3, which overlap at B2.",
IllegalStateException.class,
- sh::validateMergedRegions
+ sh::validateMergedRegions,
+ "Sheet contains merged regions A1:B2 and B2:C3, which overlap at B2."
);
}
}
@@ -640,9 +640,10 @@ public abstract class BaseTestSheet {
r.createCell(1).setCellFormula("A1*2");
Sheet s1 = wb.cloneSheet(0);
r = s1.getRow(0);
- assertEquals("double", r.getCell(0).getNumericCellValue(), 1, 0); // sanity check
+ // sanity check
+ assertEquals(r.getCell(0).getNumericCellValue(), 1, 0, "double");
assertNotNull(r.getCell(1));
- assertEquals("formula", r.getCell(1).getCellFormula(), "A1*2");
+ assertEquals(r.getCell(1).getCellFormula(), "A1*2", "formula");
}
}
@@ -660,7 +661,7 @@ public abstract class BaseTestSheet {
Cell cell = row.createCell(0);
CellStyle style2 = cell.getCellStyle();
assertNotNull(style2);
- assertEquals("style should match", style.getIndex(), style2.getIndex());
+ assertEquals(style.getIndex(), style2.getIndex(), "style should match");
}
}
@@ -1187,15 +1188,15 @@ public abstract class BaseTestSheet {
Sheet sheet = workbook.createSheet();
Cell cell = sheet.createRow(5).createCell(1);
- assertEquals("list size before add", 0, sheet.getHyperlinkList().size());
+ assertEquals(0, sheet.getHyperlinkList().size(), "list size before add");
cell.setHyperlink(hyperlink);
- assertEquals("list size after add", 1, sheet.getHyperlinkList().size());
+ assertEquals(1, sheet.getHyperlinkList().size(), "list size after add");
- assertEquals("list", hyperlink, sheet.getHyperlinkList().get(0));
+ assertEquals(hyperlink, sheet.getHyperlinkList().get(0), "list");
CellAddress B6 = new CellAddress(5, 1);
- assertEquals("row, col", hyperlink, sheet.getHyperlink(5, 1));
- assertEquals("addr", hyperlink, sheet.getHyperlink(B6));
- assertNull("no hyperlink at A1", sheet.getHyperlink(CellAddress.A1));
+ assertEquals(hyperlink, sheet.getHyperlink(5, 1), "row, col");
+ assertEquals(hyperlink, sheet.getHyperlink(B6), "addr");
+ assertNull(sheet.getHyperlink(CellAddress.A1), "no hyperlink at A1");
}
}
@@ -1302,9 +1303,8 @@ public abstract class BaseTestSheet {
// active cell behavior is undefined if not set.
// HSSFSheet defaults to A1 active cell, while XSSFSheet defaults to null.
- if (sheet.getActiveCell() != null && !sheet.getActiveCell().equals(CellAddress.A1)) {
- fail("If not set, active cell should default to null or A1");
- }
+ CellAddress ac = sheet.getActiveCell();
+ assertTrue(ac == null || CellAddress.A1.equals(ac), "If not set, active cell should default to null or A1");
sheet.setActiveCell(B42);
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java
index abbb0d1815..c7584ef978 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.usermodel;
-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.Calendar;
import java.util.Date;
@@ -27,9 +27,9 @@ import java.util.Locale;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.LocaleUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing automatic sizing of sheet columns
@@ -42,13 +42,13 @@ public abstract class BaseTestSheetAutosizeColumn {
private static Locale userLocale;
- @BeforeClass
+ @BeforeAll
public static void initLocale() {
userLocale = LocaleUtil.getUserLocale();
LocaleUtil.setUserLocale(Locale.ROOT);
}
- @AfterClass
+ @AfterAll
public static void resetLocale() {
LocaleUtil.setUserLocale(userLocale);
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetHiding.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetHiding.java
index 1611f95a8e..78642d21b8 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetHiding.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetHiding.java
@@ -17,17 +17,17 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.apache.poi.ss.ITestDataProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public abstract class BaseTestSheetHiding {
@@ -47,61 +47,50 @@ public abstract class BaseTestSheetHiding {
_file2 = file2;
}
- @Before
+ @BeforeEach
public void setUp() {
wbH = _testDataProvider.openSampleWorkbook(_file1);
wbU = _testDataProvider.openSampleWorkbook(_file2);
}
- @After
+ @AfterEach
public void teadDown() throws IOException {
wbH.close();
wbU.close();
}
-
+
@Test
public final void testSheetVisibility() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- wb.createSheet("MySheet");
-
- assertFalse(wb.isSheetHidden(0));
- assertFalse(wb.isSheetVeryHidden(0));
- assertEquals(SheetVisibility.VISIBLE, wb.getSheetVisibility(0));
-
- wb.setSheetVisibility(0, SheetVisibility.HIDDEN);
- assertTrue(wb.isSheetHidden(0));
- assertFalse(wb.isSheetVeryHidden(0));
- assertEquals(SheetVisibility.HIDDEN, wb.getSheetVisibility(0));
-
- wb.setSheetVisibility(0, SheetVisibility.VERY_HIDDEN);
- assertFalse(wb.isSheetHidden(0));
- assertTrue(wb.isSheetVeryHidden(0));
- assertEquals(SheetVisibility.VERY_HIDDEN, wb.getSheetVisibility(0));
-
- wb.setSheetVisibility(0, SheetVisibility.VISIBLE);
- assertFalse(wb.isSheetHidden(0));
- assertFalse(wb.isSheetVeryHidden(0));
- assertEquals(SheetVisibility.VISIBLE, wb.getSheetVisibility(0));
-
- // verify limits-check
-
- // check sheet-index with one more => throws exception
- try {
- wb.setSheetVisibility(1, SheetVisibility.HIDDEN);
- fail("Should catch exception here");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ wb.createSheet("MySheet");
- // check sheet-index with index out of bounds => throws exception
- try {
- wb.setSheetVisibility(10, SheetVisibility.HIDDEN);
- fail("Should catch exception here");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertFalse(wb.isSheetHidden(0));
+ assertFalse(wb.isSheetVeryHidden(0));
+ assertEquals(SheetVisibility.VISIBLE, wb.getSheetVisibility(0));
+
+ wb.setSheetVisibility(0, SheetVisibility.HIDDEN);
+ assertTrue(wb.isSheetHidden(0));
+ assertFalse(wb.isSheetVeryHidden(0));
+ assertEquals(SheetVisibility.HIDDEN, wb.getSheetVisibility(0));
+
+ wb.setSheetVisibility(0, SheetVisibility.VERY_HIDDEN);
+ assertFalse(wb.isSheetHidden(0));
+ assertTrue(wb.isSheetVeryHidden(0));
+ assertEquals(SheetVisibility.VERY_HIDDEN, wb.getSheetVisibility(0));
- wb.close();
+ wb.setSheetVisibility(0, SheetVisibility.VISIBLE);
+ assertFalse(wb.isSheetHidden(0));
+ assertFalse(wb.isSheetVeryHidden(0));
+ assertEquals(SheetVisibility.VISIBLE, wb.getSheetVisibility(0));
+
+ // verify limits-check
+
+ // check sheet-index with one more => throws exception
+ assertThrows(IllegalArgumentException.class, () -> wb.setSheetVisibility(1, SheetVisibility.HIDDEN));
+
+ // check sheet-index with index out of bounds => throws exception
+ assertThrows(IllegalArgumentException.class, () -> wb.setSheetVisibility(10, SheetVisibility.HIDDEN));
+ }
}
/**
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftColumns.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftColumns.java
index 407cba71c8..86f56daf61 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftColumns.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftColumns.java
@@ -18,11 +18,12 @@
*/
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
@@ -31,8 +32,8 @@ import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellUtil;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public abstract class BaseTestSheetShiftColumns {
protected Sheet sheet1;
@@ -41,7 +42,7 @@ public abstract class BaseTestSheetShiftColumns {
protected ITestDataProvider _testDataProvider;
- @Before
+ @BeforeEach
public void init() {
int rowIndex = 0;
sheet1 = workbook.createSheet("sheet1");
@@ -157,9 +158,9 @@ public abstract class BaseTestSheetShiftColumns {
assertNull(newb6Null);
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void testShiftTwoColumnsLeft() {
- sheet1.shiftColumns(1, 2, -2);
+ assertThrows(IllegalStateException.class, () -> sheet1.shiftColumns(1, 2, -2));
}
@Test
@@ -229,8 +230,8 @@ public abstract class BaseTestSheetShiftColumns {
verifyHyperlink(shiftedRow.getCell(4), HyperlinkType.URL, "https://poi.apache.org/");
// Make sure hyperlinks were moved and not copied
- assertNull("Document hyperlink should be moved, not copied", sh.getHyperlink(0, 0));
- assertNull("URL hyperlink should be moved, not copied", sh.getHyperlink(1, 0));
+ assertNull(sh.getHyperlink(0, 0), "Document hyperlink should be moved, not copied");
+ assertNull(sh.getHyperlink(1, 0), "URL hyperlink should be moved, not copied");
assertEquals(4, sh.getHyperlinkList().size());
read.close();
@@ -245,11 +246,10 @@ public abstract class BaseTestSheetShiftColumns {
private void verifyHyperlink(Cell cell, HyperlinkType linkType, String ref) {
assertTrue(cellHasHyperlink(cell));
- if (cell != null) {
- Hyperlink link = cell.getHyperlink();
- assertEquals(linkType, link.getType());
- assertEquals(ref, link.getAddress());
- }
+ assertNotNull(cell);
+ Hyperlink link = cell.getHyperlink();
+ assertEquals(linkType, link.getType());
+ assertEquals(ref, link.getAddress());
}
private boolean cellHasHyperlink(Cell cell) {
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java
index 25a564c917..8b4ecf8eb9 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java
@@ -19,12 +19,12 @@ package org.apache.poi.ss.usermodel;
import static org.apache.poi.POITestCase.skipTest;
import static org.apache.poi.POITestCase.testPassesNow;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
+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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.IOException;
import java.util.ArrayList;
@@ -36,7 +36,7 @@ import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests row shifting capabilities.
@@ -136,16 +136,17 @@ public abstract class BaseTestSheetShiftRows {
* When shifting rows, the page breaks should go with it
*/
@Test
- public void testShiftRowBreaks() throws IOException { // TODO - enable XSSF test
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet s = wb.createSheet();
- Row row = s.createRow(4);
- row.createCell(0).setCellValue("test");
- s.setRowBreak(4);
-
- s.shiftRows(4, 4, 2);
- assertTrue("Row number 6 should have a pagebreak", s.isRowBroken(6));
- wb.close();
+ public void testShiftRowBreaks() throws IOException {
+ // TODO - enable XSSF test
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet s = wb.createSheet();
+ Row row = s.createRow(4);
+ row.createCell(0).setCellValue("test");
+ s.setRowBreak(4);
+
+ s.shiftRows(4, 4, 2);
+ assertTrue(s.isRowBroken(6), "Row number 6 should have a pagebreak");
+ }
}
@Test
@@ -219,8 +220,8 @@ public abstract class BaseTestSheetShiftRows {
assertEquals(2, sheet.getLastRowNum());
// Verify comments are in the position expected
- assertNull("Had: " + (sheet.getCellComment(new CellAddress(0,0)) == null ? "null" : sheet.getCellComment(new CellAddress(0,0)).getString()),
- sheet.getCellComment(new CellAddress(0,0)));
+ assertNull(sheet.getCellComment(new CellAddress(0,0)),
+ "Had: " + (sheet.getCellComment(new CellAddress(0,0)) == null ? "null" : sheet.getCellComment(new CellAddress(0,0)).getString()));
assertNotNull(sheet.getCellComment(new CellAddress(1,0)));
assertNotNull(sheet.getCellComment(new CellAddress(2,0)));
}
@@ -570,18 +571,17 @@ public abstract class BaseTestSheetShiftRows {
verifyHyperlink(shiftedRow.getCell(1), HyperlinkType.URL, "https://poi.apache.org/");
// Make sure hyperlinks were moved and not copied
- assertNull("Document hyperlink should be moved, not copied", sh.getHyperlink(0, 0));
- assertNull("URL hyperlink should be moved, not copied", sh.getHyperlink(0, 1));
+ assertNull(sh.getHyperlink(0, 0), "Document hyperlink should be moved, not copied");
+ assertNull(sh.getHyperlink(0, 1), "URL hyperlink should be moved, not copied");
// Make sure hyperlink in overwritten row is deleted
assertEquals(3, sh.getHyperlinkList().size());
CellAddress unexpectedLinkAddress = new CellAddress("C4");
for (Hyperlink link : sh.getHyperlinkList()) {
final CellAddress linkAddress = new CellAddress(link.getFirstRow(), link.getFirstColumn());
- if (linkAddress.equals(unexpectedLinkAddress)) {
- fail("Row 4, including the hyperlink at C4, should have " +
- "been deleted when Row 1 was shifted on top of it.");
- }
+ assertNotEquals(linkAddress, unexpectedLinkAddress,
+ "Row 4, including the hyperlink at C4, should have " +
+ "been deleted when Row 1 was shifted on top of it.");
}
// Make sure unaffected rows are not shifted
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java
index 0c81191b1a..34d5038544 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java
@@ -17,15 +17,15 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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.Assumptions.assumeTrue;
import java.io.IOException;
import java.util.Arrays;
@@ -34,8 +34,8 @@ import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.formula.FormulaParseException;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing usermodel API for array formulas.<br>
@@ -77,12 +77,8 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
Sheet sheet = workbook.createSheet();
Cell cell = sheet.createRow(0).createCell(0);
assertFalse(cell.isPartOfArrayFormulaGroup());
- try {
- cell.getArrayFormulaRange();
- fail("expected exception");
- } catch (IllegalStateException e) {
- assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
- }
+ IllegalStateException e = assertThrows(IllegalStateException.class, cell::getArrayFormulaRange);
+ assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
// row 3 does not yet exist
assertNull(sheet.getRow(2));
@@ -139,12 +135,12 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
* Passing an incorrect formula to sheet.setArrayFormula
* should throw FormulaParseException
*/
- @Test(expected = FormulaParseException.class)
+ @Test
public final void testSetArrayFormula_incorrectFormula() throws IOException {
try (Workbook workbook = _testDataProvider.createWorkbook()) {
Sheet sheet = workbook.createSheet();
CellRangeAddress cra = new CellRangeAddress(10, 10, 10, 10);
- sheet.setArrayFormula("incorrect-formula(C11_C12*D11_D12)", cra);
+ assertThrows(FormulaParseException.class, () -> sheet.setArrayFormula("incorrect-formula(C11_C12*D11_D12)", cra));
}
}
@@ -159,19 +155,11 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
Cell cell = sheet.createRow(0).createCell(0);
assertFalse(cell.isPartOfArrayFormulaGroup());
- try {
- cell.getArrayFormulaRange();
- fail("expected exception");
- } catch (IllegalStateException e) {
- assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
- }
+ IllegalStateException e = assertThrows(IllegalStateException.class, cell::getArrayFormulaRange);
+ assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
- try {
- sheet.removeArrayFormula(cell);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
- }
+ IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> sheet.removeArrayFormula(cell));
+ assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
}
}
@@ -201,13 +189,9 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
// cells C4:C6 are not included in array formula,
// invocation of sheet.removeArrayFormula on any of them throws IllegalArgumentException
for (Cell acell : cr) {
- try {
- sheet.removeArrayFormula(acell);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- String ref = new CellReference(acell).formatAsString();
- assertEquals("Cell " + ref + " is not part of an array formula.", e.getMessage());
- }
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> sheet.removeArrayFormula(acell));
+ String ref = new CellReference(acell).formatAsString();
+ assertEquals("Cell " + ref + " is not part of an array formula.", e.getMessage());
}
}
}
@@ -299,15 +283,12 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
CellRange<? extends Cell> mrange =
sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
for (Cell mcell : mrange) {
- try {
- assertEquals(CellType.FORMULA, mcell.getCellType());
- mcell.setCellType(CellType.NUMERIC);
- fail("expected exception");
- } catch (IllegalStateException e) {
- CellReference ref = new CellReference(mcell);
- String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array.";
- assertEquals(msg, e.getMessage());
- }
+ assertEquals(CellType.FORMULA, mcell.getCellType());
+ IllegalStateException e = assertThrows(IllegalStateException.class, () -> mcell.setCellType(CellType.NUMERIC));
+ CellReference ref = new CellReference(mcell);
+ String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array.";
+ assertEquals(msg, e.getMessage());
+
// a failed invocation of Cell.setCellType leaves the cell
// in the state that it was in prior to the invocation
assertEquals(CellType.FORMULA, mcell.getCellType());
@@ -342,15 +323,12 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
for (Cell mcell : mrange) {
//we cannot set individual formulas for cells included in an array formula
- try {
- assertEquals("A1:A3*B1:B3", mcell.getCellFormula());
- mcell.setCellFormula("A1+A2");
- fail("expected exception");
- } catch (IllegalStateException e) {
- CellReference ref = new CellReference(mcell);
- String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array.";
- assertEquals(msg, e.getMessage());
- }
+ assertEquals("A1:A3*B1:B3", mcell.getCellFormula());
+ IllegalStateException e = assertThrows(IllegalStateException.class, () -> mcell.setCellFormula("A1+A2"));
+ CellReference ref = new CellReference(mcell);
+ String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array.";
+ assertEquals(msg, e.getMessage());
+
// a failed invocation of Cell.setCellFormula leaves the cell
// in the state that it was in prior to the invocation
assertEquals("A1:A3*B1:B3", mcell.getCellFormula());
@@ -386,14 +364,11 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
for (Cell mcell : mrange) {
int columnIndex = mcell.getColumnIndex();
Row mrow = mcell.getRow();
- try {
- mrow.removeCell(mcell);
- fail("expected exception");
- } catch (IllegalStateException e) {
- CellReference ref = new CellReference(mcell);
- String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array.";
- assertEquals(msg, e.getMessage());
- }
+ IllegalStateException e = assertThrows(IllegalStateException.class, () -> mrow.removeCell(mcell));
+ CellReference ref = new CellReference(mcell);
+ String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array.";
+ assertEquals(msg, e.getMessage());
+
// a failed invocation of Row.removeCell leaves the row
// in the state that it was in prior to the invocation
assertSame(mcell, mrow.getCell(columnIndex));
@@ -432,13 +407,10 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
for (Cell mcell : mrange) {
int columnIndex = mcell.getColumnIndex();
Row mrow = mcell.getRow();
- try {
- sheet.removeRow(mrow);
- fail("expected exception");
- } catch (IllegalStateException e) {
- // String msg = "Row[rownum="+mrow.getRowNum()+"] contains cell(s) included in a multi-cell array formula. You cannot change part of an array.";
- // assertEquals(msg, e.getMessage());
- }
+ assertThrows(IllegalStateException.class, () -> sheet.removeRow(mrow));
+ // String msg = "Row[rownum="+mrow.getRowNum()+"] contains cell(s) included in a multi-cell array formula. You cannot change part of an array.";
+ // assertEquals(msg, e.getMessage());
+
// a failed invocation of Row.removeCell leaves the row
// in the state that it was in prior to the invocation
assertSame(mrow, sheet.getRow(mrow.getRowNum()));
@@ -485,13 +457,9 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
"B1:D6", "B1:G3", "E1:G6", "B4:G6" // 2-row/2-column intersection
)) {
CellRangeAddress cra = CellRangeAddress.valueOf(ref);
- try {
- sheet.addMergedRegion(cra);
- fail("expected exception with ref " + ref);
- } catch (IllegalStateException e) {
- String msg = "The range " + cra.formatAsString() + " intersects with a multi-cell array formula. You cannot merge cells of an array.";
- assertEquals(msg, e.getMessage());
- }
+ IllegalStateException e = assertThrows(IllegalStateException.class, () -> sheet.addMergedRegion(cra));
+ String msg = "The range " + cra.formatAsString() + " intersects with a multi-cell array formula. You cannot merge cells of an array.";
+ assertEquals(msg, e.getMessage());
}
//the number of merged regions remains the same
assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions());
@@ -503,13 +471,9 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
"C6:F6", //bottom
"B2:B5", "H7:J9")) {
CellRangeAddress cra = CellRangeAddress.valueOf(ref);
- try {
- sheet.addMergedRegion(cra);
- expectedNumMergedRegions++;
- assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions());
- } catch (IllegalStateException e) {
- fail("did not expect exception with ref: " + ref + "\n" + e.getMessage());
- }
+ sheet.addMergedRegion(cra);
+ expectedNumMergedRegions++;
+ assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions());
}
}
@@ -522,7 +486,7 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
//single-cell array formulas behave just like normal cells - we can change the cell type
CellRange<? extends Cell> srange =
- sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
+ sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
Cell scell = srange.getTopLeftCell();
assertEquals("SUM(A4:A6,B4:B6)", scell.getCellFormula());
sheet.shiftRows(0, 0, 1);
@@ -530,14 +494,9 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
//we cannot set individual formulas for cells included in an array formula
sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
-
- try {
- sheet.shiftRows(0, 0, 1);
- fail("expected exception");
- } catch (IllegalStateException e) {
- String msg = "Row[rownum=0] contains cell(s) included in a multi-cell array formula. You cannot change part of an array.";
- assertEquals(msg, e.getMessage());
- }
+ IllegalStateException e = assertThrows(IllegalStateException.class, () -> sheet.shiftRows(0, 0, 1));
+ String msg = "Row[rownum=0] contains cell(s) included in a multi-cell array formula. You cannot change part of an array.";
+ assertEquals(msg, e.getMessage());
/*
TODO: enable shifting the whole array
@@ -556,8 +515,8 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
}
}
- @Ignore("See bug 59728")
- @Test(expected = IllegalStateException.class)
+ @Disabled("See bug 59728")
+ @Test
public void shouldNotBeAbleToCreateArrayFormulaOnPreexistingMergedRegion() throws IOException {
/*
* m = merged region
@@ -578,7 +537,7 @@ public abstract class BaseTestSheetUpdateArrayFormulas {
assumeTrue(mergedRegion.intersects(arrayFormula));
assumeTrue(arrayFormula.intersects(mergedRegion));
// expected exception: should not be able to create an array formula that intersects with a merged region
- sheet.setArrayFormula("SUM(A1:A3)", arrayFormula);
+ assertThrows(IllegalStateException.class, () -> sheet.setArrayFormula("SUM(A1:A3)", arrayFormula));
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
index b36078d310..08835946ba 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
@@ -17,15 +17,14 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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 java.io.IOException;
import java.io.OutputStream;
@@ -38,7 +37,7 @@ import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.NullOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public abstract class BaseTestWorkbook {
@@ -67,7 +66,7 @@ public abstract class BaseTestWorkbook {
* should not be able to advance an iterator when the
* underlying data has been reordered
*/
- @Test(expected=ConcurrentModificationException.class)
+ @Test
public void sheetIterator_sheetsReordered() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
wb.createSheet("Sheet0");
@@ -79,7 +78,7 @@ public abstract class BaseTestWorkbook {
wb.setSheetOrder("Sheet2", 1);
// Iterator order should be fixed when iterator is created
- assertEquals("Sheet1", it.next().getSheetName());
+ assertThrows(ConcurrentModificationException.class, it::next);
}
}
@@ -88,7 +87,7 @@ public abstract class BaseTestWorkbook {
* should not be able to advance an iterator when the
* underlying data has been reordered
*/
- @Test(expected=ConcurrentModificationException.class)
+ @Test
public void sheetIterator_sheetRemoved() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
wb.createSheet("Sheet0");
@@ -99,7 +98,7 @@ public abstract class BaseTestWorkbook {
wb.removeSheetAt(1);
// Iterator order should be fixed when iterator is created
- it.next();
+ assertThrows(ConcurrentModificationException.class, it::next);
}
}
@@ -107,14 +106,14 @@ public abstract class BaseTestWorkbook {
* Expected UnsupportedOperationException:
* should not be able to remove sheets from the sheet iterator
*/
- @Test(expected=UnsupportedOperationException.class)
+ @Test
public void sheetIterator_remove() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
wb.createSheet("Sheet0");
Iterator<Sheet> it = wb.sheetIterator();
it.next(); //Sheet0
- it.remove();
+ assertThrows(UnsupportedOperationException.class, it::remove);
}
}
@@ -127,9 +126,9 @@ public abstract class BaseTestWorkbook {
//getting a sheet by invalid index or non-existing name
assertNull(wb.getSheet("Sheet1"));
IllegalArgumentException ex = assertThrows(
- "should have thrown exception due to invalid sheet index",
IllegalArgumentException.class,
- () -> wb.getSheetAt(0)
+ () -> wb.getSheetAt(0),
+ "should have thrown exception due to invalid sheet index"
);
// expected during successful test no negative index in the range message
assertFalse(ex.getMessage().contains("-1"));
@@ -145,16 +144,15 @@ public abstract class BaseTestWorkbook {
//fetching sheets by name is case-insensitive
Sheet originalSheet = wb.createSheet("Sheet3");
Sheet fetchedSheet = wb.getSheet("sheet3");
- if (fetchedSheet == null) {
- fail("Identified bug 44892");
- }
+ assertNotNull(fetchedSheet, "Identified bug 44892");
+
assertEquals("Sheet3", fetchedSheet.getSheetName());
assertEquals(3, wb.getNumberOfSheets());
assertSame(originalSheet, fetchedSheet);
ex = assertThrows(
- "should have thrown exception due to duplicate sheet name",
IllegalArgumentException.class,
- () -> wb.createSheet("sHeeT3")
+ () -> wb.createSheet("sHeeT3"),
+ "should have thrown exception due to duplicate sheet name"
);
// expected during successful test
assertEquals("The workbook already contains a sheet named 'sHeeT3'", ex.getMessage());
@@ -165,9 +163,9 @@ public abstract class BaseTestWorkbook {
"My:Sheet"};
for (String sheetName : invalidNames) {
assertThrows(
- "should have thrown exception due to invalid sheet name: " + sheetName,
IllegalArgumentException.class,
- () -> wb.createSheet(sheetName)
+ () -> wb.createSheet(sheetName),
+ "should have thrown exception due to invalid sheet name: " + sheetName
);
}
//still have 3 sheets
@@ -177,28 +175,12 @@ public abstract class BaseTestWorkbook {
wb.setSheetName(2, "I changed!");
//try to assign an invalid name to the 2nd sheet
- try {
- wb.setSheetName(1, "[I'm invalid]");
- fail("should have thrown exceptiuon due to invalid sheet name");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
+ assertThrows(IllegalArgumentException.class, () -> wb.setSheetName(1, "[I'm invalid]"));
//try to assign an invalid name to the 2nd sheet
- try {
- wb.createSheet(null);
- fail("should have thrown exceptiuon due to invalid sheet name");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
-
- try {
- wb.setSheetName(2, null);
+ assertThrows(IllegalArgumentException.class, () -> wb.createSheet(null));
- fail("should have thrown exceptiuon due to invalid sheet name");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
+ assertThrows(IllegalArgumentException.class, () -> wb.setSheetName(2, null));
//check
assertEquals(0, wb.getSheetIndex("sheet0"));
@@ -244,14 +226,9 @@ public abstract class BaseTestWorkbook {
String sheetName2 = "My very long sheet name which is longer than 31 chars " +
"and sheetName2.substring(0, 31) == sheetName1.substring(0, 31)";
- try {
- /*Sheet sh2 =*/
- wb1.createSheet(sheetName2);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- assertEquals("The workbook already contains a sheet named 'My very long sheet name which is longer than 31 chars and sheetName2.substring(0, 31) == sheetName1.substring(0, 31)'", e.getMessage());
- }
+
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> wb1.createSheet(sheetName2));
+ assertEquals("The workbook already contains a sheet named 'My very long sheet name which is longer than 31 chars and sheetName2.substring(0, 31) == sheetName1.substring(0, 31)'", e.getMessage());
String sheetName3 = "POI allows creating sheets with names longer than 31 characters";
String truncatedSheetName3 = sheetName3.substring(0, 31);
@@ -777,11 +754,9 @@ public abstract class BaseTestWorkbook {
for(int i = 0;i < wb.getNumberOfSheets();i++) {
sheetNames.append(wb.getSheetAt(i).getSheetName()).append(",");
}
- assertEquals("Had: " + sheetNames,
- sheets.length, wb.getNumberOfSheets());
+ assertEquals(sheets.length, wb.getNumberOfSheets(), "Had: " + sheetNames);
for(int i = 0;i < wb.getNumberOfSheets();i++) {
- assertEquals("Had: " + sheetNames,
- sheets[i], wb.getSheetAt(i).getSheetName());
+ assertEquals(sheets[i], wb.getSheetAt(i).getSheetName(), "Had: " + sheetNames);
}
}
@@ -823,8 +798,7 @@ public abstract class BaseTestWorkbook {
final byte[] before = HSSFTestDataSamples.getTestDataFileContent(filename);
wb.close();
final byte[] after = HSSFTestDataSamples.getTestDataFileContent(filename);
- assertArrayEquals(filename + " sample file was modified as a result of closing the workbook",
- before, after);
+ assertArrayEquals(before, after, filename + " sample file was modified as a result of closing the workbook");
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestXEvaluationSheet.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestXEvaluationSheet.java
index f21842b4ec..5a5c8ec04f 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestXEvaluationSheet.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestXEvaluationSheet.java
@@ -17,12 +17,12 @@
package org.apache.poi.ss.usermodel;
-import org.apache.poi.ss.formula.EvaluationSheet;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
+import org.apache.poi.ss.formula.EvaluationSheet;
+import org.junit.jupiter.api.Test;
public abstract class BaseTestXEvaluationSheet {
/**
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
index 77f1ca3d3b..57887aee8e 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
@@ -16,19 +16,22 @@
2012 - Alfresco Software, Ltd.
Alfresco Software has modified source of this file
- The details of changes as svn diff can be found in svn at location root/projects/3rd-party/src
+ The details of changes as svn diff can be found in svn at location root/projects/3rd-party/src
==================================================================== */
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.text.DateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@@ -41,9 +44,9 @@ import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.NumberToTextConverter;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.SuppressForbidden;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* Tests of {@link DataFormatter}
@@ -54,7 +57,7 @@ import org.junit.Test;
public class TestDataFormatter {
private static final double _15_MINUTES = 0.041666667;
- @BeforeClass
+ @BeforeAll
@SuppressForbidden
public static void setUpClass() {
// some pre-checks to hunt for a problem in the Maven build
@@ -74,8 +77,8 @@ public class TestDataFormatter {
CellFormat cfmt = CellFormat.getInstance("_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-");
CellFormatResult result = cfmt.apply(cellValueO);
- assertEquals("This failure can indicate that the wrong locale is used during test-execution, ensure you run with english/US via -Duser.language=en -Duser.country=US",
- " 1,234.56 ", result.text);
+ assertEquals(" 1,234.56 ", result.text,
+ "This failure can indicate that the wrong locale is used during test-execution, ensure you run with english/US via -Duser.language=en -Duser.country=US");
}
/**
@@ -109,7 +112,7 @@ public class TestDataFormatter {
// Regular numeric style formats
assertEquals("63", dfUS.formatRawCellContents(63.0, -1, "[$-1010409]##"));
- assertEquals("63", dfUS.formatRawCellContents(63.0, -1, "[$-1010409]00"));
+ assertEquals("63", dfUS.formatRawCellContents(63.0, -1, "[$-1010409]00"));
}
@@ -148,14 +151,14 @@ public class TestDataFormatter {
};
for (String format : formats) {
assertEquals(
- "Wrong format for: " + format,
"12.34",
- dfUS.formatRawCellContents(12.343, -1, format)
+ dfUS.formatRawCellContents(12.343, -1, format),
+ "Wrong format for: " + format
);
assertEquals(
- "Wrong format for: " + format,
"-12.34",
- dfUS.formatRawCellContents(-12.343, -1, format)
+ dfUS.formatRawCellContents(-12.343, -1, format),
+ "Wrong format for: " + format
);
}
@@ -172,14 +175,14 @@ public class TestDataFormatter {
String[] formats = { "#,##0.00;[Blue](#,##0.00)" };
for (String format : formats) {
assertEquals(
- "Wrong format for: " + format,
"12.34",
- dfUS.formatRawCellContents(12.343, -1, format)
+ dfUS.formatRawCellContents(12.343, -1, format),
+ "Wrong format for: " + format
);
assertEquals(
- "Wrong format for: " + format,
"(12.34)",
- dfUS.formatRawCellContents(-12.343, -1, format)
+ dfUS.formatRawCellContents(-12.343, -1, format),
+ "Wrong format for: " + format
);
}
@@ -187,14 +190,14 @@ public class TestDataFormatter {
formats = new String[] { "$#,##0.00;[Red]($#,##0.00)" };
for (String format : formats) {
assertEquals(
- "Wrong format for: " + format,
"$12.34",
- dfUS.formatRawCellContents(12.343, -1, format)
+ dfUS.formatRawCellContents(12.343, -1, format),
+ "Wrong format for: " + format
);
assertEquals(
- "Wrong format for: " + format,
"($12.34)",
- dfUS.formatRawCellContents(-12.343, -1, format)
+ dfUS.formatRawCellContents(-12.343, -1, format),
+ "Wrong format for: " + format
);
}
}
@@ -204,8 +207,8 @@ public class TestDataFormatter {
DataFormatter dfUS = new DataFormatter(Locale.US);
String format = "[>=10]#,##0;[<10]0.0";
- assertEquals("Wrong format for " + format, "17,876", dfUS.formatRawCellContents(17876.000, -1, format));
- assertEquals("Wrong format for " + format, "9.7", dfUS.formatRawCellContents(9.71, -1, format));
+ assertEquals("17,876", dfUS.formatRawCellContents(17876.000, -1, format), "Wrong format for " + format);
+ assertEquals("9.7", dfUS.formatRawCellContents(9.71, -1, format), "Wrong format for " + format);
}
/**
@@ -646,7 +649,7 @@ public class TestDataFormatter {
* TODO Fix these so that they work
*/
@Test
- @Ignore
+ @Disabled
public void testCustomFormats() {
DataFormatter dfUS = new DataFormatter(Locale.US, true);
String fmt;
@@ -700,7 +703,7 @@ public class TestDataFormatter {
String format = "[h]\"\"h\"\" m\"\"m\"\"";
assertTrue(DateUtil.isADateFormat(-1,format));
assertTrue(DateUtil.isValidExcelDate(_15_MINUTES));
-
+
assertEquals("1h 0m", formatter.formatRawCellContents(_15_MINUTES, -1, format, false));
assertEquals("0.041666667", formatter.formatRawCellContents(_15_MINUTES, -1, "[h]'h'", false));
assertEquals("1h 0m\"", formatter.formatRawCellContents(_15_MINUTES, -1, "[h]\"\"h\"\" m\"\"m\"\"\"", false));
@@ -710,15 +713,13 @@ public class TestDataFormatter {
assertEquals(" 60", formatter.formatRawCellContents(_15_MINUTES, -1, " [m]", false));
assertEquals("h60", formatter.formatRawCellContents(_15_MINUTES, -1, "\"\"h\"\"[m]", false));
assertEquals("m1", formatter.formatRawCellContents(_15_MINUTES, -1, "\"\"m\"\"h", false));
-
- try {
- assertEquals("1h 0m\"", formatter.formatRawCellContents(_15_MINUTES, -1, "[h]\"\"h\"\" m\"\"m\"\"\"\"", false));
- fail("Catches exception because of invalid format, i.e. trailing quoting");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().contains("Cannot format given Object as a Number"));
- }
+
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () ->
+ formatter.formatRawCellContents(_15_MINUTES, -1, "[h]\"\"h\"\" m\"\"m\"\"\"\"", false),
+ "Catches exception because of invalid format, i.e. trailing quoting");
+ assertTrue(e.getMessage().contains("Cannot format given Object as a Number"));
}
-
+
@Test
public void testIsADateFormat() {
// first check some cases that should not be a date, also call multiple times to ensure the cache is used
@@ -926,7 +927,7 @@ public class TestDataFormatter {
String value = df.formatCellValue(cell, wb.getCreationHelper().createFormulaEvaluator());
assertEquals("-130", value);
}
-
+
/**
* Bug #63292
*/
@@ -965,7 +966,7 @@ public class TestDataFormatter {
doFormatTestSequential(formatter1);
doFormatTestConcurrent(formatter1, formatter2);
}
-
+
/**
* Bug #64319
*
@@ -976,24 +977,24 @@ public class TestDataFormatter {
@Test
public void testWithEinFormat() throws Exception {
DataFormatter formatter = new DataFormatter();
-
+
// Format string literals with an E in them shouldn't be
// treated as a Scientific format, so shouldn't become E+
- assertEquals("TRUE", formatter.formatRawCellContents(1.0, 170,
+ assertEquals("TRUE", formatter.formatRawCellContents(1.0, 170,
"\"TRUE\";\"FALSE\";\"ZERO\""));
- assertEquals("ZERO", formatter.formatRawCellContents(0.0, 170,
+ assertEquals("ZERO", formatter.formatRawCellContents(0.0, 170,
"\"TRUE\";\"FALSE\";\"ZERO\""));
- assertEquals("FALSE", formatter.formatRawCellContents(-1.0, 170,
+ assertEquals("FALSE", formatter.formatRawCellContents(-1.0, 170,
"\"TRUE\";\"FALSE\";\"ZERO\""));
// Explicit Scientific format does need E+
- assertEquals("1E+05", formatter.formatRawCellContents(1e05, 170,
+ assertEquals("1E+05", formatter.formatRawCellContents(1e05, 170,
"0E+00"));
- assertEquals("1E+10", formatter.formatRawCellContents(1e10, 170,
+ assertEquals("1E+10", formatter.formatRawCellContents(1e10, 170,
"0E+00"));
- assertEquals("1E-10", formatter.formatRawCellContents(1e-10, 170,
+ assertEquals("1E-10", formatter.formatRawCellContents(1e-10, 170,
"0E+00"));
-
+
// Large numbers with "General" need E+
assertEquals("100000", formatter.formatRawCellContents(1e05, -1, "General"));
assertEquals("1E+12", formatter.formatRawCellContents(1e12, -1, "General"));
@@ -1001,20 +1002,20 @@ public class TestDataFormatter {
// Less common Scientific-like formats which don't ask for
// the + on >1 exponentials don't need it adding
// (Java will put the -ve ones in for E-## automatically)
- assertEquals("1E5", formatter.formatRawCellContents(1e05, 170,
+ assertEquals("1E5", formatter.formatRawCellContents(1e05, 170,
"0E0"));
- assertEquals("1E10", formatter.formatRawCellContents(1e10, 170,
+ assertEquals("1E10", formatter.formatRawCellContents(1e10, 170,
"0E0"));
- assertEquals("1E-10", formatter.formatRawCellContents(1e-10, 170,
+ assertEquals("1E-10", formatter.formatRawCellContents(1e-10, 170,
"0E0"));
- assertEquals("1E5", formatter.formatRawCellContents(1e05, 170,
+ assertEquals("1E5", formatter.formatRawCellContents(1e05, 170,
"0E-0"));
- assertEquals("1E10", formatter.formatRawCellContents(1e10, 170,
+ assertEquals("1E10", formatter.formatRawCellContents(1e10, 170,
"0E-0"));
- assertEquals("1E-10", formatter.formatRawCellContents(1e-10, 170,
+ assertEquals("1E-10", formatter.formatRawCellContents(1e-10, 170,
"0E-0"));
-
+
}
private void doFormatTestSequential(DataFormatter formatter) {
@@ -1052,7 +1053,7 @@ public class TestDataFormatter {
int formatIndex = 105;
String formatString = "[$-F400]m/d/yy h:mm:ss\\ AM/PM;[$-F400]m/d/yy h:mm:ss\\ AM/PM;_-* \"\"??_-;_-@_-";
String actual = formatter.formatRawCellContents(n, formatIndex, formatString);
- assertEquals("Failed on iteration " + iteration, expected, actual);
+ assertEquals(expected, actual, "Failed on iteration " + iteration);
return true;
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDateUtil.java b/src/testcases/org/apache/poi/ss/usermodel/TestDateUtil.java
index dc5c3f5b24..550815d089 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestDateUtil.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestDateUtil.java
@@ -24,12 +24,12 @@ import static java.util.Calendar.JULY;
import static java.util.Calendar.MARCH;
import static java.util.Calendar.MAY;
import static java.util.Calendar.OCTOBER;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.text.ParseException;
@@ -45,21 +45,21 @@ import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.LocaleUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
public class TestDateUtil {
static TimeZone userTimeZone;
- @BeforeClass
+ @BeforeAll
public static void setCEST() {
userTimeZone = LocaleUtil.getUserTimeZone();
LocaleUtil.setUserTimeZone(TimeZone.getTimeZone("CEST"));
}
- @AfterClass
+ @AfterAll
public static void resetTimeZone() {
LocaleUtil.setUserTimeZone(userTimeZone);
}
@@ -194,12 +194,12 @@ public class TestDateUtil {
for (int hour = 0; hour < 24; hour++) {
double excelDate = DateUtil.getExcelDate(cal.getTime(), false);
- assertEquals("getJavaDate: Checking hour = " + hour, cal.getTime().getTime(),
- DateUtil.getJavaDate(excelDate, false).getTime());
+ assertEquals(cal.getTime().getTime(), DateUtil.getJavaDate(excelDate, false).getTime(),
+ "getJavaDate: Checking hour = " + hour);
LocalDateTime ldt = LocalDateTime.ofInstant(cal.toInstant(), cal.getTimeZone().toZoneId());
- assertEquals("getLocalDateTime: Checking hour = " + hour, ldt,
- DateUtil.getLocalDateTime(excelDate, false));
+ assertEquals(ldt, DateUtil.getLocalDateTime(excelDate, false),
+ "getLocalDateTime: Checking hour = " + hour);
cal.add(Calendar.HOUR_OF_DAY, 1);
}
@@ -214,21 +214,17 @@ public class TestDateUtil {
cal.add(Calendar.DATE,1); // now Jan. 2, 2004
Date dateIf1904 = cal.getTime();
// 1900 windowing
- assertEquals("Checking 1900 Date Windowing",
- dateIf1900.getTime(),
- DateUtil.getJavaDate(excelDate,false).getTime());
+ assertEquals(dateIf1900.getTime(), DateUtil.getJavaDate(excelDate,false).getTime(),
+ "Checking 1900 Date Windowing");
// 1904 windowing
- assertEquals("Checking 1904 Date Windowing",
- dateIf1904.getTime(),
- DateUtil.getJavaDate(excelDate,true).getTime());
+ assertEquals(dateIf1904.getTime(), DateUtil.getJavaDate(excelDate,true).getTime(),
+ "Checking 1904 Date Windowing");
// 1900 windowing (LocalDateTime)
- assertEquals("Checking 1900 Date Windowing",
- LocalDateTime.of(2000,1,1,0,0),
- DateUtil.getLocalDateTime(excelDate,false));
+ assertEquals(LocalDateTime.of(2000,1,1,0,0), DateUtil.getLocalDateTime(excelDate,false),
+ "Checking 1900 Date Windowing");
// 1904 windowing (LocalDateTime)
- assertEquals("Checking 1904 Date Windowing",
- LocalDateTime.of(2004,1,2,0,0),
- DateUtil.getLocalDateTime(excelDate,true));
+ assertEquals(LocalDateTime.of(2004,1,2,0,0), DateUtil.getLocalDateTime(excelDate,true),
+ "Checking 1904 Date Windowing");
}
/**
@@ -252,12 +248,9 @@ public class TestDateUtil {
double difference = excelDate - Math.floor(excelDate);
int differenceInHours = (int) (difference * 24 * 60 + 0.5) / 60;
- assertEquals("Checking " + hour + " hour on Daylight Saving Time start date",
- hour,
- differenceInHours);
- assertEquals("Checking " + hour + " hour on Daylight Saving Time start date",
- javaDate.getTime(),
- DateUtil.getJavaDate(excelDate, false).getTime());
+ assertEquals(hour, differenceInHours, "Checking " + hour + " hour on Daylight Saving Time start date");
+ assertEquals(javaDate.getTime(), DateUtil.getJavaDate(excelDate, false).getTime(),
+ "Checking " + hour + " hour on Daylight Saving Time start date");
// perform the same checks with LocalDateTime
LocalDateTime localDate = LocalDateTime.of(2004,3,28,hour,0,0);
@@ -265,12 +258,10 @@ public class TestDateUtil {
double differenceLocalDate = excelLocalDate - Math.floor(excelLocalDate);
int differenceLocalDateInHours = (int) (differenceLocalDate * 24 * 60 + 0.5) / 60;
- assertEquals("Checking " + hour + " hour on Daylight Saving Time start date (LocalDateTime)",
- hour,
- differenceLocalDateInHours);
- assertEquals("Checking " + hour + " hour on Daylight Saving Time start date (LocalDateTime)",
- localDate,
- DateUtil.getLocalDateTime(excelLocalDate, false));
+ assertEquals(hour, differenceLocalDateInHours,
+ "Checking " + hour + " hour on Daylight Saving Time start date (LocalDateTime)");
+ assertEquals(localDate, DateUtil.getLocalDateTime(excelLocalDate, false),
+ "Checking " + hour + " hour on Daylight Saving Time start date (LocalDateTime)");
}
}
@@ -295,15 +286,15 @@ public class TestDateUtil {
cal.set(Calendar.HOUR_OF_DAY, hour);
Date javaDate = DateUtil.getJavaDate(excelDate, false);
double actDate = DateUtil.getExcelDate(javaDate, false);
- assertEquals("Checking " + hour + " hours on Daylight Saving Time start date",
- excelDate, actDate, oneMinute);
+ assertEquals(excelDate, actDate, oneMinute,
+ "Checking " + hour + " hours on Daylight Saving Time start date");
// perform the same check with LocalDateTime
cal.set(Calendar.HOUR_OF_DAY, hour);
LocalDateTime localDate = DateUtil.getLocalDateTime(excelDate, false);
double actLocalDate = DateUtil.getExcelDate(localDate, false);
- assertEquals("Checking " + hour + " hours on Daylight Saving Time start date (LocalDateTime)",
- excelDate, actLocalDate, oneMinute);
+ assertEquals(excelDate, actLocalDate, oneMinute,
+ "Checking " + hour + " hours on Daylight Saving Time start date (LocalDateTime)");
}
}
@@ -320,23 +311,19 @@ public class TestDateUtil {
double excelDate = DateUtil.getExcelDate(javaDate, false);
double difference = excelDate - Math.floor(excelDate);
int differenceInHours = (int) (difference * 24 * 60 + 0.5) / 60;
- assertEquals("Checking " + hour + " hour on Daylight Saving Time end date",
- hour,
- differenceInHours);
- assertEquals("Checking " + hour + " hour on Daylight Saving Time start date",
- javaDate.getTime(),
- DateUtil.getJavaDate(excelDate, false).getTime());
+ assertEquals(hour, differenceInHours,
+ "Checking " + hour + " hour on Daylight Saving Time end date");
+ assertEquals(javaDate.getTime(), DateUtil.getJavaDate(excelDate, false).getTime(),
+ "Checking " + hour + " hour on Daylight Saving Time start date");
// perform the same checks using LocalDateTime
LocalDateTime localDate = LocalDateTime.of(2004,10,31,hour,0,0);
double excelLocalDate = DateUtil.getExcelDate(localDate, false);
int differenceLocalDateInHours = (int) (difference * 24 * 60 + 0.5) / 60;
- assertEquals("Checking " + hour + " hour on Daylight Saving Time end date (LocalDateTime)",
- hour,
- differenceLocalDateInHours);
- assertEquals("Checking " + hour + " hour on Daylight Saving Time start date (LocalDateTime)",
- localDate,
- DateUtil.getLocalDateTime(excelLocalDate, false));
+ assertEquals(hour, differenceLocalDateInHours,
+ "Checking " + hour + " hour on Daylight Saving Time end date (LocalDateTime)");
+ assertEquals(localDate, DateUtil.getLocalDateTime(excelLocalDate, false),
+ "Checking " + hour + " hour on Daylight Saving Time start date (LocalDateTime)");
}
}
@@ -353,15 +340,13 @@ public class TestDateUtil {
for (int hour = 0; hour < 24; hour++, excelDate += oneHour) {
cal.set(Calendar.HOUR_OF_DAY, hour);
Date javaDate = DateUtil.getJavaDate(excelDate, false);
- assertEquals("Checking " + hour + " hours on Daylight Saving Time start date",
- excelDate,
- DateUtil.getExcelDate(javaDate, false), oneMinute);
+ assertEquals(excelDate, DateUtil.getExcelDate(javaDate, false), oneMinute,
+ "Checking " + hour + " hours on Daylight Saving Time start date");
// perform the same checks using LocalDateTime
LocalDateTime localDate = DateUtil.getLocalDateTime(excelDate, false);
- assertEquals("Checking " + hour + " hours on Daylight Saving Time start date",
- excelDate,
- DateUtil.getExcelDate(localDate, false), oneMinute);
+ assertEquals(excelDate, DateUtil.getExcelDate(localDate, false), oneMinute,
+ "Checking " + hour + " hours on Daylight Saving Time start date");
}
}
@@ -386,7 +371,7 @@ public class TestDateUtil {
Date javaDate = DateUtil.getJavaDate(excelDate);
// Should match despite time-zone
- assertEquals("Checking timezone " + id, expected.getTime(), javaDate.getTime());
+ assertEquals(expected.getTime(), javaDate.getTime(), "Checking timezone " + id);
}
// Check that the timezone aware getter works correctly
@@ -398,8 +383,8 @@ public class TestDateUtil {
// Same, no change
assertEquals(
- DateUtil.getJavaDate(excelDate, false).getTime(),
- DateUtil.getJavaDate(excelDate, false, cet).getTime()
+ DateUtil.getJavaDate(excelDate, false).getTime(),
+ DateUtil.getJavaDate(excelDate, false, cet).getTime()
);
// London vs Copenhagen, should differ by an hour
@@ -464,10 +449,7 @@ public class TestDateUtil {
"[yeLLow]yyyy-mm-dd"
};
for (String format : formats) {
- assertTrue(
- format + " is a date format",
- DateUtil.isADateFormat(formatId, format)
- );
+ assertTrue(DateUtil.isADateFormat(formatId, format), format + " is a date format");
}
// Then time based ones too
@@ -482,10 +464,7 @@ public class TestDateUtil {
"[hh]", "[mm]", "[ss]", "[SS]", "[red][hh]"
};
for (String format : formats) {
- assertTrue(
- format + " is a datetime format",
- DateUtil.isADateFormat(formatId, format)
- );
+ assertTrue(DateUtil.isADateFormat(formatId, format), format + " is a datetime format");
}
// Then invalid ones
@@ -498,10 +477,7 @@ public class TestDateUtil {
"", null
};
for (String format : formats) {
- assertFalse(
- format + " is not a date or datetime format",
- DateUtil.isADateFormat(formatId, format)
- );
+ assertFalse(DateUtil.isADateFormat(formatId, format), format + " is not a date or datetime format");
}
// And these are ones we probably shouldn't allow,
@@ -624,47 +600,26 @@ public class TestDateUtil {
public void absoluteDay() {
// 1 Jan 1900 is 1 day after 31 Dec 1899
Calendar cal = LocaleUtil.getLocaleCalendar(1900,JANUARY,1,0,0,0);
- assertEquals("Checking absolute day (1 Jan 1900)", 1, DateUtil.absoluteDay(cal, false));
+ assertEquals(1, DateUtil.absoluteDay(cal, false), "Checking absolute day (1 Jan 1900)");
LocalDateTime ldt = LocalDateTime.of(1900,1,1,0,0,0);
- assertEquals("Checking absolute day (1 Jan 1900) (LocalDateTime)", 1, DateUtil.absoluteDay(ldt, false));
+ assertEquals(1, DateUtil.absoluteDay(ldt, false), "Checking absolute day (1 Jan 1900) (LocalDateTime)");
// 1 Jan 1901 is 366 days after 31 Dec 1899
ldt = LocalDateTime.of(1901,1,1,0,0,0);
cal.set(1901,JANUARY,1,0,0,0);
- assertEquals("Checking absolute day (1 Jan 1901) (LocalDateTime)", 366, DateUtil.absoluteDay(ldt, false));
+ assertEquals(366, DateUtil.absoluteDay(ldt, false), "Checking absolute day (1 Jan 1901) (LocalDateTime)");
}
@Test
public void absoluteDayYearTooLow() {
Calendar cal = LocaleUtil.getLocaleCalendar(1899,JANUARY,1,0,0,0);
- try {
- DateUtil.absoluteDay(cal, false);
- fail("Should fail here");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> DateUtil.absoluteDay(cal, false));
- try {
- cal.set(1903,JANUARY,1,0,0,0);
- DateUtil.absoluteDay(cal, true);
- fail("Should fail here");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ cal.set(1903,JANUARY,1,0,0,0);
+ assertThrows(IllegalArgumentException.class, () -> DateUtil.absoluteDay(cal, true));
// same for LocalDateTime
- try {
- DateUtil.absoluteDay(LocalDateTime.of(1899,1,1,0,0,0), false);
- fail("Should fail here");
- } catch (IllegalArgumentException e) {
- // expected here
- }
-
- try {
- DateUtil.absoluteDay(LocalDateTime.of(1903,1,1,0,0,0), true);
- fail("Should fail here");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> DateUtil.absoluteDay(LocalDateTime.of(1899,1,1,0,0,0), false));
+ assertThrows(IllegalArgumentException.class, () -> DateUtil.absoluteDay(LocalDateTime.of(1903,1,1,0,0,0), true));
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java
index 742fb2228f..47f47d3245 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss.usermodel;
-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.text.DateFormatSymbols;
import java.text.FieldPosition;
@@ -34,7 +34,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestExcelStyleDateFormatter {
private static final String EXCEL_DATE_FORMAT = "MMMMM";
@@ -77,9 +77,9 @@ public class TestExcelStyleDateFormatter {
int actIdx = localeIndex(locale);
- assertNotNull(msg, result);
- assertTrue(msg, result.length() > actIdx);
- assertEquals(msg, expected.charAt(month), result.charAt(actIdx));
+ assertNotNull(result, msg);
+ assertTrue(result.length() > actIdx, msg);
+ assertEquals(expected.charAt(month), result.charAt(actIdx), msg);
month++;
}
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java b/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
index ec8359a46d..0ae728d52c 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
@@ -17,7 +17,8 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.BufferedReader;
import java.io.File;
@@ -27,8 +28,8 @@ import java.io.InputStreamReader;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* Tests for the Fraction Formatting part of DataFormatter.
@@ -43,15 +44,12 @@ public final class TestFractionFormat {
assertEquals("26027/81", ret);
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void testInvalid() {
- FractionFormat f = new FractionFormat("", "9999999999999999999999999999");
- double val = 321.321;
- String ret = f.format(val);
- assertEquals("26027/81", ret);
+ assertThrows(IllegalStateException.class, () -> new FractionFormat("", "9999999999999999999999999999"));
}
- @Ignore("Runs for some longer time")
+ @Disabled("Runs for some longer time")
@Test
public void microBenchmark() {
FractionFormat f = new FractionFormat("", "##");
@@ -105,7 +103,7 @@ public final class TestFractionFormat {
String truth = clean(truths[j]);
String testKey = truths[0] + ":" + truths[1] + ":" + headers[j];
- assertEquals(testKey, truth, formatted);
+ assertEquals(truth, formatted, testKey);
}
truthLine = reader.readLine();
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestIndexedColors.java b/src/testcases/org/apache/poi/ss/usermodel/TestIndexedColors.java
index 093410b746..e6209f3352 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestIndexedColors.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestIndexedColors.java
@@ -17,10 +17,10 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* @author Yegor Kozlov
@@ -31,24 +31,18 @@ public final class TestIndexedColors {
public void fromInt() {
int[] illegalIndices = { -1, 65 };
for (int index : illegalIndices) {
- try {
- IndexedColors.fromInt(index);
- fail("Expected IllegalArgumentException: " + index);
- }
- catch (final IllegalArgumentException e) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> IndexedColors.fromInt(index));
}
assertEquals(IndexedColors.BLACK, IndexedColors.fromInt(8));
assertEquals(IndexedColors.GOLD, IndexedColors.fromInt(51));
assertEquals(IndexedColors.AUTOMATIC, IndexedColors.fromInt(64));
}
-
+
@Test
public void getIndex() {
assertEquals(51, IndexedColors.GOLD.getIndex());
}
-
+
@Test
public void index() {
assertEquals(51, IndexedColors.GOLD.index);
diff --git a/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java b/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java
deleted file mode 100644
index 569fadce71..0000000000
--- a/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.util;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-/**
- * Test suite for <tt>org.apache.poi.ss.util</tt>
- *
- * @author Josh Micich
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestAreaReference.class,
- //TestCellRangeAddress.class, //converted to junit4
- //TestCellReference.class, //converted to junit4
- TestDateFormatConverter.class,
- TestExpandedDouble.class,
- TestNumberComparer.class,
- TestNumberToTextConverter.class,
- TestSheetBuilder.class,
- TestSheetUtil.class,
- TestWorkbookUtil.class
-})
-public class AllSSUtilTests {
-}
diff --git a/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java b/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java
index d06bea9b3e..ce3fbeef15 100644
--- a/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java
+++ b/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java
@@ -5,9 +5,9 @@
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,11 +17,12 @@
package org.apache.poi.ss.util;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.HashMap;
@@ -39,7 +40,7 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests Spreadsheet CellUtil
@@ -52,30 +53,29 @@ public abstract class BaseTestCellUtil {
protected BaseTestCellUtil(ITestDataProvider testDataProvider) {
_testDataProvider = testDataProvider;
}
-
+
@Test
public void setCellStyleProperty() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet s = wb.createSheet();
- Row r = s.createRow(0);
- Cell c = r.createCell(0);
-
- // Add a border should create a new style
- int styCnt1 = wb.getNumCellStyles();
- CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, BorderStyle.THIN);
- int styCnt2 = wb.getNumCellStyles();
- assertEquals(styCnt1+1, styCnt2);
-
- // Add same border to another cell, should not create another style
- c = r.createCell(1);
- CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, BorderStyle.THIN);
- int styCnt3 = wb.getNumCellStyles();
- assertEquals(styCnt2, styCnt3);
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0);
- wb.close();
+ // Add a border should create a new style
+ int styCnt1 = wb.getNumCellStyles();
+ CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, BorderStyle.THIN);
+ int styCnt2 = wb.getNumCellStyles();
+ assertEquals(styCnt1 + 1, styCnt2);
+
+ // Add same border to another cell, should not create another style
+ c = r.createCell(1);
+ CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, BorderStyle.THIN);
+ int styCnt3 = wb.getNumCellStyles();
+ assertEquals(styCnt2, styCnt3);
+ }
}
-
- @Test(expected=RuntimeException.class)
+
+ @Test
public void setCellStylePropertyWithInvalidValue() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
Sheet s = wb.createSheet();
@@ -83,127 +83,120 @@ public abstract class BaseTestCellUtil {
Cell c = r.createCell(0);
// An invalid BorderStyle constant
- CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, 42);
+ assertThrows(RuntimeException.class, () -> CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, 42));
}
}
-
+
@Test()
public void setCellStylePropertyBorderWithShortAndEnum() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet s = wb.createSheet();
- Row r = s.createRow(0);
- Cell c = r.createCell(0);
-
- // A valid BorderStyle constant, as a Short
- CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, BorderStyle.DASH_DOT.getCode());
- assertEquals(BorderStyle.DASH_DOT, c.getCellStyle().getBorderBottom());
-
- // A valid BorderStyle constant, as an Enum
- CellUtil.setCellStyleProperty(c, CellUtil.BORDER_TOP, BorderStyle.MEDIUM_DASH_DOT);
- assertEquals(BorderStyle.MEDIUM_DASH_DOT, c.getCellStyle().getBorderTop());
-
- wb.close();
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0);
+
+ // A valid BorderStyle constant, as a Short
+ CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, BorderStyle.DASH_DOT.getCode());
+ assertEquals(BorderStyle.DASH_DOT, c.getCellStyle().getBorderBottom());
+
+ // A valid BorderStyle constant, as an Enum
+ CellUtil.setCellStyleProperty(c, CellUtil.BORDER_TOP, BorderStyle.MEDIUM_DASH_DOT);
+ assertEquals(BorderStyle.MEDIUM_DASH_DOT, c.getCellStyle().getBorderTop());
+ }
}
@Test
public void setCellStyleProperties() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet s = wb.createSheet();
- Row r = s.createRow(0);
- Cell c = r.createCell(0);
-
- // Add multiple border properties to cell should create a single new style
- int styCnt1 = wb.getNumCellStyles();
- Map<String, Object> props = new HashMap<>();
- props.put(CellUtil.BORDER_TOP, BorderStyle.THIN);
- props.put(CellUtil.BORDER_BOTTOM, BorderStyle.THIN);
- props.put(CellUtil.BORDER_LEFT, BorderStyle.THIN);
- props.put(CellUtil.BORDER_RIGHT, BorderStyle.THIN);
- props.put(CellUtil.ALIGNMENT, HorizontalAlignment.CENTER.getCode()); // try it both with a Short (deprecated)
- props.put(CellUtil.VERTICAL_ALIGNMENT, VerticalAlignment.CENTER); // and with an enum
- CellUtil.setCellStyleProperties(c, props);
- int styCnt2 = wb.getNumCellStyles();
- assertEquals("Only one additional style should have been created", styCnt1 + 1, styCnt2);
-
- // Add same border another to same cell, should not create another style
- c = r.createCell(1);
- CellUtil.setCellStyleProperties(c, props);
- int styCnt3 = wb.getNumCellStyles();
- assertEquals("No additional styles should have been created", styCnt2, styCnt3);
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0);
- wb.close();
-
+ // Add multiple border properties to cell should create a single new style
+ int styCnt1 = wb.getNumCellStyles();
+ Map<String, Object> props = new HashMap<>();
+ props.put(CellUtil.BORDER_TOP, BorderStyle.THIN);
+ props.put(CellUtil.BORDER_BOTTOM, BorderStyle.THIN);
+ props.put(CellUtil.BORDER_LEFT, BorderStyle.THIN);
+ props.put(CellUtil.BORDER_RIGHT, BorderStyle.THIN);
+ props.put(CellUtil.ALIGNMENT, HorizontalAlignment.CENTER.getCode()); // try it both with a Short (deprecated)
+ props.put(CellUtil.VERTICAL_ALIGNMENT, VerticalAlignment.CENTER); // and with an enum
+ CellUtil.setCellStyleProperties(c, props);
+ int styCnt2 = wb.getNumCellStyles();
+ assertEquals(styCnt1 + 1, styCnt2, "Only one additional style should have been created");
+
+ // Add same border another to same cell, should not create another style
+ c = r.createCell(1);
+ CellUtil.setCellStyleProperties(c, props);
+ int styCnt3 = wb.getNumCellStyles();
+ assertEquals(styCnt2, styCnt3, "No additional styles should have been created");
+ }
}
@Test
public void getRow() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet sh = wb.createSheet();
- Row row1 = sh.createRow(0);
-
- // Get row that already exists
- Row r1 = CellUtil.getRow(0, sh);
- assertNotNull(r1);
- assertSame("An existing row should not be recreated", row1, r1);
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet sh = wb.createSheet();
+ Row row1 = sh.createRow(0);
- // Get row that does not exist yet
- assertNotNull(CellUtil.getRow(1, sh));
+ // Get row that already exists
+ Row r1 = CellUtil.getRow(0, sh);
+ assertNotNull(r1);
+ assertSame(row1, r1, "An existing row should not be recreated");
- wb.close();
+ // Get row that does not exist yet
+ assertNotNull(CellUtil.getRow(1, sh));
+ }
}
@Test
public void getCell() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet sh = wb.createSheet();
- Row row = sh.createRow(0);
- Cell A1 = row.createCell(0);
-
- // Get cell that already exists
- Cell a1 = CellUtil.getCell(row, 0);
- assertNotNull(a1);
- assertSame("An existing cell should not be recreated", A1, a1);
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet sh = wb.createSheet();
+ Row row = sh.createRow(0);
+ Cell A1 = row.createCell(0);
- // Get cell that does not exist yet
- assertNotNull(CellUtil.getCell(row, 1));
+ // Get cell that already exists
+ Cell a1 = CellUtil.getCell(row, 0);
+ assertNotNull(a1);
+ assertSame(A1, a1, "An existing cell should not be recreated");
- wb.close();
+ // Get cell that does not exist yet
+ assertNotNull(CellUtil.getCell(row, 1));
+ }
}
@Test
public void createCell() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet sh = wb.createSheet();
- Row row = sh.createRow(0);
-
- CellStyle style = wb.createCellStyle();
- style.setWrapText(true);
-
- // calling createCell on a non-existing cell should create a cell and set the cell value and style.
- Cell F1 = CellUtil.createCell(row, 5, "Cell Value", style);
-
- assertSame(row.getCell(5), F1);
- assertEquals("Cell Value", F1.getStringCellValue());
- assertEquals(style, F1.getCellStyle());
- // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call.
- // HSSFCellStyle wraps an underlying style record, and the underlying
- // style record is the same between multiple getCellStyle() calls.
-
- // calling createCell on an existing cell should return the existing cell and modify the cell value and style.
- Cell f1 = CellUtil.createCell(row, 5, "Overwritten cell value", null);
- assertSame(row.getCell(5), f1);
- assertSame(F1, f1);
- assertEquals("Overwritten cell value", f1.getStringCellValue());
- assertEquals("Overwritten cell value", F1.getStringCellValue());
- assertEquals("cell style should be unchanged with createCell(..., null)", style, f1.getCellStyle());
- assertEquals("cell style should be unchanged with createCell(..., null)", style, F1.getCellStyle());
-
- // test createCell(row, column, value) (no CellStyle)
- f1 = CellUtil.createCell(row, 5, "Overwritten cell with default style");
- assertSame(F1, f1);
-
- wb.close();
-
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet sh = wb.createSheet();
+ Row row = sh.createRow(0);
+
+ CellStyle style = wb.createCellStyle();
+ style.setWrapText(true);
+
+ // calling createCell on a non-existing cell should create a cell and set the cell value and style.
+ Cell F1 = CellUtil.createCell(row, 5, "Cell Value", style);
+
+ assertSame(row.getCell(5), F1);
+ assertEquals("Cell Value", F1.getStringCellValue());
+ assertEquals(style, F1.getCellStyle());
+ // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call.
+ // HSSFCellStyle wraps an underlying style record, and the underlying
+ // style record is the same between multiple getCellStyle() calls.
+
+ // calling createCell on an existing cell should return the existing cell and modify the cell value and style.
+ Cell f1 = CellUtil.createCell(row, 5, "Overwritten cell value", null);
+ assertSame(row.getCell(5), f1);
+ assertSame(F1, f1);
+ assertEquals("Overwritten cell value", f1.getStringCellValue());
+ assertEquals("Overwritten cell value", F1.getStringCellValue());
+ assertEquals(style, f1.getCellStyle(), "cell style should be unchanged with createCell(..., null)");
+ assertEquals(style, F1.getCellStyle(), "cell style should be unchanged with createCell(..., null)");
+
+ // test createCell(row, column, value) (no CellStyle)
+ f1 = CellUtil.createCell(row, 5, "Overwritten cell with default style");
+ assertSame(F1, f1);
+ }
}
/**
@@ -221,7 +214,7 @@ public abstract class BaseTestCellUtil {
// Assumptions
assertEquals(A1.getCellStyle(), B1.getCellStyle());
- // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call.
+ // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call.
// HSSFCellStyle wraps an underlying style record, and the underlying
// style record is the same between multiple getCellStyle() calls.
assertEquals(HorizontalAlignment.GENERAL, A1.getCellStyle().getAlignment());
@@ -238,7 +231,7 @@ public abstract class BaseTestCellUtil {
wb.close();
}
-
+
@Test
public void setAlignmentEnum() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
@@ -249,7 +242,7 @@ public abstract class BaseTestCellUtil {
// Assumptions
assertEquals(A1.getCellStyle(), B1.getCellStyle());
- // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call.
+ // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call.
// HSSFCellStyle wraps an underlying style record, and the underlying
// style record is the same between multiple getCellStyle() calls.
assertEquals(HorizontalAlignment.GENERAL, A1.getCellStyle().getAlignment());
@@ -266,94 +259,83 @@ public abstract class BaseTestCellUtil {
wb.close();
}
-
+
@Test
public void setVerticalAlignmentEnum() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet sh = wb.createSheet();
- Row row = sh.createRow(0);
- Cell A1 = row.createCell(0);
- Cell B1 = row.createCell(1);
-
- // Assumptions
- assertEquals(A1.getCellStyle(), B1.getCellStyle());
- // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call.
- // HSSFCellStyle wraps an underlying style record, and the underlying
- // style record is the same between multiple getCellStyle() calls.
- assertEquals(VerticalAlignment.BOTTOM, A1.getCellStyle().getVerticalAlignment());
- assertEquals(VerticalAlignment.BOTTOM, B1.getCellStyle().getVerticalAlignment());
-
- // get/set alignment modifies the cell's style
- CellUtil.setVerticalAlignment(A1, VerticalAlignment.TOP);
- assertEquals(VerticalAlignment.TOP, A1.getCellStyle().getVerticalAlignment());
-
- // get/set alignment doesn't affect the style of cells with
- // the same style prior to modifying the style
- assertNotEquals(A1.getCellStyle(), B1.getCellStyle());
- assertEquals(VerticalAlignment.BOTTOM, B1.getCellStyle().getVerticalAlignment());
-
- wb.close();
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet sh = wb.createSheet();
+ Row row = sh.createRow(0);
+ Cell A1 = row.createCell(0);
+ Cell B1 = row.createCell(1);
+
+ // Assumptions
+ assertEquals(A1.getCellStyle(), B1.getCellStyle());
+ // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call.
+ // HSSFCellStyle wraps an underlying style record, and the underlying
+ // style record is the same between multiple getCellStyle() calls.
+ assertEquals(VerticalAlignment.BOTTOM, A1.getCellStyle().getVerticalAlignment());
+ assertEquals(VerticalAlignment.BOTTOM, B1.getCellStyle().getVerticalAlignment());
+
+ // get/set alignment modifies the cell's style
+ CellUtil.setVerticalAlignment(A1, VerticalAlignment.TOP);
+ assertEquals(VerticalAlignment.TOP, A1.getCellStyle().getVerticalAlignment());
+
+ // get/set alignment doesn't affect the style of cells with
+ // the same style prior to modifying the style
+ assertNotEquals(A1.getCellStyle(), B1.getCellStyle());
+ assertEquals(VerticalAlignment.BOTTOM, B1.getCellStyle().getVerticalAlignment());
+ }
}
@Test
public void setFont() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- Sheet sh = wb.createSheet();
- Row row = sh.createRow(0);
- Cell A1 = row.createCell(0);
- Cell B1 = row.createCell(1);
- final int defaultFontIndex = 0;
- Font font = wb.createFont();
- font.setItalic(true);
- final int customFontIndex = font.getIndex();
-
- // Assumptions
- assertNotEquals(defaultFontIndex, customFontIndex);
- assertEquals(A1.getCellStyle(), B1.getCellStyle());
- // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call.
- // HSSFCellStyle wraps an underlying style record, and the underlying
- // style record is the same between multiple getCellStyle() calls.
- assertEquals(defaultFontIndex, A1.getCellStyle().getFontIndex());
- assertEquals(defaultFontIndex, B1.getCellStyle().getFontIndex());
-
- // get/set alignment modifies the cell's style
- CellUtil.setFont(A1, font);
- assertEquals(customFontIndex, A1.getCellStyle().getFontIndex());
-
- // get/set alignment doesn't affect the style of cells with
- // the same style prior to modifying the style
- assertNotEquals(A1.getCellStyle(), B1.getCellStyle());
- assertEquals(defaultFontIndex, B1.getCellStyle().getFontIndex());
-
- wb.close();
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet sh = wb.createSheet();
+ Row row = sh.createRow(0);
+ Cell A1 = row.createCell(0);
+ Cell B1 = row.createCell(1);
+ final int defaultFontIndex = 0;
+ Font font = wb.createFont();
+ font.setItalic(true);
+ final int customFontIndex = font.getIndex();
+
+ // Assumptions
+ assertNotEquals(defaultFontIndex, customFontIndex);
+ assertEquals(A1.getCellStyle(), B1.getCellStyle());
+ // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call.
+ // HSSFCellStyle wraps an underlying style record, and the underlying
+ // style record is the same between multiple getCellStyle() calls.
+ assertEquals(defaultFontIndex, A1.getCellStyle().getFontIndex());
+ assertEquals(defaultFontIndex, B1.getCellStyle().getFontIndex());
+
+ // get/set alignment modifies the cell's style
+ CellUtil.setFont(A1, font);
+ assertEquals(customFontIndex, A1.getCellStyle().getFontIndex());
+
+ // get/set alignment doesn't affect the style of cells with
+ // the same style prior to modifying the style
+ assertNotEquals(A1.getCellStyle(), B1.getCellStyle());
+ assertEquals(defaultFontIndex, B1.getCellStyle().getFontIndex());
+ }
}
@Test
public void setFontFromDifferentWorkbook() throws IOException {
- Workbook wb1 = _testDataProvider.createWorkbook();
- Workbook wb2 = _testDataProvider.createWorkbook();
- Font font1 = wb1.createFont();
- Font font2 = wb2.createFont();
- // do something to make font1 and font2 different
- // so they are not same or equal.
- font1.setItalic(true);
- Cell A1 = wb1.createSheet().createRow(0).createCell(0);
-
- // okay
- CellUtil.setFont(A1, font1);
-
- // font belongs to different workbook
- try {
- CellUtil.setFont(A1, font2);
- fail("setFont not allowed if font belongs to a different workbook");
- } catch (final IllegalArgumentException e) {
- // one specific message is expected
- if (!e.getMessage().startsWith("Font does not belong to this workbook")) {
- throw e;
- }
- } finally {
- wb1.close();
- wb2.close();
+ try (Workbook wb1 = _testDataProvider.createWorkbook();
+ Workbook wb2 = _testDataProvider.createWorkbook()) {
+ Font font1 = wb1.createFont();
+ Font font2 = wb2.createFont();
+ // do something to make font1 and font2 different
+ // so they are not same or equal.
+ font1.setItalic(true);
+ Cell A1 = wb1.createSheet().createRow(0).createCell(0);
+
+ // okay
+ CellUtil.setFont(A1, font1);
+
+ // font belongs to different workbook
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> CellUtil.setFont(A1, font2));
+ assertTrue(e.getMessage().startsWith("Font does not belong to this workbook"));
}
}
@@ -363,20 +345,19 @@ public abstract class BaseTestCellUtil {
*/
@Test
public void setFillForegroundColorBeforeFillBackgroundColorEnum() throws IOException {
- Workbook wb1 = _testDataProvider.createWorkbook();
- Cell A1 = wb1.createSheet().createRow(0).createCell(0);
- Map<String, Object> properties = new HashMap<>();
- properties.put(CellUtil.FILL_PATTERN, FillPatternType.BRICKS);
- properties.put(CellUtil.FILL_FOREGROUND_COLOR, IndexedColors.BLUE.index);
- properties.put(CellUtil.FILL_BACKGROUND_COLOR, IndexedColors.RED.index);
-
- CellUtil.setCellStyleProperties(A1, properties);
- CellStyle style = A1.getCellStyle();
- assertEquals("fill pattern", FillPatternType.BRICKS, style.getFillPattern());
- assertEquals("fill foreground color", IndexedColors.BLUE, IndexedColors.fromInt(style.getFillForegroundColor()));
- assertEquals("fill background color", IndexedColors.RED, IndexedColors.fromInt(style.getFillBackgroundColor()));
-
- wb1.close();
+ try (Workbook wb1 = _testDataProvider.createWorkbook()) {
+ Cell A1 = wb1.createSheet().createRow(0).createCell(0);
+ Map<String, Object> properties = new HashMap<>();
+ properties.put(CellUtil.FILL_PATTERN, FillPatternType.BRICKS);
+ properties.put(CellUtil.FILL_FOREGROUND_COLOR, IndexedColors.BLUE.index);
+ properties.put(CellUtil.FILL_BACKGROUND_COLOR, IndexedColors.RED.index);
+
+ CellUtil.setCellStyleProperties(A1, properties);
+ CellStyle style = A1.getCellStyle();
+ assertEquals(FillPatternType.BRICKS, style.getFillPattern(), "fill pattern");
+ assertEquals(IndexedColors.BLUE, IndexedColors.fromInt(style.getFillForegroundColor()), "fill foreground color");
+ assertEquals(IndexedColors.RED, IndexedColors.fromInt(style.getFillBackgroundColor()), "fill background color");
+ }
}
/**
diff --git a/src/testcases/org/apache/poi/ss/util/TestAreaReference.java b/src/testcases/org/apache/poi/ss/util/TestAreaReference.java
index d15dd5f7dd..3d7f99839b 100644
--- a/src/testcases/org/apache/poi/ss/util/TestAreaReference.java
+++ b/src/testcases/org/apache/poi/ss/util/TestAreaReference.java
@@ -16,20 +16,19 @@
==================================================================== */
package org.apache.poi.ss.util;
+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.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.SpreadsheetVersion;
-
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.Test;
/**
* Test for {@link AreaReference} handling of max rows.
- *
+ *
* @author David North
*/
public class TestAreaReference {
@@ -63,7 +62,7 @@ public class TestAreaReference {
assertEquals(0, oldStyle.getFirstCell().getRow());
assertEquals(SpreadsheetVersion.EXCEL97.getLastColumnIndex(), oldStyle.getLastCell().getCol());
assertEquals(1, oldStyle.getLastCell().getRow());
-
+
AreaReference newStyle = AreaReference.getWholeRow(SpreadsheetVersion.EXCEL2007, "1", "2");
assertEquals(0, newStyle.getFirstCell().getCol());
assertEquals(0, newStyle.getFirstCell().getRow());
diff --git a/src/testcases/org/apache/poi/ss/util/TestCellAddress.java b/src/testcases/org/apache/poi/ss/util/TestCellAddress.java
index 96c783f6a7..dffeff5ea8 100644
--- a/src/testcases/org/apache/poi/ss/util/TestCellAddress.java
+++ b/src/testcases/org/apache/poi/ss/util/TestCellAddress.java
@@ -17,14 +17,15 @@
package org.apache.poi.ss.util;
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.util.Arrays;
+import org.junit.jupiter.api.Test;
+
/**
* Tests that the common CellAddress works as we need it to.
*/
@@ -57,7 +58,7 @@ public final class TestCellAddress {
assertEquals(new CellReference(6, 4), new CellReference(6, 4));
assertNotEquals(new CellReference(4, 6), new CellReference(6, 4));
}
-
+
@SuppressWarnings("EqualsWithItself")
@Test
public void testCompareTo() {
@@ -65,27 +66,27 @@ public final class TestCellAddress {
final CellAddress A2 = new CellAddress(1, 0);
final CellAddress B1 = new CellAddress(0, 1);
final CellAddress B2 = new CellAddress(1, 1);
-
+
assertEquals(0, A1.compareTo(A1));
assertEquals(-1, A1.compareTo(B1));
assertEquals(-1, A1.compareTo(A2));
assertEquals(-1, A1.compareTo(B2));
-
+
assertEquals(1, B1.compareTo(A1));
assertEquals(0, B1.compareTo(B1));
assertEquals(-1, B1.compareTo(A2));
assertEquals(-1, B1.compareTo(B2));
-
+
assertEquals(1, A2.compareTo(A1));
assertEquals(1, A2.compareTo(B1));
assertEquals(0, A2.compareTo(A2));
assertEquals(-1, A2.compareTo(B2));
-
+
assertEquals(1, B2.compareTo(A1));
assertEquals(1, B2.compareTo(B1));
assertEquals(1, B2.compareTo(A2));
assertEquals(0, B2.compareTo(B2));
-
+
CellAddress[] sorted = {A1, B1, A2, B2};
CellAddress[] unsorted = {B1, B2, A1, A2};
assumeTrue(!Arrays.equals(sorted, unsorted));
@@ -98,7 +99,7 @@ public final class TestCellAddress {
final CellAddress addr = new CellAddress(6, 4);
assertEquals(6, addr.getRow());
}
-
+
@Test
public void testGetColumn() {
final CellAddress addr = new CellAddress(6, 4);
diff --git a/src/testcases/org/apache/poi/ss/util/TestCellRangeAddress.java b/src/testcases/org/apache/poi/ss/util/TestCellRangeAddress.java
index 3bc1e59980..bdf715d4cb 100644
--- a/src/testcases/org/apache/poi/ss/util/TestCellRangeAddress.java
+++ b/src/testcases/org/apache/poi/ss/util/TestCellRangeAddress.java
@@ -17,12 +17,13 @@ limitations under the License.
package org.apache.poi.ss.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+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.ByteArrayOutputStream;
import java.io.IOException;
@@ -31,7 +32,7 @@ import java.util.NoSuchElementException;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.util.LittleEndianOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestCellRangeAddress {
static final byte[] data = new byte[] {
@@ -53,13 +54,9 @@ public final class TestCellRangeAddress {
@Test
public void testLoadInvalid() {
- try {
- new CellRangeAddress(
- TestcaseRecordInputStream.create(0x000, new byte[] { (byte)0x02 }));
- fail();
- } catch (RuntimeException e) {
- assertTrue("Had: " + e, e.getMessage().contains("Ran out of data"));
- }
+ RuntimeException e = assertThrows(RuntimeException.class, () ->
+ new CellRangeAddress(TestcaseRecordInputStream.create(0x000, new byte[]{(byte) 0x02})));
+ assertTrue(e.getMessage().contains("Ran out of data"));
}
@Test
@@ -74,7 +71,7 @@ public final class TestCellRangeAddress {
recordBytes = baos.toByteArray();
assertEquals(recordBytes.length, data.length);
for (int i = 0; i < data.length; i++) {
- assertEquals("At offset " + i, 0, recordBytes[i]);
+ assertEquals(0, recordBytes[i], "At offset " + i);
}
// Now set the flags
@@ -90,26 +87,16 @@ public final class TestCellRangeAddress {
assertEquals(recordBytes.length, data.length);
for (int i = 0; i < data.length; i++) {
- assertEquals("At offset " + i, data[i], recordBytes[i]);
+ assertEquals(data[i], recordBytes[i], "At offset " + i);
}
}
}
-
+
@Test
- public void testCreateIllegal() throws IOException {
+ public void testCreateIllegal() {
// for some combinations we expected exceptions
- try {
- new CellRangeAddress(1, 0, 0, 0);
- fail("Expect to catch an exception");
- } catch (IllegalArgumentException e) {
- // expected here
- }
- try {
- new CellRangeAddress(0, 0, 1, 0);
- fail("Expect to catch an exception");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> new CellRangeAddress(1, 0, 0, 0));
+ assertThrows(IllegalArgumentException.class, () -> new CellRangeAddress(0, 0, 1, 0));
}
@Test
@@ -120,14 +107,14 @@ public final class TestCellRangeAddress {
}
@Test
- public void testGetEncodedSize() throws IOException {
+ public void testGetEncodedSize() {
assertEquals(2*CellRangeAddress.ENCODED_SIZE, CellRangeAddress.getEncodedSize(2));
}
@Test
- public void testFormatAsString() throws IOException {
+ public void testFormatAsString() {
CellRangeAddress ref = new CellRangeAddress(1, 2, 3, 4);
-
+
assertEquals("D2:E3", ref.formatAsString());
assertEquals("D2:E3", CellRangeAddress.valueOf(ref.formatAsString()).formatAsString());
@@ -142,11 +129,11 @@ public final class TestCellRangeAddress {
assertEquals("D2:E3", ref.formatAsString(null, false));
assertEquals("D2:E3", CellRangeAddress.valueOf(ref.formatAsString()).formatAsString(null, false));
assertEquals("D2:E3", CellRangeAddress.valueOf(ref.formatAsString(null, false)).formatAsString(null, false));
-
+
assertEquals("$D$2:$E$3", ref.formatAsString(null, true));
assertEquals("$D$2:$E$3", CellRangeAddress.valueOf(ref.formatAsString()).formatAsString(null, true));
assertEquals("$D$2:$E$3", CellRangeAddress.valueOf(ref.formatAsString(null, true)).formatAsString(null, true));
-
+
ref = new CellRangeAddress(-1, -1, 3, 4);
assertEquals("D:E", ref.formatAsString());
assertEquals("sheet1!$D:$E", CellRangeAddress.valueOf(ref.formatAsString()).formatAsString("sheet1", true));
@@ -178,117 +165,107 @@ public final class TestCellRangeAddress {
ref = new CellRangeAddress(-1, -1, -1, -1);
assertEquals(":", ref.formatAsString());
}
-
+
@Test
public void testEquals() {
final CellRangeAddress ref1 = new CellRangeAddress(1, 2, 3, 4);
final CellRangeAddress ref2 = new CellRangeAddress(1, 2, 3, 4);
assertEquals(ref1, ref2);
-
+
// Invert first/last row, but refer to same area
ref2.setFirstRow(2);
ref2.setLastRow(1);
assertEquals(ref1, ref2);
-
+
// Invert first/last column, but refer to same area
ref2.setFirstColumn(4);
ref2.setLastColumn(3);
assertEquals(ref1, ref2);
-
+
// Refer to a different area
assertNotEquals(ref1, new CellRangeAddress(3, 4, 1, 2));
}
-
+
@Test
public void testGetMinMaxRow() {
final CellRangeAddress ref = new CellRangeAddress(1, 2, 3, 4);
assertEquals(1, ref.getMinRow());
assertEquals(2, ref.getMaxRow());
-
+
ref.setFirstRow(10);
//now ref is CellRangeAddress(10, 2, 3, 4)
assertEquals(2, ref.getMinRow());
assertEquals(10, ref.getMaxRow());
}
-
+
@Test
public void testGetMinMaxColumn() {
final CellRangeAddress ref = new CellRangeAddress(1, 2, 3, 4);
assertEquals(3, ref.getMinColumn());
assertEquals(4, ref.getMaxColumn());
-
+
ref.setFirstColumn(10);
//now ref is CellRangeAddress(1, 2, 10, 4)
assertEquals(4, ref.getMinColumn());
assertEquals(10, ref.getMaxColumn());
}
-
+
@Test
public void testIntersects() {
final CellRangeAddress baseRegion = new CellRangeAddress(0, 1, 0, 1);
-
+
final CellRangeAddress duplicateRegion = new CellRangeAddress(0, 1, 0, 1);
assertIntersects(baseRegion, duplicateRegion);
-
+
final CellRangeAddress partiallyOverlappingRegion = new CellRangeAddress(1, 2, 1, 2);
assertIntersects(baseRegion, partiallyOverlappingRegion);
-
+
final CellRangeAddress subsetRegion = new CellRangeAddress(0, 1, 0, 0);
assertIntersects(baseRegion, subsetRegion);
-
+
final CellRangeAddress supersetRegion = new CellRangeAddress(0, 2, 0, 2);
assertIntersects(baseRegion, supersetRegion);
-
+
final CellRangeAddress disjointRegion = new CellRangeAddress(10, 11, 10, 11);
assertNotIntersects(baseRegion, disjointRegion);
}
-
+
@Test
public void containsRow() {
final CellRangeAddress region = new CellRangeAddress(10, 12, 3, 5);
-
+
assertFalse(region.containsRow(9));
assertTrue(region.containsRow(10));
assertTrue(region.containsRow(11));
assertTrue(region.containsRow(12));
assertFalse(region.containsRow(13));
}
-
+
@Test
public void containsColumn() {
final CellRangeAddress region = new CellRangeAddress(10, 12, 3, 5);
-
+
assertFalse(region.containsColumn(2));
assertTrue(region.containsColumn(3));
assertTrue(region.containsColumn(4));
assertTrue(region.containsColumn(5));
assertFalse(region.containsColumn(6));
}
-
+
@Test
public void iterator() {
final CellRangeAddress A1_B2 = new CellRangeAddress(0, 1, 0, 1);
-
+
// the cell address iterator iterates in row major order
final Iterator<CellAddress> iter = A1_B2.iterator();
- assertEquals("A1", new CellAddress(0, 0), iter.next());
- assertEquals("B1", new CellAddress(0, 1), iter.next());
- assertEquals("A2", new CellAddress(1, 0), iter.next());
- assertEquals("B2", new CellAddress(1, 1), iter.next());
+ assertEquals(new CellAddress(0, 0), iter.next(), "A1");
+ assertEquals(new CellAddress(0, 1), iter.next(), "B1");
+ assertEquals(new CellAddress(1, 0), iter.next(), "A2");
+ assertEquals(new CellAddress(1, 1), iter.next(), "B2");
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException");
- } catch (final NoSuchElementException e) {
- //expected
- }
- try {
- iter.remove();
- fail("Expected UnsupportedOperationException");
- } catch (final UnsupportedOperationException e) {
- //expected
- }
-
+ assertThrows(NoSuchElementException.class, iter::next);
+ assertThrows(UnsupportedOperationException.class, iter::remove);
+
// for each interface
int count = 0;
for (final CellAddress addr : A1_B2) {
@@ -297,7 +274,7 @@ public final class TestCellRangeAddress {
}
assertEquals(4, count);
}
-
+
private static void assertIntersects(CellRangeAddress regionA, CellRangeAddress regionB) {
if (!(regionA.intersects(regionB) && regionB.intersects(regionA))) {
final String A = regionA.formatAsString();
diff --git a/src/testcases/org/apache/poi/ss/util/TestCellRangeUtil.java b/src/testcases/org/apache/poi/ss/util/TestCellRangeUtil.java
index 377f78d82a..0de86405da 100644
--- a/src/testcases/org/apache/poi/ss/util/TestCellRangeUtil.java
+++ b/src/testcases/org/apache/poi/ss/util/TestCellRangeUtil.java
@@ -17,13 +17,14 @@
package org.apache.poi.ss.util;
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-import java.util.HashSet;
+
+import org.junit.jupiter.api.Test;
/**
* Tests CellRangeUtil.
@@ -31,7 +32,7 @@ import java.util.HashSet;
* @see org.apache.poi.ss.util.CellRangeUtil
*/
public final class TestCellRangeUtil {
-
+
private static final CellRangeAddress A1 = new CellRangeAddress(0, 0, 0, 0);
private static final CellRangeAddress B1 = new CellRangeAddress(0, 0, 1, 1);
private static final CellRangeAddress A2 = new CellRangeAddress(1, 1, 0, 0);
@@ -39,7 +40,7 @@ public final class TestCellRangeUtil {
private static final CellRangeAddress A1_B2 = new CellRangeAddress(0, 1, 0, 1);
private static final CellRangeAddress A1_B1 = new CellRangeAddress(0, 0, 0, 1);
private static final CellRangeAddress A1_A2 = new CellRangeAddress(0, 1, 0, 0);
-
+
@Test
public void testMergeCellRanges() {
// Note that the order of the output array elements does not matter
@@ -56,7 +57,7 @@ public final class TestCellRangeUtil {
// Partially mergeable: multiple possible merges
// A B
// 1 x x A1,A2,B1 --> A1:B1,A2 or A1:A2,B1
- // 2 x
+ // 2 x
assertCellRangesEqual(asArray(A1_B1, A2), merge(A1, B1, A2));
assertCellRangesEqual(asArray(A1_A2, B1), merge(A2, A1, B1));
assertCellRangesEqual(asArray(A1_B1, A2), merge(B1, A2, A1));
diff --git a/src/testcases/org/apache/poi/ss/util/TestCellReference.java b/src/testcases/org/apache/poi/ss/util/TestCellReference.java
index 095eb701d2..b2222986d0 100644
--- a/src/testcases/org/apache/poi/ss/util/TestCellReference.java
+++ b/src/testcases/org/apache/poi/ss/util/TestCellReference.java
@@ -17,24 +17,24 @@
package org.apache.poi.ss.util;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.SpreadsheetVersion;
-
import org.apache.poi.ss.usermodel.Cell;
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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import org.junit.jupiter.api.Test;
/**
* Tests that the common CellReference works as we need it to.
@@ -288,7 +288,7 @@ public final class TestCellReference {
confirmCrInRange(false, "XFD", "1048577", v2007);
confirmCrInRange(false, "XFE", "1048576", v2007);
- assertFalse("Identified bug 47312a", CellReference.cellReferenceIsWithinRange("B", "0", v97));
+ assertFalse(CellReference.cellReferenceIsWithinRange("B", "0", v97), "Identified bug 47312a");
confirmCrInRange(false, "A", "0", v97);
confirmCrInRange(false, "A", "0", v2007);
@@ -296,35 +296,17 @@ public final class TestCellReference {
@Test
public void testInvalidReference() {
- try {
- new CellReference("Sheet1!#REF!");
- fail("Shouldn't be able to create a #REF! refence");
- } catch(IllegalArgumentException expected) {
- // expected here
- }
-
- try {
- new CellReference("'MySheetName'!#REF!");
- fail("Shouldn't be able to create a #REF! refence");
- } catch(IllegalArgumentException expected) {
- // expected here
- }
-
- try {
- new CellReference("#REF!");
- fail("Shouldn't be able to create a #REF! refence");
- } catch(IllegalArgumentException expected) {
- // expected here
+ for (String s : new String[]{"Sheet1!#REF!", "'MySheetName'!#REF!", "#REF!"}) {
+ assertThrows(IllegalArgumentException.class, () -> new CellReference(s),
+ "Shouldn't be able to create a #REF! "+s);
}
}
- private static void confirmCrInRange(boolean expResult, String colStr, String rowStr,
- SpreadsheetVersion sv) {
- if (expResult == CellReference.cellReferenceIsWithinRange(colStr, rowStr, sv)) {
- return;
- }
- fail("expected (c='" + colStr + "', r='" + rowStr + "' to be "
- + (expResult ? "within" : "out of") + " bounds for version " + sv.name());
+ private static void confirmCrInRange(boolean expResult, String colStr, String rowStr, SpreadsheetVersion sv) {
+ assertEquals(expResult, CellReference.cellReferenceIsWithinRange(colStr, rowStr, sv),
+ "expected (c='" + colStr + "', r='" + rowStr + "' to be "
+ + (expResult ? "within" : "out of") + " bounds for version " + sv.name()
+ );
}
@Test
@@ -338,12 +320,9 @@ public final class TestCellReference {
assertEquals(0, CellReference.convertColStringToIndex("$A"));
assertEquals(1, CellReference.convertColStringToIndex("$B"));
- try {
- CellReference.convertColStringToIndex("A$");
- fail("Should throw exception here");
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("A$"));
- }
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+ () -> CellReference.convertColStringToIndex("A$"));
+ assertTrue(e.getMessage().contains("A$"));
}
@Test
@@ -368,10 +347,10 @@ public final class TestCellReference {
assertEquals("HOME", ref.getSheetName());
assertEquals(168, ref.getRow());
assertEquals(-1, ref.getCol());
- assertTrue("row absolute", ref.isRowAbsolute());
+ assertTrue(ref.isRowAbsolute(), "row absolute");
//assertFalse("column absolute/relative is undefined", ref.isColAbsolute());
}
-
+
@Test
public void getSheetName() {
assertNull(new CellReference("A5").getSheetName());
@@ -381,39 +360,38 @@ public final class TestCellReference {
assertEquals("Sheet1", new CellReference("Sheet1!A5").getSheetName());
assertEquals("Sheet 1", new CellReference("'Sheet 1'!A5").getSheetName());
}
-
+
@Test
public void testToString() {
CellReference ref = new CellReference("'Sheet 1'!A5");
assertEquals("org.apache.poi.ss.util.CellReference ['Sheet 1'!A5]", ref.toString());
}
-
+
@Test
public void testEqualsAndHashCode() {
CellReference ref1 = new CellReference("'Sheet 1'!A5");
CellReference ref2 = new CellReference("Sheet 1", 4, 0, false, false);
- assertEquals("equals", ref1, ref2);
- assertEquals("hash code", ref1.hashCode(), ref2.hashCode());
+ assertEquals(ref1, ref2);
+ assertEquals(ref1.hashCode(), ref2.hashCode());
//noinspection ObjectEqualsNull
- assertNotEquals("null", null, ref1);
- assertNotEquals("3D vs 2D", ref1, new CellReference("A5"));
- assertNotEquals("type", ref1, 0L);
+ assertNotEquals(null, ref1);
+ assertNotEquals(ref1, new CellReference("A5"));
}
@Test
public void isRowWithinRange() {
SpreadsheetVersion ss = SpreadsheetVersion.EXCEL2007;
- assertFalse("1 before first row", CellReference.isRowWithinRange("0", ss));
- assertTrue("first row", CellReference.isRowWithinRange("1", ss));
- assertTrue("last row", CellReference.isRowWithinRange("1048576", ss));
- assertFalse("1 beyond last row", CellReference.isRowWithinRange("1048577", ss));
+ assertFalse(CellReference.isRowWithinRange("0", ss), "1 before first row");
+ assertTrue(CellReference.isRowWithinRange("1", ss), "first row");
+ assertTrue(CellReference.isRowWithinRange("1048576", ss), "last row");
+ assertFalse(CellReference.isRowWithinRange("1048577", ss), "1 beyond last row");
// int versions of above, using 0-based indices
- assertFalse("1 before first row", CellReference.isRowWithinRange(-1, ss));
- assertTrue("first row", CellReference.isRowWithinRange(0, ss));
- assertTrue("last row", CellReference.isRowWithinRange(1048575, ss));
- assertFalse("1 beyond last row", CellReference.isRowWithinRange(1048576, ss));
+ assertFalse(CellReference.isRowWithinRange(-1, ss), "1 before first row");
+ assertTrue(CellReference.isRowWithinRange(0, ss), "first row");
+ assertTrue(CellReference.isRowWithinRange(1048575, ss), "last row");
+ assertFalse(CellReference.isRowWithinRange(1048576, ss), "1 beyond last row");
}
@Test
@@ -421,63 +399,59 @@ public final class TestCellReference {
String rowNum = "4000000000";
assertFalse(CellReference.isRowWithinRange(rowNum, SpreadsheetVersion.EXCEL2007));
}
-
- @Test(expected=NumberFormatException.class)
+
+ @Test
public void isRowWithinRangeNonInteger_Alpha() {
String rowNum = "NotANumber";
- CellReference.isRowWithinRange(rowNum, SpreadsheetVersion.EXCEL2007);
+ assertThrows(NumberFormatException.class, () -> CellReference.isRowWithinRange(rowNum, SpreadsheetVersion.EXCEL2007));
}
@Test
public void isColWithinRange() {
SpreadsheetVersion ss = SpreadsheetVersion.EXCEL2007;
- assertTrue("(empty)", CellReference.isColumnWithinRange("", ss));
- assertTrue("first column (A)", CellReference.isColumnWithinRange("A", ss));
- assertTrue("last column (XFD)", CellReference.isColumnWithinRange("XFD", ss));
- assertFalse("1 beyond last column (XFE)", CellReference.isColumnWithinRange("XFE", ss));
+ assertTrue(CellReference.isColumnWithinRange("", ss), "(empty)");
+ assertTrue(CellReference.isColumnWithinRange("A", ss), "first column (A)");
+ assertTrue(CellReference.isColumnWithinRange("XFD", ss), "last column (XFD)");
+ assertFalse(CellReference.isColumnWithinRange("XFE", ss), "1 beyond last column (XFE)");
}
-
- @Test(expected=IllegalArgumentException.class)
+
+ @Test
public void unquotedSheetName() {
- new CellReference("'Sheet 1!A5");
+ assertThrows(IllegalArgumentException.class, () -> new CellReference("'Sheet 1!A5"));
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void mismatchedQuotesSheetName() {
- new CellReference("Sheet 1!A5");
+ assertThrows(IllegalArgumentException.class, () -> new CellReference("Sheet 1!A5"));
}
-
+
@Test
public void escapedSheetName() {
String escapedName = "'Don''t Touch'!A5";
String unescapedName = "'Don't Touch'!A5";
new CellReference(escapedName);
- try {
- new CellReference(unescapedName);
- fail("Sheet names containing apostrophe's must be escaped via a repeated apostrophe");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Bad sheet name quote escaping: "));
- }
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> new CellReference(unescapedName));
+ assertTrue(e.getMessage().startsWith("Bad sheet name quote escaping: "));
}
-
- @Test(expected=IllegalArgumentException.class)
+
+ @Test
public void negativeRow() {
- new CellReference("sheet", -2, 0, false, false);
+ assertThrows(IllegalArgumentException.class, () -> new CellReference("sheet", -2, 0, false, false));
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void negativeColumn() {
- new CellReference("sheet", 0, -2, false, false);
+ assertThrows(IllegalArgumentException.class, () -> new CellReference("sheet", 0, -2, false, false));
}
-
- @Test(expected=IllegalArgumentException.class)
+
+ @Test
public void classifyEmptyStringCellReference() {
- CellReference.classifyCellReference("", SpreadsheetVersion.EXCEL2007);
+ assertThrows(IllegalArgumentException.class, () -> CellReference.classifyCellReference("", SpreadsheetVersion.EXCEL2007));
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void classifyInvalidFirstCharCellReference() {
- CellReference.classifyCellReference("!A5", SpreadsheetVersion.EXCEL2007);
+ assertThrows(IllegalArgumentException.class, () -> CellReference.classifyCellReference("!A5", SpreadsheetVersion.EXCEL2007));
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java b/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java
index 4a0115605a..5a6bb29ad0 100644
--- a/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java
+++ b/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java
@@ -19,10 +19,10 @@
package org.apache.poi.ss.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
@@ -46,7 +46,7 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.LocaleID;
import org.apache.poi.util.TempFile;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestDateFormatConverter {
private void outputLocaleDataFormats( Date date, boolean dates, boolean times, int style, String styleName ) throws Exception {
@@ -181,20 +181,20 @@ public final class TestDateFormatConverter {
final String partTag = langTag.substring(0, idx);
Locale loc = Locale.forLanguageTag(partTag);
- assertNotNull("Invalid language tag: "+partTag, loc);
+ assertNotNull(loc, "Invalid language tag: "+partTag);
if (excludeList.contains(partTag)) {
continue;
}
String prefix = DateFormatConverter.getPrefixForLocale(loc);
- assertNotNull("Prefix not found - language tag: "+partTag, prefix);
- assertNotEquals("Prefix not found - language tag: "+partTag,"", prefix);
+ assertNotNull(prefix, "Prefix not found - language tag: "+partTag);
+ assertNotEquals("", prefix, "Prefix not found - language tag: "+partTag);
Matcher m = p.matcher(prefix);
- assertTrue("Invalid prefix: "+prefix, m.matches());
+ assertTrue(m.matches(), "Invalid prefix: "+prefix);
LocaleID partLid = LocaleID.lookupByLanguageTag(partTag);
- assertNotNull("LocaleID not found for part: "+partTag, partLid);
+ assertNotNull(partLid, "LocaleID not found for part: "+partTag);
assertEquals(partLid.getLcid(), Integer.parseInt(m.group(1), 16));
}
}
diff --git a/src/testcases/org/apache/poi/ss/util/TestDateParser.java b/src/testcases/org/apache/poi/ss/util/TestDateParser.java
index d20d234ef7..7b86ff1102 100644
--- a/src/testcases/org/apache/poi/ss/util/TestDateParser.java
+++ b/src/testcases/org/apache/poi/ss/util/TestDateParser.java
@@ -17,63 +17,50 @@
package org.apache.poi.ss.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Calendar;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
public class TestDateParser {
- @Test
- public void testFailWhenNoDate() {
- try {
- DateParser.parseDate("potato");
- fail("Shouldn't parse potato!");
- } catch (EvaluationException e) {
- assertEquals(ErrorEval.VALUE_INVALID, e.getErrorEval());
- }
- }
-
- @Test
- public void testFailWhenLooksLikeDateButItIsnt() {
- try {
- DateParser.parseDate("potato/cucumber/banana");
- fail("Shouldn't parse this thing!");
- } catch (EvaluationException e) {
- assertEquals(ErrorEval.VALUE_INVALID, e.getErrorEval());
- }
- }
-
- @Test
- public void testFailWhenIsInvalidDate() {
- try {
- DateParser.parseDate("13/13/13");
- fail("Shouldn't parse this thing!");
- } catch (EvaluationException e) {
- assertEquals(ErrorEval.VALUE_INVALID, e.getErrorEval());
- }
+ @ParameterizedTest
+ @ValueSource(strings = {
+ // no date
+ "potato",
+ // fail when looks like date but it isnt
+ "potato/cucumber/banana",
+ // fail when is invalid date
+ "13/13/13"
+ })
+ public void testFailWhenInvalidDate(String invalidDate) {
+ EvaluationException e = assertThrows(EvaluationException.class,
+ () -> DateParser.parseDate(invalidDate), "Shouldn't parse " + invalidDate);
+ assertEquals(ErrorEval.VALUE_INVALID, e.getErrorEval());
}
@Test
public void testShouldParseValidDate() throws EvaluationException {
Calendar expDate = LocaleUtil.getLocaleCalendar(1984, Calendar.OCTOBER, 20);
Calendar actDate = DateParser.parseDate("1984/10/20");
- assertEquals("Had: " + expDate.getTime() + " and " + actDate.getTime() + "/" +
- expDate.getTimeInMillis() + "ms and " + actDate.getTimeInMillis() + "ms",
- expDate, actDate);
+ assertEquals(expDate, actDate,
+ "Had: " + expDate.getTime() + " and " + actDate.getTime() + "/" +
+ expDate.getTimeInMillis() + "ms and " + actDate.getTimeInMillis() + "ms");
}
@Test
public void testShouldIgnoreTimestamp() throws EvaluationException {
Calendar expDate = LocaleUtil.getLocaleCalendar(1984, Calendar.OCTOBER, 20);
Calendar actDate = DateParser.parseDate("1984/10/20 12:34:56");
- assertEquals("Had: " + expDate.getTime() + " and " + actDate.getTime() + "/" +
- expDate.getTimeInMillis() + "ms and " + actDate.getTimeInMillis() + "ms",
- expDate, actDate);
+ assertEquals(expDate, actDate,
+ "Had: " + expDate.getTime() + " and " + actDate.getTime() + "/" +
+ expDate.getTimeInMillis() + "ms and " + actDate.getTimeInMillis() + "ms");
}
}
diff --git a/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java b/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java
index c02f58dd2f..7b285a60b4 100644
--- a/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java
+++ b/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java
@@ -17,13 +17,13 @@
package org.apache.poi.ss.util;
-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 java.math.BigInteger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link ExpandedDouble}
@@ -34,7 +34,7 @@ public final class TestExpandedDouble {
@Test
public void testNegative() {
ExpandedDouble hd = new ExpandedDouble(0xC010000000000000L);
- assertNotEquals("identified bug - sign bit not masked out of exponent", -2046, hd.getBinaryExponent());
+ assertNotEquals(-2046, hd.getBinaryExponent(), "identified bug - sign bit not masked out of exponent");
assertEquals(2, hd.getBinaryExponent());
BigInteger frac = hd.getSignificand();
assertEquals(64, frac.bitLength());
@@ -44,7 +44,7 @@ public final class TestExpandedDouble {
@Test
public void testSubnormal() {
ExpandedDouble hd = new ExpandedDouble(0x0000000000000001L);
- assertNotEquals("identified bug - subnormal numbers not decoded properly", -1023, hd.getBinaryExponent());
+ assertNotEquals(-1023, hd.getBinaryExponent(), "identified bug - subnormal numbers not decoded properly");
assertEquals(-1086, hd.getBinaryExponent());
BigInteger frac = hd.getSignificand();
assertEquals(64, frac.bitLength());
@@ -91,7 +91,7 @@ public final class TestExpandedDouble {
checkNormaliseBaseTenResult(ed1, nd2);
ExpandedDouble ed3 = nd2.normaliseBaseTwo();
- assertEquals("bin exp mismatch", ed3.getBinaryExponent(), ed1.getBinaryExponent());
+ assertEquals(ed3.getBinaryExponent(), ed1.getBinaryExponent(), "bin exp mismatch");
BigInteger diff = ed3.getSignificand().subtract(ed1.getSignificand()).abs();
if (diff.signum() == 0) {
@@ -127,6 +127,6 @@ public final class TestExpandedDouble {
}
BigInteger diff = subDigsB.subtract(subDigsO).abs();
// 100/32768 ~= 0.003
- assertTrue("minor mistake", diff.intValue() <= 100);
+ assertTrue(diff.intValue() <= 100, "minor mistake");
}
}
diff --git a/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java b/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
index 66e357b753..abd9a01177 100644
--- a/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
+++ b/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
@@ -17,13 +17,14 @@
package org.apache.poi.ss.util;
-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.util.NumberComparisonExamples.ComparisonExample;
import org.apache.poi.util.HexDump;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
/**
* Tests for {@link NumberComparer}
*/
@@ -42,7 +43,7 @@ public final class TestNumberComparer {
success &= confirm(i, ce.getNegB(), ce.getNegA(), +ce.getExpectedResult());
}
- assertTrue("One or more cases failed. See stderr", success);
+ assertTrue(success, "One or more cases failed. See stderr");
}
@Test
@@ -68,7 +69,6 @@ public final class TestNumberComparer {
public void testSpecificExampleA() {
double a = 0.06-0.01;
double b = 0.05;
- //noinspection ConstantConditions
assertNotEquals(a, b, 0.0);
assertEquals(0, NumberComparer.compare(a, b));
}
@@ -80,7 +80,6 @@ public final class TestNumberComparer {
public void testSpecificExampleB() {
double a = 1+1.0028-0.9973;
double b = 1.0055;
- //noinspection ConstantConditions
assertNotEquals(a, b, 0.0);
assertEquals(0, NumberComparer.compare(a, b));
}
diff --git a/src/testcases/org/apache/poi/ss/util/TestNumberToTextConverter.java b/src/testcases/org/apache/poi/ss/util/TestNumberToTextConverter.java
index a471923b2d..feb8fa8b0f 100644
--- a/src/testcases/org/apache/poi/ss/util/TestNumberToTextConverter.java
+++ b/src/testcases/org/apache/poi/ss/util/TestNumberToTextConverter.java
@@ -17,14 +17,14 @@
package org.apache.poi.ss.util;
-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.hssf.record.FormulaRecord;
import org.apache.poi.ss.formula.constant.ConstantValueParser;
import org.apache.poi.ss.formula.ptg.NumberPtg;
import org.apache.poi.ss.util.NumberToTextConversionExamples.ExampleConversion;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link NumberToTextConverter}
diff --git a/src/testcases/org/apache/poi/ss/util/TestPropertyTemplate.java b/src/testcases/org/apache/poi/ss/util/TestPropertyTemplate.java
index 927f764280..b53e92dd9c 100644
--- a/src/testcases/org/apache/poi/ss/util/TestPropertyTemplate.java
+++ b/src/testcases/org/apache/poi/ss/util/TestPropertyTemplate.java
@@ -17,8 +17,8 @@
package org.apache.poi.ss.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
import java.io.IOException;
@@ -31,7 +31,7 @@ import org.apache.poi.ss.usermodel.IndexedColors;
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;
/**
* Tests Spreadsheet PropertyTemplate
@@ -799,12 +799,12 @@ public final class TestPropertyTemplate {
}
}
}
-
+
@Test
public void drawBordersWithColors() throws IOException {
CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
PropertyTemplate pt = new PropertyTemplate();
-
+
pt.drawBorders(a1c3, BorderStyle.MEDIUM, IndexedColors.RED.getIndex(), BorderExtent.ALL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
@@ -855,10 +855,10 @@ public final class TestPropertyTemplate {
PropertyTemplate pt = new PropertyTemplate();
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
-
+
pt.drawBorders(a1c3, BorderStyle.THIN, IndexedColors.RED.getIndex(), BorderExtent.ALL);
pt.applyBorders(sheet);
-
+
for (Row row: sheet) {
for (Cell cell: row) {
CellStyle cs = cell.getCellStyle();
@@ -872,10 +872,10 @@ public final class TestPropertyTemplate {
assertEquals(IndexedColors.RED.getIndex(), cs.getRightBorderColor());
}
}
-
+
pt.drawBorders(b2, BorderStyle.NONE, BorderExtent.ALL);
pt.applyBorders(sheet);
-
+
for (Row row: sheet) {
for (Cell cell: row) {
CellStyle cs = cell.getCellStyle();
@@ -905,10 +905,10 @@ public final class TestPropertyTemplate {
}
}
}
-
+
wb.close();
}
-
+
@Test
public void clonePropertyTemplate() throws IOException {
CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
@@ -922,14 +922,14 @@ public final class TestPropertyTemplate {
assertEquals(4, pt2.getNumBorderColors(i, j));
}
}
-
+
CellRangeAddress b2 = new CellRangeAddress(1,1,1,1);
pt2.drawBorders(b2, BorderStyle.THIN, BorderExtent.ALL);
-
+
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
pt.applyBorders(sheet);
-
+
for (Row row : sheet) {
for (Cell cell : row) {
CellStyle cs = cell.getCellStyle();
@@ -943,7 +943,7 @@ public final class TestPropertyTemplate {
assertEquals(IndexedColors.RED.getIndex(), cs.getRightBorderColor());
}
}
-
+
wb.close();
}
}
diff --git a/src/testcases/org/apache/poi/ss/util/TestRegionUtil.java b/src/testcases/org/apache/poi/ss/util/TestRegionUtil.java
index 6e3842b7a9..67f1e1310f 100644
--- a/src/testcases/org/apache/poi/ss/util/TestRegionUtil.java
+++ b/src/testcases/org/apache/poi/ss/util/TestRegionUtil.java
@@ -17,7 +17,7 @@
package org.apache.poi.ss.util;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
@@ -27,9 +27,9 @@ import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
@@ -44,18 +44,18 @@ public final class TestRegionUtil {
private static final int DEFAULT_COLOR = 0;
private Workbook wb;
private Sheet sheet;
-
- @Before
+
+ @BeforeEach
public void setUp() {
wb = new HSSFWorkbook();
sheet = wb.createSheet();
}
-
- @After
+
+ @AfterEach
public void tearDown() throws IOException {
wb.close();
}
-
+
private CellStyle getCellStyle(int rowIndex, int columnIndex) {
Row row = sheet.getRow(rowIndex);
if (row == null) row = sheet.createRow(rowIndex);
@@ -63,7 +63,7 @@ public final class TestRegionUtil {
if (cell == null) cell = row.createCell(columnIndex);
return cell.getCellStyle();
}
-
+
@Test
public void setBorderTop() {
assertEquals(NONE, getCellStyle(0, 0).getBorderTop());
@@ -104,7 +104,7 @@ public final class TestRegionUtil {
assertEquals(THIN, getCellStyle(1, 0).getBorderLeft());
assertEquals(THIN, getCellStyle(2, 0).getBorderLeft());
}
-
+
@Test
public void setTopBorderColor() {
assertEquals(DEFAULT_COLOR, getCellStyle(0, 0).getTopBorderColor());
@@ -145,7 +145,7 @@ public final class TestRegionUtil {
assertEquals(RED, getCellStyle(1, 0).getLeftBorderColor());
assertEquals(RED, getCellStyle(2, 0).getLeftBorderColor());
}
-
+
@Test
public void bordersCanBeAddedToNonExistantCells() {
RegionUtil.setBorderTop(THIN, A1C3, sheet);
diff --git a/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java b/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java
index cae0407ab7..0951e72afa 100644
--- a/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java
+++ b/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss.util;
-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.io.IOException;
import java.util.Date;
@@ -30,7 +30,7 @@ import org.apache.poi.ss.usermodel.CellType;
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;
/**
* Tests SheetBuilder.
diff --git a/src/testcases/org/apache/poi/ss/util/TestSheetUtil.java b/src/testcases/org/apache/poi/ss/util/TestSheetUtil.java
index 44b75f5be5..ebf84dc424 100644
--- a/src/testcases/org/apache/poi/ss/util/TestSheetUtil.java
+++ b/src/testcases/org/apache/poi/ss/util/TestSheetUtil.java
@@ -5,9 +5,9 @@
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,13 +22,14 @@ import org.apache.poi.ss.usermodel.Cell;
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;
import java.io.IOException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests SheetUtil.
@@ -38,122 +39,128 @@ import static org.junit.Assert.assertTrue;
public final class TestSheetUtil {
@Test
public void testCellWithMerges() throws Exception {
- Workbook wb = new HSSFWorkbook();
- Sheet s = wb.createSheet();
-
- // Create some test data
- Row r2 = s.createRow(1);
- r2.createCell(0).setCellValue(10);
- r2.createCell(1).setCellValue(11);
- Row r3 = s.createRow(2);
- r3.createCell(0).setCellValue(20);
- r3.createCell(1).setCellValue(21);
-
- assertEquals(0, s.addMergedRegion(new CellRangeAddress(2, 3, 0, 0)));
- assertEquals(1, s.addMergedRegion(new CellRangeAddress(2, 2, 1, 4)));
-
- // With a cell that isn't defined, we'll get null
- assertNull(SheetUtil.getCellWithMerges(s, 0, 0));
-
- // With a cell that's not in a merged region, we'll get that
- assertEquals(10.0, SheetUtil.getCellWithMerges(s, 1, 0).getNumericCellValue(), 0.01);
- assertEquals(11.0, SheetUtil.getCellWithMerges(s, 1, 1).getNumericCellValue(), 0.01);
-
- // With a cell that's the primary one of a merged region, we get that cell
- assertEquals(20.0, SheetUtil.getCellWithMerges(s, 2, 0).getNumericCellValue(), 0.01);
- assertEquals(21., SheetUtil.getCellWithMerges(s, 2, 1).getNumericCellValue(), 0.01);
-
- // With a cell elsewhere in the merged region, get top-left
- assertEquals(20.0, SheetUtil.getCellWithMerges(s, 3, 0).getNumericCellValue(), 0.01);
- assertEquals(21.0, SheetUtil.getCellWithMerges(s, 2, 2).getNumericCellValue(), 0.01);
- assertEquals(21.0, SheetUtil.getCellWithMerges(s, 2, 3).getNumericCellValue(), 0.01);
- assertEquals(21.0, SheetUtil.getCellWithMerges(s, 2, 4).getNumericCellValue(), 0.01);
-
- wb.close();
+ try (Workbook wb = new HSSFWorkbook()) {
+ Sheet s = wb.createSheet();
+
+ // Create some test data
+ Row r2 = s.createRow(1);
+ r2.createCell(0).setCellValue(10);
+ r2.createCell(1).setCellValue(11);
+ Row r3 = s.createRow(2);
+ r3.createCell(0).setCellValue(20);
+ r3.createCell(1).setCellValue(21);
+
+ assertEquals(0, s.addMergedRegion(new CellRangeAddress(2, 3, 0, 0)));
+ assertEquals(1, s.addMergedRegion(new CellRangeAddress(2, 2, 1, 4)));
+
+ // With a cell that isn't defined, we'll get null
+ assertNull(SheetUtil.getCellWithMerges(s, 0, 0));
+
+ // With a cell that's not in a merged region, we'll get that
+ Cell cell = SheetUtil.getCellWithMerges(s, 1, 0);
+ assertNotNull(cell);
+ assertEquals(10.0, cell.getNumericCellValue(), 0.01);
+ cell = SheetUtil.getCellWithMerges(s, 1, 1);
+ assertNotNull(cell);
+ assertEquals(11.0, cell.getNumericCellValue(), 0.01);
+
+ // With a cell that's the primary one of a merged region, we get that cell
+ cell = SheetUtil.getCellWithMerges(s, 2, 0);
+ assertNotNull(cell);
+ assertEquals(20.0, cell.getNumericCellValue(), 0.01);
+ cell = SheetUtil.getCellWithMerges(s, 2, 1);
+ assertNotNull(cell);
+ assertEquals(21., cell.getNumericCellValue(), 0.01);
+
+ // With a cell elsewhere in the merged region, get top-left
+ cell = SheetUtil.getCellWithMerges(s, 3, 0);
+ assertNotNull(cell);
+ assertEquals(20.0, cell.getNumericCellValue(), 0.01);
+ cell = SheetUtil.getCellWithMerges(s, 2, 2);
+ assertNotNull(cell);
+ assertEquals(21.0, cell.getNumericCellValue(), 0.01);
+ cell = SheetUtil.getCellWithMerges(s, 2, 3);
+ assertNotNull(cell);
+ assertEquals(21.0, cell.getNumericCellValue(), 0.01);
+ assertNotNull(cell);
+ cell = SheetUtil.getCellWithMerges(s, 2, 4);
+ assertNotNull(cell);
+ assertEquals(21.0, cell.getNumericCellValue(), 0.01);
+ }
}
@Test
public void testCanComputeWidthHSSF() throws IOException {
- Workbook wb = new HSSFWorkbook();
-
- // cannot check on result because on some machines we get back false here!
- SheetUtil.canComputeColumnWidth(wb.getFontAt(0));
-
- wb.close();
+ try (Workbook wb = new HSSFWorkbook()) {
+ // cannot check on result because on some machines we get back false here!
+ SheetUtil.canComputeColumnWidth(wb.getFontAt(0));
+ }
}
@Test
public void testGetCellWidthEmpty() throws IOException {
- Workbook wb = new HSSFWorkbook();
- Sheet sheet = wb.createSheet("sheet");
- Row row = sheet.createRow(0);
- Cell cell = row.createCell(0);
-
- // no contents: cell.setCellValue("sometext");
-
- assertEquals(-1.0, SheetUtil.getCellWidth(cell, 1, null, true), 0.01);
-
- wb.close();
+ try (Workbook wb = new HSSFWorkbook()) {
+ Sheet sheet = wb.createSheet("sheet");
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+
+ // no contents: cell.setCellValue("sometext");
+ assertEquals(-1.0, SheetUtil.getCellWidth(cell, 1, null, true), 0.01);
+ }
}
@Test
public void testGetCellWidthString() throws IOException {
- Workbook wb = new HSSFWorkbook();
- Sheet sheet = wb.createSheet("sheet");
- Row row = sheet.createRow(0);
- Cell cell = row.createCell(0);
-
- cell.setCellValue("sometext");
-
- assertTrue(SheetUtil.getCellWidth(cell, 1, null, true) > 0);
-
- wb.close();
+ try (Workbook wb = new HSSFWorkbook()) {
+ Sheet sheet = wb.createSheet("sheet");
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+
+ cell.setCellValue("sometext");
+
+ assertTrue(SheetUtil.getCellWidth(cell, 1, null, true) > 0);
+ }
}
@Test
public void testGetCellWidthNumber() throws IOException {
- Workbook wb = new HSSFWorkbook();
- Sheet sheet = wb.createSheet("sheet");
- Row row = sheet.createRow(0);
- Cell cell = row.createCell(0);
-
- cell.setCellValue(88.234);
-
- assertTrue(SheetUtil.getCellWidth(cell, 1, null, true) > 0);
-
- wb.close();
+ try (Workbook wb = new HSSFWorkbook()) {
+ Sheet sheet = wb.createSheet("sheet");
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+
+ cell.setCellValue(88.234);
+
+ assertTrue(SheetUtil.getCellWidth(cell, 1, null, true) > 0);
+ }
}
@Test
public void testGetCellWidthBoolean() throws IOException {
- Workbook wb = new HSSFWorkbook();
- Sheet sheet = wb.createSheet("sheet");
- Row row = sheet.createRow(0);
- Cell cell = row.createCell(0);
-
- cell.setCellValue(false);
-
- assertTrue(SheetUtil.getCellWidth(cell, 1, null, false) > 0);
-
- wb.close();
+ try (Workbook wb = new HSSFWorkbook()) {
+ Sheet sheet = wb.createSheet("sheet");
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+
+ cell.setCellValue(false);
+
+ assertTrue(SheetUtil.getCellWidth(cell, 1, null, false) > 0);
+ }
}
@Test
public void testGetColumnWidthString() throws IOException {
- Workbook wb = new HSSFWorkbook();
- Sheet sheet = wb.createSheet("sheet");
- Row row = sheet.createRow(0);
- sheet.createRow(1);
- sheet.createRow(2);
- Cell cell = row.createCell(0);
-
- cell.setCellValue("sometext");
-
- assertTrue("Having some width for rows with actual cells",
- SheetUtil.getColumnWidth(sheet, 0, true) > 0);
- assertEquals("Not having any widht for rows with all empty cells",
- -1.0, SheetUtil.getColumnWidth(sheet, 0, true, 1, 2), 0.01);
-
- wb.close();
+ try (Workbook wb = new HSSFWorkbook()) {
+ Sheet sheet = wb.createSheet("sheet");
+ Row row = sheet.createRow(0);
+ sheet.createRow(1);
+ sheet.createRow(2);
+ Cell cell = row.createCell(0);
+
+ cell.setCellValue("sometext");
+
+ assertTrue(SheetUtil.getColumnWidth(sheet, 0, true) > 0, "Having some width for rows with actual cells");
+ assertEquals(-1.0, SheetUtil.getColumnWidth(sheet, 0, true, 1, 2), 0.01, "Not having any widht for rows with all empty cells");
+ }
}
}
diff --git a/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java b/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java
index 30c080e40b..aa9b37ecac 100644
--- a/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java
+++ b/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java
@@ -17,9 +17,9 @@
package org.apache.poi.ss.util;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests WorkbookUtil.
diff --git a/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java b/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java
index c553d0cc60..1a84d13e0f 100644
--- a/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java
+++ b/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java
@@ -16,7 +16,7 @@
==================================================================== */
package org.apache.poi.ss.util.cellwalk;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Date;
@@ -25,7 +25,7 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.SheetBuilder;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestCellWalk {