aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
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
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')
-rw-r--r--src/testcases/org/apache/poi/AllPOITests.java40
-rw-r--r--src/testcases/org/apache/poi/POITestCase.java32
-rw-r--r--src/testcases/org/apache/poi/TestJDK12.java2
-rw-r--r--src/testcases/org/apache/poi/TestPOIDocumentMain.java22
-rw-r--r--src/testcases/org/apache/poi/TestPOITestCase.java4
-rw-r--r--src/testcases/org/apache/poi/ddf/AllPOIDDFTests.java42
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java8
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java10
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java4
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java4
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java4
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java6
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java12
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java4
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java4
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherDump.java12
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java6
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherProperty.java10
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java4
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java4
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java4
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java4
-rw-r--r--src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java16
-rw-r--r--src/testcases/org/apache/poi/hpsf/TestVariantSupport.java24
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/AllPOIHPSFBasicTests.java37
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestBasic.java12
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestClassID.java15
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java12
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java8
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java160
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java47
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java10
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestWrite.java51
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java44
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/Util.java59
-rw-r--r--src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/HSSFTests.java48
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java40
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestReSave.java12
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java25
-rw-r--r--src/testcases/org/apache/poi/hssf/eventusermodel/AllEventUserModelTests.java34
-rw-r--r--src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java13
-rw-r--r--src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java36
-rw-r--r--src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java25
-rw-r--r--src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java7
-rw-r--r--src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java60
-rw-r--r--src/testcases/org/apache/poi/hssf/model/AllModelTests.java41
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java288
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestDrawingManager2.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java52
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestEscherRecordFactory.java53
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java288
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java40
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java16
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestLinkTable.java14
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java18
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestRVA.java64
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java18
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestSheet.java126
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestWorkbook.java20
-rw-r--r--src/testcases/org/apache/poi/hssf/record/AllRecordTests.java96
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestArrayRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java15
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java20
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java21
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java30
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestExtSSTRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java14
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java12
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestFontRecord.java12
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java28
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestInterfaceEndRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestLabelRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestLbsDataSubRecord.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java18
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestNameCommentRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestNameRecord.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java12
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestObjRecord.java16
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestPLVRecord.java2
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestPaletteRecord.java12
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestPaneRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestRecalcIdRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java38
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestRecordFactoryInputStream.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestRecordInputStream.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSCLRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java14
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java16
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java12
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestStringRecord.java16
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSubRecord.java16
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestTableRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java37
-rw-r--r--src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java40
-rw-r--r--src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java19
-rw-r--r--src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java9
-rw-r--r--src/testcases/org/apache/poi/hssf/record/aggregates/TestPageSettingsBlock.java16
-rw-r--r--src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java22
-rw-r--r--src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java22
-rw-r--r--src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java22
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/AllChartRecordTests.java66
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestAreaFormatRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestAreaRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestAxisLineFormatRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestAxisParentRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestAxisRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestAxisUsedRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestBarRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestCategorySeriesAxisRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestChartRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestChartTitleFormatRecord.java21
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestDatRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestDataFormatRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestDefaultDataLabelTextPropertiesRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestFontBasisRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestFontIndexRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestFrameRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestLegendRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestLineFormatRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestNumberFormatIndexRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestPlotAreaRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestPlotGrowthRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestSeriesChartGroupIndexRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestSeriesLabelsRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestSeriesListRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestSeriesRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java12
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestTextRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestUnitsRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/chart/TestValueRangeRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.java33
-rw-r--r--src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java76
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/SanityChecker.java246
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java57
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java38
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java27
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestCryptoAPI.java5
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java17
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestEmbeddedObjects.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java22
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java24
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestExternalReferenceChange.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java63
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java75
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java98
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java38
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java20
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java50
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java37
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java38
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java24
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFont.java2
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java493
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java16
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java14
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java60
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java50
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java92
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java18
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRangeCopier.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java32
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java118
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetShiftColumns.java54
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java19
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java227
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java102
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java18
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java64
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestPatriarch.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java24
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java45
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestSanityChecker.java21
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java18
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestText.java14
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java109
-rw-r--r--src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java34
-rw-r--r--src/testcases/org/apache/poi/hssf/util/TestAreaReference.java58
-rw-r--r--src/testcases/org/apache/poi/hssf/util/TestCellReference.java32
-rw-r--r--src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java14
-rw-r--r--src/testcases/org/apache/poi/hssf/util/TestRKUtil.java4
-rw-r--r--src/testcases/org/apache/poi/poifs/AllPOIFSTests.java42
-rw-r--r--src/testcases/org/apache/poi/poifs/crypt/AllEncryptionTests.java33
-rw-r--r--src/testcases/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java14
-rw-r--r--src/testcases/org/apache/poi/poifs/crypt/TestCipherAlgorithm.java27
-rw-r--r--src/testcases/org/apache/poi/poifs/crypt/TestXorEncryption.java8
-rw-r--r--src/testcases/org/apache/poi/poifs/crypt/binaryrc4/TestBinaryRC4.java24
-rw-r--r--src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java89
-rw-r--r--src/testcases/org/apache/poi/poifs/eventfilesystem/TestPOIFSReaderRegistry.java8
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/AllPOIFSFileSystemTests.java42
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java28
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestDocument.java10
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java10
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java159
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java26
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java40
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java80
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestFileMagic.java27
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java10
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestFilteringDirectoryNode.java302
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java24
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java12
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java8
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java37
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java39
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSMiniStore.java883
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSStream.java5455
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java8
-rw-r--r--src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java36
-rw-r--r--src/testcases/org/apache/poi/poifs/nio/TestDataSource.java77
-rw-r--r--src/testcases/org/apache/poi/poifs/property/AllPOIFSPropertyTests.java35
-rw-r--r--src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java52
-rw-r--r--src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java17
-rw-r--r--src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java24
-rw-r--r--src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java16
-rw-r--r--src/testcases/org/apache/poi/poifs/property/TestRootProperty.java14
-rw-r--r--src/testcases/org/apache/poi/poifs/storage/AllPOIFSStorageTests.java31
-rw-r--r--src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java8
-rw-r--r--src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java23
-rw-r--r--src/testcases/org/apache/poi/sl/draw/geom/TestFormulaParser.java4
-rw-r--r--src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java12
-rw-r--r--src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java14
-rw-r--r--src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java43
-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
-rw-r--r--src/testcases/org/apache/poi/util/AllPOIUtilTests.java43
-rw-r--r--src/testcases/org/apache/poi/util/MemoryLeakVerifier.java7
-rw-r--r--src/testcases/org/apache/poi/util/TestArrayUtil.java22
-rw-r--r--src/testcases/org/apache/poi/util/TestBitField.java8
-rw-r--r--src/testcases/org/apache/poi/util/TestByteField.java18
-rw-r--r--src/testcases/org/apache/poi/util/TestHexDump.java82
-rw-r--r--src/testcases/org/apache/poi/util/TestIOUtils.java113
-rw-r--r--src/testcases/org/apache/poi/util/TestIntList.java287
-rw-r--r--src/testcases/org/apache/poi/util/TestIntegerField.java82
-rw-r--r--src/testcases/org/apache/poi/util/TestLittleEndian.java54
-rw-r--r--src/testcases/org/apache/poi/util/TestLittleEndianStreams.java16
-rw-r--r--src/testcases/org/apache/poi/util/TestLocaleUtil.java20
-rw-r--r--src/testcases/org/apache/poi/util/TestLongField.java96
-rw-r--r--src/testcases/org/apache/poi/util/TestPOILogFactory.java2
-rw-r--r--src/testcases/org/apache/poi/util/TestPOILogger.java20
-rw-r--r--src/testcases/org/apache/poi/util/TestRLEDecompressingInputStream.java54
-rw-r--r--src/testcases/org/apache/poi/util/TestShortField.java72
-rw-r--r--src/testcases/org/apache/poi/util/TestStringCodepointsIterable.java9
-rw-r--r--src/testcases/org/apache/poi/util/TestStringUtil.java113
-rw-r--r--src/testcases/org/apache/poi/util/TestTempFile.java60
-rw-r--r--src/testcases/org/apache/poi/util/TestXMLHelper.java18
511 files changed, 9713 insertions, 12719 deletions
diff --git a/src/testcases/org/apache/poi/AllPOITests.java b/src/testcases/org/apache/poi/AllPOITests.java
deleted file mode 100644
index 40454c0473..0000000000
--- a/src/testcases/org/apache/poi/AllPOITests.java
+++ /dev/null
@@ -1,40 +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;
-
-import org.apache.poi.ddf.AllPOIDDFTests;
-import org.apache.poi.hpsf.basic.AllPOIHPSFBasicTests;
-import org.apache.poi.hssf.HSSFTests;
-import org.apache.poi.poifs.AllPOIFSTests;
-import org.apache.poi.util.AllPOIUtilTests;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-/**
- * Root Test Suite for entire POI project. (Includes all sub-packages of org.apache.poi)<br>
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestPOIDocumentMain.class,
- AllPOIDDFTests.class,
- AllPOIHPSFBasicTests.class,
- HSSFTests.class,
- AllPOIFSTests.class,
- AllPOIUtilTests.class
-})
-public final class AllPOITests {
-}
diff --git a/src/testcases/org/apache/poi/POITestCase.java b/src/testcases/org/apache/poi/POITestCase.java
index 7907012cfb..5dac0dc90f 100644
--- a/src/testcases/org/apache/poi/POITestCase.java
+++ b/src/testcases/org/apache/poi/POITestCase.java
@@ -23,10 +23,10 @@ import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeNoException;
+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 static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.lang.reflect.Field;
import java.security.AccessController;
@@ -84,9 +84,7 @@ public final class POITestCase {
assertNotNull(needle);
String hay = haystack.toLowerCase(locale);
String n = needle.toLowerCase(locale);
- assertTrue("Unable to find expected text '" + needle + "' in text:\n" + haystack,
- hay.contains(n)
- );
+ assertTrue(hay.contains(n), "Unable to find expected text '" + needle + "' in text:\n" + haystack);
}
public static void assertContainsIgnoreCase(String haystack, String needle) {
assertContainsIgnoreCase(haystack, needle, Locale.ROOT);
@@ -103,17 +101,11 @@ public final class POITestCase {
* @param key needle
*/
public static <T> void assertContains(Map<T, ?> map, T key) {
- if (map.containsKey(key)) {
- return;
- }
- fail("Unable to find " + key + " in " + map);
+ assertTrue(map.containsKey(key), "Unable to find " + key + " in " + map);
}
public static <T> void assertNotContained(Set<T> set, T element) {
- assertThat(set, not(hasItem(element)));
- /*if (set.contains(element)) {
- fail("Set should not contain " + element);
- }*/
+ assertThat("Set should not contain " + element, set, not(hasItem(element)));
}
/**
@@ -123,7 +115,7 @@ public final class POITestCase {
@SuppressWarnings({"unused", "unchecked"})
@SuppressForbidden("For test usage only")
public static <R,T> R getFieldValue(final Class<? super T> clazz, final T instance, final Class<R> fieldType, final String fieldName) {
- assertTrue("Reflection of private fields is only allowed for POI classes.", clazz.getName().startsWith("org.apache.poi."));
+ assertTrue(clazz.getName().startsWith("org.apache.poi."), "Reflection of private fields is only allowed for POI classes.");
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<R>) () -> {
Field f = clazz.getDeclaredField(fieldName);
@@ -193,7 +185,7 @@ public final class POITestCase {
* be raised when the bug is fixed
*/
public static void skipTest(Throwable e) {
- assumeNoException("This test currently fails with", e);
+ assumeTrue(e != null, "This test currently fails with");
}
/**
* @see #skipTest(Throwable)
@@ -205,9 +197,7 @@ public final class POITestCase {
}
public static void assertBetween(String message, int value, int min, int max) {
- assertTrue(message + ": " + value + " is less than the minimum value of " + min,
- min <= value);
- assertTrue(message + ": " + value + " is greater than the maximum value of " + max,
- value <= max);
+ assertTrue(min <= value, message + ": " + value + " is less than the minimum value of " + min);
+ assertTrue(value <= max, message + ": " + value + " is greater than the maximum value of " + max);
}
}
diff --git a/src/testcases/org/apache/poi/TestJDK12.java b/src/testcases/org/apache/poi/TestJDK12.java
index dfac092f04..d2736ed1a0 100644
--- a/src/testcases/org/apache/poi/TestJDK12.java
+++ b/src/testcases/org/apache/poi/TestJDK12.java
@@ -23,7 +23,7 @@ import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import java.text.AttributedString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Minimal Test-Class found when running the Apache POI regression tests.
diff --git a/src/testcases/org/apache/poi/TestPOIDocumentMain.java b/src/testcases/org/apache/poi/TestPOIDocumentMain.java
index 8717d4c291..fc57f8eae5 100644
--- a/src/testcases/org/apache/poi/TestPOIDocumentMain.java
+++ b/src/testcases/org/apache/poi/TestPOIDocumentMain.java
@@ -17,9 +17,9 @@
package org.apache.poi;
-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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -31,8 +31,8 @@ import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests that POIDocument correctly loads and saves the common
@@ -49,7 +49,7 @@ public final class TestPOIDocumentMain {
/**
* Set things up, two spreadsheets for our testing
*/
- @Before
+ @BeforeEach
public void setUp() {
doc = HSSFTestDataSamples.openSampleWorkbook("DateFormats.xls");
doc2 = HSSFTestDataSamples.openSampleWorkbook("StringFormulas.xls");
@@ -114,7 +114,7 @@ public final class TestPOIDocumentMain {
// Check they're still there
POIDocument doc3 = new HPSFPropertiesOnlyDocument(inFS);
doc3.readProperties();
-
+
// Delegate test
readPropertiesHelper(doc3);
doc3.close();
@@ -144,7 +144,7 @@ public final class TestPOIDocumentMain {
assertNotNull(doc.getSummaryInformation());
assertNotNull(doc.getDocumentSummaryInformation());
-
+
doc.close();
}
@@ -159,9 +159,9 @@ public final class TestPOIDocumentMain {
// Write out and back in again, no change
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.write(baos);
-
+
doc.close();
-
+
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
doc = new HSSFWorkbook(bais);
@@ -176,7 +176,7 @@ public final class TestPOIDocumentMain {
// Save and re-load
baos = new ByteArrayOutputStream();
doc.write(baos);
-
+
doc.close();
bais = new ByteArrayInputStream(baos.toByteArray());
diff --git a/src/testcases/org/apache/poi/TestPOITestCase.java b/src/testcases/org/apache/poi/TestPOITestCase.java
index 60f5fb9cb7..f1b695611a 100644
--- a/src/testcases/org/apache/poi/TestPOITestCase.java
+++ b/src/testcases/org/apache/poi/TestPOITestCase.java
@@ -17,7 +17,7 @@
package org.apache.poi;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import java.util.Collections;
@@ -26,7 +26,7 @@ import java.util.Map;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.property.PropertyTable;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* A class for testing the POI Junit TestCase utility class
diff --git a/src/testcases/org/apache/poi/ddf/AllPOIDDFTests.java b/src/testcases/org/apache/poi/ddf/AllPOIDDFTests.java
deleted file mode 100644
index 2088e9760e..0000000000
--- a/src/testcases/org/apache/poi/ddf/AllPOIDDFTests.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.ddf;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestEscherBSERecord.class,
- TestEscherBlipRecord.class,
- TestEscherBoolProperty.class,
- TestEscherChildAnchorRecord.class,
- TestEscherClientAnchorRecord.class,
- TestEscherClientDataRecord.class,
- TestEscherContainerRecord.class,
- TestEscherDgRecord.class,
- TestEscherDggRecord.class,
- TestEscherOptRecord.class,
- TestEscherPropertyFactory.class,
- TestEscherSpRecord.class,
- TestEscherSpgrRecord.class,
- TestEscherSplitMenuColorsRecord.class,
- TestUnknownEscherRecord.class
-})
-public final class AllPOIDDFTests {
-}
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java b/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java
index 184486b3bd..82d573df18 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java
@@ -17,8 +17,8 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
@@ -26,7 +26,7 @@ import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestEscherBSERecord {
@Test
@@ -56,7 +56,7 @@ public final class TestEscherBSERecord {
EscherBSERecord r = createRecord();
String exp64 = "H4sIAAAAAAAAAGNkYP+gwsDAwMrKyMTMwsrGzsHJxc3Dy8fPwMgAAkxAzAzEICkAgs9OoSwAAAA=";
byte[] expected = RawDataUtil.decompress(exp64);
-
+
byte[] data = new byte[8 + 36];
int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() );
assertEquals(data.length, bytesWritten);
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java
index 818a5cb97b..d1644f052e 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java
@@ -17,14 +17,14 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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 org.apache.poi.POIDataSamples;
import org.apache.poi.sl.usermodel.PictureData;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test read/serialize of escher blip records
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java b/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java
index 96083e4d84..4f34ab1fb8 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java
@@ -17,9 +17,9 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestEscherBoolProperty {
@Test
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java
index 457accfa4d..c6d67052be 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java
@@ -17,11 +17,11 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestEscherChildAnchorRecord {
@Test
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java
index 5077118286..1cca9dd476 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java
@@ -17,11 +17,11 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestEscherClientAnchorRecord {
@Test
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java
index 3c0285931e..e10a86ef84 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java
@@ -14,14 +14,14 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.ddf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestEscherClientDataRecord {
@Test
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java
index 2f77f6c28f..832e66afd9 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java
@@ -17,18 +17,18 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
+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.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link EscherContainerRecord}
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java
index c3d07958ed..8de2256f58 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java
@@ -17,11 +17,11 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestEscherDgRecord {
@Test
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java
index d06979dab9..8666fd5693 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java
@@ -17,11 +17,11 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestEscherDggRecord {
@Test
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherDump.java b/src/testcases/org/apache/poi/ddf/TestEscherDump.java
index b18a7cc790..d53bb9496c 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherDump.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherDump.java
@@ -17,9 +17,9 @@
package org.apache.poi.ddf;
-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.ByteArrayOutputStream;
import java.io.InputStream;
@@ -33,8 +33,8 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.util.IOUtils;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public class TestEscherDump {
private static final String recordData =
@@ -67,7 +67,7 @@ public class TestEscherDump {
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private PrintStream stream;
- @Before
+ @BeforeEach
public void setup() throws UnsupportedEncodingException {
stream = new PrintStream(baos, true, StandardCharsets.UTF_8.name());
}
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java
index 33af04b3ba..79fcd66ad4 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java
@@ -17,15 +17,15 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestEscherOptRecord {
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherProperty.java b/src/testcases/org/apache/poi/ddf/TestEscherProperty.java
index 62c6879f7f..a7a4774b0a 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherProperty.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherProperty.java
@@ -17,17 +17,17 @@
package org.apache.poi.ddf;
-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.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestEscherProperty {
/**
* assure that EscherProperty.getName() returns correct name for complex properties
- * See Bugzilla 50401
+ * See Bugzilla 50401
*/
@Test
public void testPropertyNames() throws Exception {
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java b/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java
index 803b3bdf01..dd64bd5e7c 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java
@@ -17,13 +17,13 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestEscherPropertyFactory {
@Test
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java
index 786cf0917b..8f1826c18c 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java
@@ -17,11 +17,11 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestEscherSpRecord {
@Test
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java
index 0e8e356ff2..54c7589b81 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java
@@ -17,11 +17,11 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestEscherSpgrRecord {
@Test
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java
index 6df9fd6122..3180b6ddaa 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java
@@ -17,11 +17,11 @@
package org.apache.poi.ddf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestEscherSplitMenuColorsRecord {
@Test
diff --git a/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java b/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java
index d354c5d887..2b7217de1c 100644
--- a/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java
+++ b/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java
@@ -17,13 +17,13 @@
package org.apache.poi.ddf;
-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.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestUnknownEscherRecord {
@Test
@@ -81,7 +81,7 @@ public final class TestUnknownEscherRecord {
assertTrue( r.isContainerRecord() );
assertEquals( 1, r.getChildRecords().size() );
assertEquals( (short) 0xFFFF, r.getChild( 0 ).getRecordId() );
-
+
//Add by Zhang Zhang test error situation when remaining bytes > avalible bytes
testData =
"00 02 " + // options
@@ -91,7 +91,7 @@ public final class TestUnknownEscherRecord {
r = new UnknownEscherRecord();
r.fillFields( HexRead.readFromString( testData ), factory );
-
+
assertEquals( 0x0200, r.getOptions() );
assertEquals( (short) 0xF111, r.getRecordId() );
assertEquals( 12, r.getRecordSize() );
@@ -102,7 +102,7 @@ public final class TestUnknownEscherRecord {
assertEquals( 2, r.getData()[1] );
assertEquals( 3, r.getData()[2] );
assertEquals( 4, r.getData()[3] );
-
+
testData =
"0F 02 " + // options
"11 F1 " + // record id
@@ -113,7 +113,7 @@ public final class TestUnknownEscherRecord {
r = new UnknownEscherRecord();
r.fillFields( HexRead.readFromString( testData ), factory );
-
+
assertEquals( 0x020F, r.getOptions() );
assertEquals( (short) 0xF111, r.getRecordId() );
assertEquals( 8, r.getRecordSize() );
diff --git a/src/testcases/org/apache/poi/hpsf/TestVariantSupport.java b/src/testcases/org/apache/poi/hpsf/TestVariantSupport.java
index 26ca734f77..6fcc2a89b4 100644
--- a/src/testcases/org/apache/poi/hpsf/TestVariantSupport.java
+++ b/src/testcases/org/apache/poi/hpsf/TestVariantSupport.java
@@ -18,19 +18,19 @@
*/
package org.apache.poi.hpsf;
-import static org.junit.Assert.*;
-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.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.math.BigInteger;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestVariantSupport {
@Test
@@ -52,10 +52,10 @@ public class TestVariantSupport {
Object hdrs = s.getProperty(PropertyIDMap.PID_HEADINGPAIR);
assertNotNull(hdrs);
assertEquals(byte[].class, hdrs.getClass());
-
+
// parse the value
Vector v = new Vector((short)Variant.VT_VARIANT);
- LittleEndianByteArrayInputStream lei = new LittleEndianByteArrayInputStream((byte[])hdrs, 0);
+ LittleEndianByteArrayInputStream lei = new LittleEndianByteArrayInputStream((byte[])hdrs, 0);
v.read(lei);
TypedPropertyValue[] items = v.getValues();
@@ -70,7 +70,7 @@ public class TestVariantSupport {
assertEquals(1, i);
}
-
+
@Test
public void newNumberTypes() throws Exception {
ClipboardData cd = new ClipboardData();
@@ -90,8 +90,7 @@ public class TestVariantSupport {
{Variant.VT_R4, -999.99f},
{Variant.VT_R8, -999.99d},
};
-
- HSSFWorkbook wb = new HSSFWorkbook();
+
POIFSFileSystem poifs = new POIFSFileSystem();
DocumentSummaryInformation dsi = PropertySetFactory.newDocumentSummaryInformation();
CustomProperties cpList = new CustomProperties();
@@ -99,7 +98,7 @@ public class TestVariantSupport {
int type = (Integer)o[0];
Property p = new Property(PropertyIDMap.PID_MAX+type, type, o[1]);
cpList.put("testprop"+type, new CustomProperty(p, "testprop"+type));
-
+
}
dsi.setCustomProperties(cpList);
dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
@@ -108,14 +107,15 @@ public class TestVariantSupport {
poifs.close();
poifs = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
dsi = (DocumentSummaryInformation)PropertySetFactory.create(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+ assertNotNull(dsi);
cpList = dsi.getCustomProperties();
int i=0;
for (Object[] o : exp) {
Object obj = cpList.get("testprop"+o[0]);
if (o[1] instanceof byte[]) {
- assertArrayEquals("property "+i, (byte[])o[1], (byte[])obj);
+ assertArrayEquals((byte[])o[1], (byte[])obj, "property "+i);
} else {
- assertEquals("property "+i, o[1], obj);
+ assertEquals(o[1], obj, "property "+i);
}
i++;
}
diff --git a/src/testcases/org/apache/poi/hpsf/basic/AllPOIHPSFBasicTests.java b/src/testcases/org/apache/poi/hpsf/basic/AllPOIHPSFBasicTests.java
deleted file mode 100644
index dbb56451ac..0000000000
--- a/src/testcases/org/apache/poi/hpsf/basic/AllPOIHPSFBasicTests.java
+++ /dev/null
@@ -1,37 +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.hpsf.basic;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-/**
- * Test suite for org.apache.poi.hpsf.basic
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestBasic.class,
- TestClassID.class,
- TestEmptyProperties.class,
- TestHPSFBugs.class,
- TestMetaDataIPI.class,
- TestUnicode.class,
- TestWrite.class,
- TestWriteWellKnown.class
-})
-public class AllPOIHPSFBasicTests {
-}
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
index 13cce30251..dfccfdc235 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
@@ -17,9 +17,9 @@
package org.apache.poi.hpsf.basic;
-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.ByteArrayInputStream;
import java.io.File;
@@ -42,8 +42,8 @@ import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.Section;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* <p>Tests the basic HPSF functionality.</p>
@@ -76,7 +76,7 @@ public final class TestBasic {
* @exception FileNotFoundException if the file to be read does not exist.
* @exception IOException if any other I/O exception occurs.
*/
- @Before
+ @BeforeEach
public void setUp() throws IOException {
final File data = samples.getFile("TestGermanWord90.doc");
poiFiles = Util.readPOIFiles(data);
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java b/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java
index 7be9bbf3f7..5ded0baa1d 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java
@@ -17,14 +17,15 @@
package org.apache.poi.hpsf.basic;
-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 static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Locale;
import org.apache.poi.hpsf.ClassID;
import org.apache.poi.hpsf.ClassIDPredefined;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests ClassID structure.
@@ -52,14 +53,14 @@ public final class TestClassID {
* Try to write to a buffer that is too small. This should
* throw an Exception
*/
- @Test(expected = ArrayStoreException.class)
+ @Test
public void testWriteArrayStoreException1() {
- new ClassID(BUF16, 0).write(new byte[15], 0);
+ assertThrows(ArrayStoreException.class, () -> new ClassID(BUF16, 0).write(new byte[15], 0));
}
- @Test(expected = ArrayIndexOutOfBoundsException.class)
+ @Test
public void testWriteArrayStoreException2() {
- new ClassID(BUF16, 0).write(new byte[16], 1);
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new ClassID(BUF16, 0).write(new byte[16], 1));
}
@Test
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java b/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java
index bdc7c5b6de..dd1bf74e0b 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java
@@ -17,9 +17,9 @@
package org.apache.poi.hpsf.basic;
-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.ByteArrayInputStream;
import java.io.File;
@@ -38,8 +38,8 @@ import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.Variant;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Test case for OLE2 files with empty properties.
@@ -69,7 +69,7 @@ public final class TestEmptyProperties {
* does not exist
* @exception IOException if an I/O exception occurs
*/
- @Before
+ @BeforeEach
public void setUp() throws IOException {
final File data = samples.getFile(POI_FS);
poiFiles = Util.readPOIFiles(data);
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java b/src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java
index c5d4937239..a8cbbbbd95 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java
@@ -17,9 +17,9 @@
package org.apache.poi.hpsf.basic;
-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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -38,7 +38,7 @@ import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests various bugs have been fixed
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java b/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
index 9347699566..f3f0d35cd3 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
@@ -17,12 +17,11 @@
package org.apache.poi.hpsf.basic;
-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.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -38,9 +37,10 @@ import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-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;
+
/**
* Basing on: src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java
* This class tests reading and writing of meta data. No actual document is created. All information
@@ -52,7 +52,7 @@ public final class TestMetaDataIPI {
private DocumentSummaryInformation dsi;
private SummaryInformation si;
- @After
+ @AfterEach
public void tearDown() throws Exception {
poifs.close();
}
@@ -61,7 +61,7 @@ public final class TestMetaDataIPI {
* Setup is used to get the document ready. Gets the DocumentSummaryInformation and the
* SummaryInformation to reasonable values
*/
- @Before
+ @BeforeEach
public void setUp() throws Exception {
poifs = new POIFSFileSystem();
dsi = PropertySetFactory.newDocumentSummaryInformation();
@@ -113,15 +113,15 @@ public final class TestMetaDataIPI {
assertNotNull(dsi);
assertNotNull(si);
- assertEquals("Category", "xxxCategoryxxx", dsi.getCategory());
- assertEquals("Company", "xxxCompanyxxx", dsi.getCompany());
- assertEquals("Manager", "xxxManagerxxx", dsi.getManager());
+ assertEquals("xxxCategoryxxx", dsi.getCategory(), "Category");
+ assertEquals("xxxCompanyxxx", dsi.getCompany(), "Company");
+ assertEquals("xxxManagerxxx", dsi.getManager(), "Manager");
- assertEquals("", "xxxAuthorxxx", si.getAuthor());
- assertEquals("", "xxxTitlexxx", si.getTitle());
- assertEquals("", "xxxCommentsxxx", si.getComments());
- assertEquals("", "xxxKeyWordsxxx", si.getKeywords());
- assertEquals("", "xxxSubjectxxx", si.getSubject());
+ assertEquals("xxxAuthorxxx", si.getAuthor());
+ assertEquals("xxxTitlexxx", si.getTitle());
+ assertEquals("xxxCommentsxxx", si.getComments());
+ assertEquals("xxxKeyWordsxxx", si.getKeywords());
+ assertEquals("xxxSubjectxxx", si.getSubject());
/*
* Read the custom properties. If there are no custom properties yet,
@@ -133,21 +133,21 @@ public final class TestMetaDataIPI {
/* Insert some custom properties into the container. */
String a1 = (String) customProperties.get("Key1");
- assertEquals("Key1", "Value1", a1);
+ assertEquals("Value1", a1, "Key1");
String a2 = (String) customProperties.get("Schl\u00fcssel2");
- assertEquals("Schl\u00fcssel2", "Wert2", a2);
+ assertEquals("Wert2", a2, "Schl\u00fcssel2");
Integer a3 = (Integer) customProperties.get("Sample Integer");
- assertEquals("Sample Number", 12345, (int)a3);
+ assertEquals(12345, (int)a3, "Sample Number");
Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
- assertTrue("Sample Boolean", a4);
+ assertTrue(a4, "Sample Boolean");
Date a5 = (Date) customProperties.get("Sample Date");
- assertEquals("Custom Date:", date, a5);
+ assertEquals(date, a5, "Custom Date:");
Double a6 = (Double) customProperties.get("Sample Double");
- assertEquals("Custom Float", -1.0001, a6, 0);
+ assertEquals(-1.0001, a6, 0, "Custom Float");
Integer a7 = (Integer) customProperties.get("Sample Negative Integer");
- assertEquals("Neg", -100000, (int)a7);
+ assertEquals(-100000, (int)a7, "Neg");
}
/**
@@ -201,15 +201,15 @@ public final class TestMetaDataIPI {
* Change the category to "POI example". Any former category value will
* be lost. If there has been no category yet, it will be created.
*/
- assertEquals("Category", category, dsi.getCategory());
- assertEquals("Company", company, dsi.getCompany());
- assertEquals("Manager", manager, dsi.getManager());
+ assertEquals(category, dsi.getCategory(), "Category");
+ assertEquals(company, dsi.getCompany(), "Company");
+ assertEquals(manager, dsi.getManager(), "Manager");
- assertEquals("", author, si.getAuthor());
- assertEquals("", title, si.getTitle());
- assertEquals("", comments, si.getComments());
- assertEquals("", keywords, si.getKeywords());
- assertEquals("", subject, si.getSubject());
+ assertEquals(author, si.getAuthor());
+ assertEquals(title, si.getTitle());
+ assertEquals(comments, si.getComments());
+ assertEquals(keywords, si.getKeywords());
+ assertEquals(subject, si.getSubject());
/*
* Read the custom properties. If there are no custom properties yet,
@@ -217,21 +217,19 @@ public final class TestMetaDataIPI {
* serve as a container for custom properties.
*/
customProperties = dsi.getCustomProperties();
- if (customProperties == null) {
- fail();
- }
+ assertNotNull(customProperties);
/* Insert some custom properties into the container. */
String a1 = (String) customProperties.get(k1);
- assertEquals("Key1", p1, a1);
+ assertEquals(p1, a1, "Key1");
String a2 = (String) customProperties.get(k2);
- assertEquals("Schl\u00fcssel2", p2, a2);
+ assertEquals(p2, a2, "Schl\u00fcssel2");
Integer a3 = (Integer) customProperties.get("Sample Number");
- assertEquals("Sample Number", 12345, (int)a3);
+ assertEquals(12345, (int)a3, "Sample Number");
Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
- assertTrue("Sample Boolean", a4);
+ assertTrue(a4, "Sample Boolean");
Date a5 = (Date) customProperties.get("Sample Date");
- assertEquals("Custom Date:", date, a5);
+ assertEquals(date, a5, "Custom Date:");
}
@@ -287,15 +285,15 @@ public final class TestMetaDataIPI {
* Change the category to "POI example". Any former category value will
* be lost. If there has been no category yet, it will be created.
*/
- assertEquals("Category", category, dsi.getCategory());
- assertEquals("Company", company, dsi.getCompany());
- assertEquals("Manager", manager, dsi.getManager());
+ assertEquals(category, dsi.getCategory(), "Category");
+ assertEquals(company, dsi.getCompany(), "Company");
+ assertEquals(manager, dsi.getManager(), "Manager");
- assertEquals("", author, si.getAuthor());
- assertEquals("", title, si.getTitle());
- assertEquals("", comments, si.getComments());
- assertEquals("", keywords, si.getKeywords());
- assertEquals("", subject, si.getSubject());
+ assertEquals(author, si.getAuthor());
+ assertEquals(title, si.getTitle());
+ assertEquals(comments, si.getComments());
+ assertEquals(keywords, si.getKeywords());
+ assertEquals(subject, si.getSubject());
/*
* Read the custom properties. If there are no custom properties yet,
@@ -303,22 +301,20 @@ public final class TestMetaDataIPI {
* serve as a container for custom properties.
*/
customProperties = dsi.getCustomProperties();
- if (customProperties == null) {
- fail();
- }
+ assertNotNull(customProperties);
/* Insert some custom properties into the container. */
// System.out.println(k1);
String a1 = (String) customProperties.get(k1);
- assertEquals("Key1", p1, a1);
+ assertEquals(p1, a1, "Key1");
String a2 = (String) customProperties.get(k2);
- assertEquals("Schl\u00fcssel2", p2, a2);
+ assertEquals(p2, a2, "Schl\u00fcssel2");
Integer a3 = (Integer) customProperties.get("Sample Number");
- assertEquals("Sample Number", 12345, (int)a3);
+ assertEquals(12345, (int)a3, "Sample Number");
Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
- assertFalse("Sample Boolean", a4);
+ assertFalse(a4, "Sample Boolean");
Date a5 = (Date) customProperties.get("Sample Date");
- assertEquals("Custom Date:", date, a5);
+ assertEquals(date, a5, "Custom Date:");
}
@@ -380,15 +376,15 @@ public final class TestMetaDataIPI {
* Change the category to "POI example". Any former category value will
* be lost. If there has been no category yet, it will be created.
*/
- assertEquals("Category", category, dsi.getCategory());
- assertEquals("Company", company, dsi.getCompany());
- assertEquals("Manager", manager, dsi.getManager());
+ assertEquals(category, dsi.getCategory(), "Category");
+ assertEquals(company, dsi.getCompany(), "Company");
+ assertEquals(manager, dsi.getManager(), "Manager");
- assertEquals("", author, si.getAuthor());
- assertEquals("", title, si.getTitle());
- assertEquals("", comments, si.getComments());
- assertEquals("", keywords, si.getKeywords());
- assertEquals("", subject, si.getSubject());
+ assertEquals(author, si.getAuthor());
+ assertEquals(title, si.getTitle());
+ assertEquals(comments, si.getComments());
+ assertEquals(keywords, si.getKeywords());
+ assertEquals(subject, si.getSubject());
/*
* Read the custom properties. If there are no custom properties yet,
@@ -401,15 +397,15 @@ public final class TestMetaDataIPI {
/* Insert some custom properties into the container. */
// System.out.println(k1);
String a1 = (String) customProperties.get(k1);
- assertEquals("Key1", p1, a1);
+ assertEquals(p1, a1, "Key1");
String a2 = (String) customProperties.get(k2);
- assertEquals("Schl\u00fcssel2", p2, a2);
+ assertEquals(p2, a2, "Schl\u00fcssel2");
Integer a3 = (Integer) customProperties.get("Sample Number");
- assertEquals("Sample Number", 12345, (int)a3);
+ assertEquals(12345, (int)a3, "Sample Number");
Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
- assertTrue("Sample Boolean", a4);
+ assertTrue(a4, "Sample Boolean");
Date a5 = (Date) customProperties.get("Sample Date");
- assertEquals("Custom Date:", date, a5);
+ assertEquals(date, a5, "Custom Date:");
}
@@ -479,38 +475,36 @@ public final class TestMetaDataIPI {
* serve as a container for custom properties.
*/
customProperties = dsi.getCustomProperties();
- if (customProperties == null) {
- fail();
- }
+ assertNotNull(customProperties);
/* Insert some custom properties into the container. */
Integer a3 = (Integer) customProperties.get("int");
- assertEquals("int", 12345, (int)a3);
+ assertEquals(12345, (int)a3, "int");
a3 = (Integer) customProperties.get("negint");
- assertEquals("negint", -12345, (int)a3);
+ assertEquals(-12345, (int)a3, "negint");
Long al = (Long) customProperties.get("neglong");
- assertEquals("neglong", -12345L, (long)al);
+ assertEquals(-12345L, (long)al, "neglong");
al = (Long) customProperties.get("long");
- assertEquals("long", 12345L, (long)al);
+ assertEquals(12345L, (long)al, "long");
Boolean a4 = (Boolean) customProperties.get("boolean");
- assertTrue("boolean", a4);
+ assertTrue(a4, "boolean");
Date a5 = (Date) customProperties.get("date");
- assertEquals("Custom Date:", date, a5);
+ assertEquals(date, a5, "Custom Date:");
Double d = (Double) customProperties.get("double");
- assertEquals("int", 12345.2, d, 0);
+ assertEquals(12345.2, d, 0, "int");
d = (Double) customProperties.get("negdouble");
- assertEquals("string", -12345.3, d, 0);
+ assertEquals(-12345.3, d, 0, "string");
String s = (String) customProperties.get("string");
- assertEquals("sring", "a String", s);
+ assertEquals("a String", s, "string");
assertTrue(customProperties.get("string") instanceof String);
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java b/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java
index 4b6884165a..cc40ccd3d1 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java
@@ -17,8 +17,8 @@
package org.apache.poi.hpsf.basic;
-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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -29,7 +29,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
-import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hpsf.CustomProperties;
@@ -42,43 +42,35 @@ import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-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.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
/**
* Tests some HPSF functionality by reading all property sets from all files
* in the "data" directory. If you want to ensure HPSF can deal with a certain
* OLE2 file, just add it to the "data" directory and run this test case.
*/
-@RunWith(Parameterized.class)
public class TestReadAllFiles {
private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
- @Parameters(name="{index}: {0} using {1}")
- public static Iterable<Object[]> files() {
+ public static Stream<Arguments> files() {
File hpsfTestDir = _samples.getFile("");
File[] files = hpsfTestDir.listFiles(f -> true);
Objects.requireNonNull(files, "Could not find directory " + hpsfTestDir.getAbsolutePath());
// convert to list of object-arrays for @Parameterized
- return Arrays.stream(files).
- map(file1 -> new Object[] {file1}).
- collect(Collectors.toList());
+ return Arrays.stream(files).map(Arguments::of);
}
- @Parameter()
- public File file;
-
/**
* This test methods reads all property set streams from all POI
* filesystems in the "data" directory.
*/
- @Test
- public void read() throws IOException, NoPropertySetStreamException, MarkUnsupportedException {
+ @ParameterizedTest
+ @MethodSource("files")
+ public void read(File file) throws IOException, NoPropertySetStreamException, MarkUnsupportedException {
/* Read the POI filesystem's property set streams: */
for (POIFile pf : Util.readPropertySets(file)) {
try (InputStream in = new ByteArrayInputStream(pf.getBytes())) {
@@ -102,8 +94,9 @@ public class TestReadAllFiles {
* the origin file and check whether they are equal.
* </ul>
*/
- @Test
- public void recreate() throws IOException, HPSFException {
+ @ParameterizedTest
+ @MethodSource("files")
+ public void recreate(File file) throws IOException, HPSFException {
/* Read the POI filesystem's property set streams: */
Map<String,PropertySet> psMap = new HashMap<>();
@@ -135,7 +128,7 @@ public class TestReadAllFiles {
String ps1str = ps1.toString().replace(" 00", " ").replace(".", " ").replaceAll("(?m)( +$|(size|offset): [0-9]+)","");
String ps2str = ps2.toString().replace(" 00", " ").replace(".", " ").replaceAll("(?m)( +$|(size|offset): [0-9]+)","");
- assertEquals("Equality for file " + file.getName(), ps1str, ps2str);
+ assertEquals(ps1str, ps2str, "Equality for file " + file.getName());
}
poiFs.close();
}
@@ -147,8 +140,9 @@ public class TestReadAllFiles {
* the document summary information stream in the root directory and calling
* its get... methods.
*/
- @Test
- public void readDocumentSummaryInformation() throws Exception {
+ @ParameterizedTest
+ @MethodSource("files")
+ public void readDocumentSummaryInformation(File file) throws Exception {
/* Read a test document <em>doc</em> into a POI filesystem. */
try (POIFSFileSystem poifs = new POIFSFileSystem(file, true)) {
final DirectoryEntry dir = poifs.getRoot();
@@ -189,8 +183,9 @@ public class TestReadAllFiles {
*
* @throws Exception if anything goes wrong.
*/
- @Test
- public void readCustomPropertiesFromFiles() throws Exception {
+ @ParameterizedTest
+ @MethodSource("files")
+ public void readCustomPropertiesFromFiles(File file) throws Exception {
/* Read a test document <em>doc</em> into a POI filesystem. */
try (POIFSFileSystem poifs = new POIFSFileSystem(file)) {
/*
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java b/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java
index 3e3eafd495..498c9119e0 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java
@@ -17,8 +17,8 @@
package org.apache.poi.hpsf.basic;
-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.ByteArrayInputStream;
import java.io.File;
@@ -33,8 +33,8 @@ import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.Section;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.util.CodePageUtil;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests whether Unicode string can be read from a DocumentSummaryInformation.
@@ -55,7 +55,7 @@ public class TestUnicode {
* @exception FileNotFoundException if the file to be read does not exist.
* @exception IOException if any other I/O exception occurs
*/
- @Before
+ @BeforeEach
public void setUp() {
POIDataSamples samples = POIDataSamples.getHPSFInstance();
data = samples.getFile(POI_FS);
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
index 688ea0088d..b8f59dfa67 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
@@ -19,12 +19,14 @@ package org.apache.poi.hpsf.basic;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertArrayEquals;
-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.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -71,8 +73,8 @@ import org.apache.poi.util.CodePageUtil;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.TempFile;
-import org.junit.Assume;
-import org.junit.Test;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.Test;
/**
* Tests HPSF's writing functionality
@@ -120,7 +122,7 @@ public class TestWrite {
*
* @exception IOException if an I/O exception occurs
*/
- @Test(expected=NoFormatIDException.class)
+ @Test
public void withoutAFormatID() throws Exception {
final File filename = TempFile.createTempFile(POI_FS, ".doc");
@@ -134,7 +136,7 @@ public class TestWrite {
try (OutputStream out = new FileOutputStream(filename);
POIFSFileSystem poiFs = new POIFSFileSystem();
ByteArrayOutputStream psStream = new ByteArrayOutputStream()) {
- ps.write(psStream);
+ assertThrows(NoFormatIDException.class, () -> ps.write(psStream));
poiFs.createDocument(new ByteArrayInputStream(psStream.toByteArray()), SummaryInformation.DEFAULT_STREAM_NAME);
poiFs.writeFilesystem(out);
}
@@ -270,11 +272,7 @@ public class TestWrite {
final PropertySet[] psa = new PropertySet[1];
final POIFSReader r = new POIFSReader();
final POIFSReaderListener listener = (event) -> {
- try {
- psa[0] = PropertySetFactory.create(event.getStream());
- } catch (Exception ex) {
- fail(ex.getMessage());
- }
+ assertDoesNotThrow(() -> psa[0] = PropertySetFactory.create(event.getStream()));
};
r.registerListener(listener,STREAM_NAME);
@@ -291,13 +289,7 @@ public class TestWrite {
}
private static POIFSReaderListener getListener(List<PropertySet> psa) {
- return event -> {
- try {
- psa.add(PropertySetFactory.create(event.getStream()));
- } catch (Exception ex) {
- fail(ex.getMessage());
- }
- };
+ return event -> assertDoesNotThrow(() -> psa.add(PropertySetFactory.create(event.getStream())));
}
/**
@@ -307,7 +299,7 @@ public class TestWrite {
@Test
public void variantTypes() throws Exception {
final int codepage = CODEPAGE_DEFAULT;
- Assume.assumeTrue(IMPROPER_DEFAULT_CHARSET_MESSAGE, hasProperDefaultCharset());
+ Assumptions.assumeTrue(hasProperDefaultCharset(), IMPROPER_DEFAULT_CHARSET_MESSAGE);
check(Variant.VT_EMPTY, null, codepage);
check(Variant.VT_BOOL, Boolean.TRUE, codepage);
@@ -358,12 +350,9 @@ public class TestWrite {
final int[] invalidCodepages = new int[] {0, 1, 2, 4711, 815};
for (int cp : invalidCodepages) {
- try {
- checkString(Variant.VT_LPSTR, "\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df", cp);
- fail("UnsupportedEncodingException for codepage " + cp + " expected.");
- } catch (UnsupportedEncodingException ex) {
- /* This is the expected behaviour. */
- }
+ assertThrows(UnsupportedEncodingException.class,
+ () -> checkString(Variant.VT_LPSTR, "\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df", cp),
+ "UnsupportedEncodingException for codepage " + cp + " expected.");
}
}
@@ -683,7 +672,7 @@ public class TestWrite {
* Tests writing and reading back a proper dictionary with an invalid
* codepage. (HPSF writes Unicode dictionaries only.)
*/
- @Test(expected=UnsupportedEncodingException.class)
+ @Test
public void dictionaryWithInvalidCodepage() throws IOException, HPSFException {
final File copy = TempFile.createTempFile("Test-HPSF", "ole2");
copy.deleteOnExit();
@@ -703,7 +692,7 @@ public class TestWrite {
s.setFormatID(DocumentSummaryInformation.FORMAT_ID[0]);
int codepage = 12345;
s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, codepage);
- poiFs.createDocument(ps1.toInputStream(), "Test");
+ assertThrows(UnsupportedEncodingException.class, () -> poiFs.createDocument(ps1.toInputStream(), "Test"));
poiFs.writeFilesystem(out);
}
}
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
index 152e04cf88..3d3c962a82 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
@@ -17,11 +17,11 @@
package org.apache.poi.hpsf.basic;
-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.assertTrue;
import java.io.File;
import java.io.FileInputStream;
@@ -51,8 +51,8 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.TempFile;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
* <p>Tests HPSF's high-level writing functionality for the well-known property
@@ -62,7 +62,7 @@ public class TestWriteWellKnown {
private static final String POI_FS = "TestWriteWellKnown.doc";
- @BeforeClass
+ @BeforeAll
public static void setUp() {
VariantSupport.setLogUnsupportedTypes(false);
}
@@ -125,7 +125,7 @@ public class TestWriteWellKnown {
cal.set(2002, 8, 8, 8, 8, 8);
P_LAST_SAVE_DATE_TIME = cal.getTime();
}
-
+
/**
* <p>This test method test the writing of properties in the well-known
* property set streams "SummaryInformation" and
@@ -172,7 +172,7 @@ public class TestWriteWellKnown {
@Test
public void testWriteWellKnown() throws Exception {
POIDataSamples _samples = POIDataSamples.getHPSFInstance();
-
+
final File doc1 = TempFile.createTempFile("POI_HPSF_Test1.", ".tmp");
final File doc2 = TempFile.createTempFile("POI_HPSF_Test2.", ".tmp");
final File doc3 = TempFile.createTempFile("POI_HPSF_Test3.", ".tmp");
@@ -182,14 +182,14 @@ public class TestWriteWellKnown {
IOUtils.copy(fis, fos);
fos.close();
fis.close();
-
+
CustomProperties cps1 = write1stFile(doc1, doc2);
CustomProperties cps2 = write2ndFile(doc2, doc3);
write3rdFile(doc3);
-
+
assertEquals(cps1, cps2);
}
-
+
/*
* Write all properties supported by HPSF to the summary information
* (e.g. author, edit date, application name) and to the document
@@ -268,17 +268,17 @@ public class TestWriteWellKnown {
cps.put("min_Long", MIN_LONG);
cps.put("max_Double", MAX_DOUBLE);
cps.put("min_Double", MIN_DOUBLE);
-
+
// Check the keys went in
assertTrue(cps.containsKey("Schl\u00fcssel \u00e4"));
assertTrue(cps.containsKey("Boolean"));
-
+
// Check the values went in
assertEquals("Wert \u00e4", cps.get("Schl\u00fcssel \u00e4"));
assertEquals(Boolean.TRUE, cps.get("Boolean"));
assertTrue(cps.containsValue(Boolean.TRUE));
assertTrue(cps.containsValue("Wert \u00e4"));
-
+
// Check that things that aren't in aren't in
assertFalse(cps.containsKey("False Boolean"));
assertFalse(cps.containsValue(Boolean.FALSE));
@@ -286,7 +286,7 @@ public class TestWriteWellKnown {
// Save as our custom properties
dsi.setCustomProperties(cps);
-
+
/* Write the summary information stream and the document summary
* information stream to the POI filesystem. */
si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
@@ -298,10 +298,10 @@ public class TestWriteWellKnown {
poifs.writeFilesystem(out);
out.close();
poifs.close();
-
+
return cps;
}
-
+
/*
* Open <em>doc2</em> for reading and check summary information and
* document summary information. All properties written before must be
@@ -419,10 +419,10 @@ public class TestWriteWellKnown {
poifs.writeFilesystem(out);
out.close();
poifs.close();
-
+
return cps;
}
-
+
/*
* Open {@code doc3} for reading and check summary information
* and document summary information. All properties removed before must not
@@ -491,7 +491,7 @@ public class TestWriteWellKnown {
dis.close();
return si;
}
-
+
static DocumentSummaryInformation getDocumentSummaryInformation(POIFSFileSystem poifs)
throws IOException, NoPropertySetStreamException, UnexpectedPropertySetTypeException {
if (!poifs.getRoot().hasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)) {
diff --git a/src/testcases/org/apache/poi/hpsf/basic/Util.java b/src/testcases/org/apache/poi/hpsf/basic/Util.java
index af4e4462a9..c6ef7ae6c7 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/Util.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/Util.java
@@ -18,7 +18,8 @@
package org.apache.poi.hpsf.basic;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.FileNotFoundException;
@@ -47,7 +48,7 @@ final class Util {
* as an array of {@link POIFile} instances. This method loads all
* files into memory and thus does not cope well with large POI
* filessystems.</p>
- *
+ *
* @param poiFs The name of the POI filesystem as seen by the
* operating system. (This is the "filename".)
*
@@ -55,28 +56,24 @@ final class Util {
*
* @return The POI files. The elements are ordered in the same way
* as the files in the POI filesystem.
- *
- * @exception FileNotFoundException if the file containing the POI
+ *
+ * @exception FileNotFoundException if the file containing the POI
* filesystem does not exist
- *
+ *
* @exception IOException if an I/O exception occurs
*/
static List<POIFile> readPOIFiles(final File poiFs, final String... poiFiles) throws IOException {
final List<POIFile> files = new ArrayList<>();
POIFSReader r = new POIFSReader();
- POIFSReaderListener pfl = event -> {
- try {
- final POIFile f = new POIFile();
- f.setName(event.getName());
- f.setPath(event.getPath());
- final InputStream in = event.getStream();
- f.setBytes(IOUtils.toByteArray(in));
- in.close();
- files.add(f);
- } catch (IOException ex) {
- fail(ex.getMessage());
- }
- };
+ POIFSReaderListener pfl = event -> assertDoesNotThrow(() -> {
+ final POIFile f = new POIFile();
+ f.setName(event.getName());
+ f.setPath(event.getPath());
+ final InputStream in = event.getStream();
+ f.setBytes(IOUtils.toByteArray(in));
+ in.close();
+ files.add(f);
+ });
if (poiFiles.length == 0) {
/* Register the listener for all POI files. */
r.registerListener(pfl);
@@ -98,32 +95,28 @@ final class Util {
* <p>Read all files from a POI filesystem which are property set streams
* and returns them as an array of {@link org.apache.poi.hpsf.PropertySet}
* instances.</p>
- *
+ *
* @param poiFs The name of the POI filesystem as seen by the
* operating system. (This is the "filename".)
*
* @return The property sets. The elements are ordered in the same way
* as the files in the POI filesystem.
- *
+ *
* @exception IOException if an I/O exception occurs
*/
static List<POIFile> readPropertySets(final File poiFs) throws IOException {
final List<POIFile> files = new ArrayList<>(7);
final POIFSReader r = new POIFSReader();
- final POIFSReaderListener pfl = event -> {
- try {
- final POIFile f = new POIFile();
- f.setName(event.getName());
- f.setPath(event.getPath());
- final InputStream in = event.getStream();
- if (PropertySet.isPropertySetStream(in)) {
- f.setBytes(IOUtils.toByteArray(in));
- files.add(f);
- }
- } catch (Exception ex) {
- fail(ex.getMessage());
+ final POIFSReaderListener pfl = event -> assertDoesNotThrow(() -> {
+ final POIFile f = new POIFile();
+ f.setName(event.getName());
+ f.setPath(event.getPath());
+ final InputStream in = event.getStream();
+ if (PropertySet.isPropertySetStream(in)) {
+ f.setBytes(IOUtils.toByteArray(in));
+ files.add(f);
}
- };
+ });
/* Register the listener for all POI files. */
r.registerListener(pfl);
diff --git a/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java b/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
index 9ea2fdd074..4c697074fa 100644
--- a/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
+++ b/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
@@ -18,8 +18,8 @@
package org.apache.poi.hpsf.extractor;
import static org.apache.poi.POITestCase.assertContains;
-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;
import java.io.InputStream;
@@ -30,7 +30,7 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestHPSFPropertiesExtractor {
private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
diff --git a/src/testcases/org/apache/poi/hssf/HSSFTests.java b/src/testcases/org/apache/poi/hssf/HSSFTests.java
deleted file mode 100644
index fa87897da8..0000000000
--- a/src/testcases/org/apache/poi/hssf/HSSFTests.java
+++ /dev/null
@@ -1,48 +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.hssf;
-
-import org.apache.poi.hssf.eventmodel.TestEventRecordFactory;
-import org.apache.poi.hssf.eventusermodel.AllEventUserModelTests;
-import org.apache.poi.hssf.extractor.TestExcelExtractor;
-import org.apache.poi.hssf.model.AllModelTests;
-import org.apache.poi.hssf.record.AllRecordTests;
-import org.apache.poi.hssf.usermodel.AllUserModelTests;
-import org.apache.poi.hssf.util.AllHSSFUtilTests;
-import org.apache.poi.ss.formula.AllSSFormulaTests;
-import org.apache.poi.ss.util.AllSSUtilTests;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test Suite for all sub-packages of org.apache.poi.hssf<br>
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- AllEventUserModelTests.class,
- AllModelTests.class,
- AllUserModelTests.class,
- AllRecordTests.class,
- AllHSSFUtilTests.class,
- TestExcelExtractor.class,
- TestEventRecordFactory.class,
- AllSSFormulaTests.class,
- AllSSUtilTests.class
-})
-public final class HSSFTests {
-}
diff --git a/src/testcases/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java b/src/testcases/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java
index 823dc4418e..9eb7ffac66 100644
--- a/src/testcases/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java
+++ b/src/testcases/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java
@@ -16,8 +16,8 @@
==================================================================== */
package org.apache.poi.hssf.dev;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.File;
import java.util.ArrayList;
@@ -25,53 +25,45 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.stream.Stream;
import org.apache.poi.POIDataSamples;
-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.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
/**
* Base class for integration-style tests which iterate over all test-files
* and execute the same action to find out if any change breaks these applications.
- *
- * This test uses {@link Parameterized} to run the test for each file separatedely.
*/
-@RunWith(Parameterized.class)
public abstract class BaseTestIteratingXLS {
protected static final Map<String,Class<? extends Throwable>> EXCLUDED = new HashMap<>();
- @Parameters(name="{index}: {0}")
- public static Iterable<Object[]> files() {
+ private static Stream<Arguments> files() {
String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
if(dataDirName == null) {
dataDirName = "test-data";
}
- List<Object[]> files = new ArrayList<>();
+ List<Arguments> files = new ArrayList<>();
findFile(files, dataDirName + "/spreadsheet");
findFile(files, dataDirName + "/hpsf");
- return files;
+ return files.stream();
}
- private static void findFile(List<Object[]> list, String dir) {
+ private static void findFile(List<Arguments> list, String dir) {
String[] files = new File(dir).list((arg0, arg1) -> arg1.toLowerCase(Locale.ROOT).endsWith(".xls"));
-
- assertNotNull("Did not find any xls files in directory " + dir, files);
+ assertNotNull(files, "Did not find any xls files in directory " + dir);
for(String file : files) {
- list.add(new Object[]{new File(dir, file)});
- }
+ list.add(Arguments.of(new File(dir, file)));
}
+ }
- @Parameter
- public File file;
-
- @Test
- public void testMain() throws Exception {
+ @ParameterizedTest
+ @MethodSource("files")
+ public void testMain(File file) throws Exception {
String fileName = file.getName();
Class<? extends Throwable> t = EXCLUDED.get(fileName);
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java b/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
index 406266d902..8724122f1f 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
@@ -25,10 +25,10 @@ import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.NullOutputStream;
import org.apache.poi.util.RecordFormatException;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
public class TestBiffDrawingToXml extends BaseTestIteratingXLS {
- @BeforeClass
+ @BeforeAll
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
index f5cce1b268..6130b1566d 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
@@ -27,10 +27,10 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.NullOutputStream;
import org.apache.poi.util.RecordFormatException;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
public class TestBiffViewer extends BaseTestIteratingXLS {
- @BeforeClass
+ @BeforeAll
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("35897-type4.xls", IllegalArgumentException.class); // unsupported crypto api header
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
index 20a7a635c9..f05167dcf7 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
@@ -25,10 +25,10 @@ import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.NullPrintStream;
import org.apache.poi.util.RecordFormatException;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
public class TestEFBiffViewer extends BaseTestIteratingXLS {
- @BeforeClass
+ @BeforeAll
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
index a3eae963c8..a5b952396c 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
@@ -16,7 +16,7 @@
==================================================================== */
package org.apache.poi.hssf.dev;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.File;
import java.io.PrintStream;
@@ -26,10 +26,10 @@ import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.NullPrintStream;
import org.apache.poi.util.RecordFormatException;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
public class TestFormulaViewer extends BaseTestIteratingXLS {
- @BeforeClass
+ @BeforeAll
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestReSave.java b/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
index 8ab108378f..b03de96459 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
@@ -16,7 +16,7 @@
==================================================================== */
package org.apache.poi.hssf.dev;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.PrintStream;
@@ -27,12 +27,12 @@ import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.NullPrintStream;
import org.apache.poi.util.RecordFormatException;
-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;
public class TestReSave extends BaseTestIteratingXLS {
- @BeforeClass
+ @BeforeAll
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
@@ -84,7 +84,7 @@ public class TestReSave extends BaseTestIteratingXLS {
}
}
- @Ignore("Only used for local testing")
+ @Disabled("Only used for local testing")
@Test
public void testOneFile() throws Exception {
String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java b/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java
index 3a1b9bb2fe..0950553125 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java
@@ -23,10 +23,10 @@ import java.io.PrintStream;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.util.NullPrintStream;
import org.apache.poi.util.RecordFormatException;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
public class TestRecordLister extends BaseTestIteratingXLS {
- @BeforeClass
+ @BeforeAll
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("46904.xls", OldExcelFormatException.class);
diff --git a/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java b/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java
index 8a80b78393..973da0839f 100644
--- a/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java
+++ b/src/testcases/org/apache/poi/hssf/eventmodel/TestAbortableListener.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.eventmodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -31,7 +31,7 @@ import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link AbortableHSSFListener}
diff --git a/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java b/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
index f579c4097e..0c93ffe5e1 100644
--- a/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
+++ b/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.eventmodel;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -40,8 +40,8 @@ import org.apache.poi.hssf.record.StandardRecord;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.record.UnknownRecord;
import org.apache.poi.util.NotImplemented;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* enclosing_type describe the purpose here
@@ -65,7 +65,7 @@ public final class TestEventRecordFactory {
ERFListener listener = rec -> {
wascalled[0] = true;
- assertEquals("must be BOFRecord got SID=" + rec.getSid(), rec.getSid(), BOFRecord.sid);
+ assertEquals(rec.getSid(), BOFRecord.sid, "must be BOFRecord got SID=" + rec.getSid());
return true;
};
EventRecordFactory factory = new EventRecordFactory(listener, new short[] {BOFRecord.sid});
@@ -85,7 +85,7 @@ public final class TestEventRecordFactory {
eof.serialize(offset,bytes);
factory.processRecords(new ByteArrayInputStream(bytes));
- assertTrue("The record listener must be called", wascalled[0]);
+ assertTrue(wascalled[0], "The record listener must be called");
}
@@ -107,7 +107,7 @@ public final class TestEventRecordFactory {
Record[] records = RecordFactory.createRecord(TestcaseRecordInputStream.create(bytes));
- assertEquals("record.length must be 1, was =" + records.length, 1, records.length);
+ assertEquals(1, records.length, "record.length must be 1, was =" + records.length);
byte[] rec1 = bof.serialize();
byte[] rec2 = records[0].serialize();
@@ -121,9 +121,8 @@ public final class TestEventRecordFactory {
*/
@NotImplemented
@Test
- @Ignore
+ @Disabled
public void testCreateContinuedRecord() {
- // fail("not implemented");
}
@@ -145,7 +144,7 @@ public final class TestEventRecordFactory {
}
@Test
- @Ignore("same as testContinuedUnknownRecord but with SequenceInputStream which causes the available() bug 59893")
+ @Disabled("same as testContinuedUnknownRecord but with SequenceInputStream which causes the available() bug 59893")
public void bug59893() {
Iterator<ByteArrayInputStream> iter = Stream.of(CONTINUE_DATA).map(ByteArrayInputStream::new).iterator();
SequenceInputStream sis = new SequenceInputStream(IteratorUtils.asEnumeration(iter));
@@ -164,6 +163,6 @@ public final class TestEventRecordFactory {
};
EventRecordFactory factory = new EventRecordFactory(listener, new short[] {-256, 0x3C});
factory.processRecords(data);
- assertFalse("left over input data", expectedData.hasNext());
+ assertFalse(expectedData.hasNext(), "left over input data");
}
}
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/AllEventUserModelTests.java b/src/testcases/org/apache/poi/hssf/eventusermodel/AllEventUserModelTests.java
deleted file mode 100644
index a5d9073759..0000000000
--- a/src/testcases/org/apache/poi/hssf/eventusermodel/AllEventUserModelTests.java
+++ /dev/null
@@ -1,34 +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.hssf.eventusermodel;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for <tt>org.apache.poi.hssf.eventusermodel</tt>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestEventWorkbookBuilder.class,
- TestFormatTrackingHSSFListener.class,
- TestHSSFEventFactory.class,
- TestMissingRecordAwareHSSFListener.class
-})
-public class AllEventUserModelTests {
-}
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java
index d639c2c3f8..df64164d0c 100644
--- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java
+++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.eventusermodel;
-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.io.InputStream;
@@ -31,14 +31,13 @@ import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollec
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.FormulaRecord;
-import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.Ref3DPtg;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link EventWorkbookBuilder}
@@ -47,7 +46,7 @@ public final class TestEventWorkbookBuilder {
private final List<FormulaRecord> fRecs = new ArrayList<>();
private SheetRecordCollectingListener listener;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
HSSFRequest req = new HSSFRequest();
fRecs.clear();
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java
index ad9640647d..e3ca90ca92 100644
--- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java
+++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java
@@ -16,9 +16,9 @@
==================================================================== */
package org.apache.poi.hssf.eventusermodel;
-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.File;
import java.util.ArrayList;
@@ -28,9 +28,9 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.NumberRecord;
-import org.apache.poi.hssf.record.Record;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
/**
* Tests for FormatTrackingHSSFListener
*/
@@ -43,14 +43,14 @@ public final class TestFormatTrackingHSSFListener {
mockListen = new MockHSSFListener();
listener = new FormatTrackingHSSFListener(mockListen);
req.addListenerForAllRecords(listener);
-
+
File file = HSSFTestDataSamples.getSampleFile(filename);
HSSFEventFactory factory = new HSSFEventFactory();
POIFSFileSystem fs = new POIFSFileSystem(file);
factory.processWorkbookEvents(req, fs);
fs.close();
- }
-
+ }
+
@Test
public void testFormats() throws Exception {
processFile("MissingBits.xls");
@@ -60,7 +60,7 @@ public final class TestFormatTrackingHSSFListener {
assertEquals("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)", listener.getFormatString(43));
assertEquals("_(\"$\"* #,##0.00_);_(\"$\"* (#,##0.00);_(\"$\"* \"-\"??_);_(@_)", listener.getFormatString(44));
}
-
+
/**
* Ensure that all number and formula records can be
* turned into strings without problems.
@@ -70,40 +70,40 @@ public final class TestFormatTrackingHSSFListener {
*/
@Test
public void testTurnToString() throws Exception {
- String[] files = new String[] {
- "45365.xls", "45365-2.xls", "MissingBits.xls"
+ String[] files = new String[] {
+ "45365.xls", "45365-2.xls", "MissingBits.xls"
};
for (String file : files) {
processFile(file);
-
+
// Check we found our formats
assertTrue(listener.getNumberOfCustomFormats() > 5);
assertTrue(listener.getNumberOfExtendedFormats() > 5);
-
+
// Now check we can turn all the numeric
// cells into strings without error
for(org.apache.poi.hssf.record.Record r : mockListen._records) {
CellValueRecordInterface cvr = null;
-
+
if(r instanceof NumberRecord) {
cvr = (CellValueRecordInterface)r;
}
if(r instanceof FormulaRecord) {
cvr = (CellValueRecordInterface)r;
}
-
+
if(cvr != null) {
- // Should always give us a string
+ // Should always give us a string
String s = listener.formatNumberDateCell(cvr);
assertNotNull(s);
assertTrue(s.length() > 0);
}
}
-
+
// TODO - test some specific format strings
}
}
-
+
private static final class MockHSSFListener implements HSSFListener {
public MockHSSFListener() {}
private final List<org.apache.poi.hssf.record.Record> _records = new ArrayList<>();
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java
index cb1015f729..4cf5f77ae2 100644
--- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java
+++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java
@@ -17,10 +17,11 @@
package org.apache.poi.hssf.eventusermodel;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.io.InputStream;
@@ -40,7 +41,7 @@ import org.apache.poi.hssf.record.SelectionRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Testing for {@link HSSFEventFactory}
@@ -115,11 +116,11 @@ public final class TestHSSFEventFactory {
openSample("WORKBOOK_in_capitals.xls");
}
- @Test(expected = EncryptedDocumentException.class)
+ @Test
@SuppressWarnings("java:S2699")
- public void testWithPasswordProtectedWorkbooksNoPass() throws Exception {
+ public void testWithPasswordProtectedWorkbooksNoPass() {
// Without a password, can't be read
- openSample("xor-encryption-abc.xls");
+ assertThrows(EncryptedDocumentException.class, () -> openSample("xor-encryption-abc.xls"));
}
@Test
@@ -157,10 +158,10 @@ public final class TestHSSFEventFactory {
}
}
- assertTrue("Sheet record not found", hasSheet);
- assertTrue("Numeric record for A1 not found", hasA1);
- assertTrue("Numeric record for A2 not found", hasA2);
- assertTrue("Numeric record for A3 not found", hasA3);
+ assertTrue(hasSheet, "Sheet record not found");
+ assertTrue(hasA1, "Numeric record for A1 not found");
+ assertTrue(hasA2, "Numeric record for A2 not found");
+ assertTrue(hasA3, "Numeric record for A3 not found");
} finally {
Biff8EncryptionKey.setCurrentUserPassword(null);
}
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
index 29be9baab2..d89584cbf3 100644
--- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
+++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.eventusermodel;
-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;
import java.io.InputStream;
@@ -36,12 +36,11 @@ import org.apache.poi.hssf.record.DimensionsRecord;
import org.apache.poi.hssf.record.LabelSSTRecord;
import org.apache.poi.hssf.record.MulBlankRecord;
import org.apache.poi.hssf.record.NumberRecord;
-import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.SharedFormulaRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for MissingRecordAwareHSSFListener
diff --git a/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java b/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
index 139b03fb03..6d32039836 100644
--- a/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
+++ b/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
@@ -19,9 +19,9 @@ package org.apache.poi.hssf.extractor;
import static org.apache.poi.POITestCase.assertContains;
import static org.apache.poi.POITestCase.assertStartsWith;
-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.File;
import java.io.IOException;
@@ -34,7 +34,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
*
diff --git a/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java b/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
index 6403fe4e74..708cf2e94d 100644
--- a/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
+++ b/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.extractor;
import static org.apache.poi.POITestCase.assertContains;
-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 java.io.ByteArrayOutputStream;
import java.io.File;
@@ -38,8 +38,9 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.NullPrintStream;
import org.apache.poi.util.RecordFormatException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit tests for the Excel 5/95 and Excel 4 (and older) text
@@ -228,38 +229,31 @@ public final class TestOldExcelExtractor {
}
}
- @Test(expected=OfficeXmlFileException.class)
+ @Test
public void testOpenInvalidFile1() throws IOException {
// a file that exists, but is a different format
- createExtractor("WithVariousData.xlsx").close();
- }
-
+ assertThrows(OfficeXmlFileException.class, () -> createExtractor("WithVariousData.xlsx").close());
- @Test(expected=RecordFormatException.class)
- public void testOpenInvalidFile2() throws IOException {
// a completely different type of file
- createExtractor("48936-strings.txt").close();
- }
+ assertThrows(RecordFormatException.class, () -> createExtractor("48936-strings.txt").close());
- @Test(expected=FileNotFoundException.class)
- public void testOpenInvalidFile3() throws IOException {
// a POIFS file which is not a Workbook
try (InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream("47304.doc")) {
- new OldExcelExtractor(is).close();
+ assertThrows(FileNotFoundException.class, () -> new OldExcelExtractor(is).close());
}
}
- @Test(expected=EmptyFileException.class)
- public void testOpenNonExistingFile() throws IOException {
+ @Test
+ public void testOpenNonExistingFile() {
// a file that exists, but is a different format
- new OldExcelExtractor(new File("notexistingfile.xls")).close();
+ assertThrows(EmptyFileException.class, () -> new OldExcelExtractor(new File("notexistingfile.xls")).close());
}
@Test
public void testInputStream() throws IOException {
File file = HSSFTestDataSamples.getSampleFile("testEXCEL_3.xls");
try (InputStream stream = new FileInputStream(file);
- OldExcelExtractor extractor = new OldExcelExtractor(stream);) {
+ OldExcelExtractor extractor = new OldExcelExtractor(stream)) {
String text = extractor.getText();
assertNotNull(text);
}
@@ -299,27 +293,23 @@ public final class TestOldExcelExtractor {
}
}
- @Test(expected = FileNotFoundException.class)
+ @Test
public void testDirectoryNodeInvalidFile() throws IOException {
File file = POIDataSamples.getDocumentInstance().getFile("test.doc");
- try (POIFSFileSystem fs = new POIFSFileSystem(file);
- OldExcelExtractor extractor = new OldExcelExtractor(fs.getRoot())) {
- fail("Should throw exception here");
+ try (POIFSFileSystem fs = new POIFSFileSystem(file)) {
+ assertThrows(FileNotFoundException.class, () -> new OldExcelExtractor(fs.getRoot()));
}
}
- @Test(expected = ExitException.class)
- public void testMainUsage() throws IOException {
+ @Test
+ public void testMainUsage() {
PrintStream save = System.err;
SecurityManager sm = System.getSecurityManager();
System.setSecurityManager(new NoExitSecurityManager());
try {
- try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
- PrintStream str = new PrintStream(out, false, "UTF-8");
- System.setErr(str);
- // calls System.exit()
- OldExcelExtractor.main(new String[]{});
- }
+ System.setErr(new NullPrintStream());
+ // calls System.exit()
+ assertThrows(ExitException.class, () -> OldExcelExtractor.main(new String[]{}));
} finally {
System.setSecurityManager(sm);
System.setErr(save);
@@ -336,13 +326,13 @@ public final class TestOldExcelExtractor {
System.setOut(str);
OldExcelExtractor.main(new String[] {file.getAbsolutePath()});
String string = out.toString("UTF-8");
- assertTrue("Had: " + string, string.contains("Table C-13--Lemons"));
+ assertTrue(string.contains("Table C-13--Lemons"), "Had: " + string);
} finally {
System.setOut(save);
}
}
- @Test(expected = EncryptedDocumentException.class)
+ @Test
public void testEncryptionException() throws IOException {
//test file derives from Common Crawl
File file = HSSFTestDataSamples.getSampleFile("60284.xls");
@@ -350,7 +340,7 @@ public final class TestOldExcelExtractor {
try (OldExcelExtractor ex = new OldExcelExtractor(file)) {
assertEquals(5, ex.getBiffVersion());
assertEquals(5, ex.getFileType());
- ex.getText();
+ assertThrows(EncryptedDocumentException.class, ex::getText);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/model/AllModelTests.java b/src/testcases/org/apache/poi/hssf/model/AllModelTests.java
deleted file mode 100644
index 419b7309b8..0000000000
--- a/src/testcases/org/apache/poi/hssf/model/AllModelTests.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.hssf.model;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for <tt>org.apache.poi.hssf.model</tt>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestDrawingManager2.class,
- TestFormulaParser.class,
- TestFormulaParserEval.class,
- TestFormulaParserIf.class,
- TestLinkTable.class,
- TestOperandClassTransformer.class,
- TestRowBlocksReader.class,
- TestRVA.class,
- TestSheet.class,
- TestSheetAdditional.class,
- TestWorkbook.class
-})
-public final class AllModelTests {
-}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java
index 47918cfb0e..cac09fd549 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java
@@ -17,12 +17,11 @@
package org.apache.poi.hssf.model;
import static org.apache.poi.poifs.storage.RawDataUtil.decompress;
-import static org.junit.Assert.assertArrayEquals;
-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.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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -32,6 +31,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Stream;
import org.apache.poi.ddf.DefaultEscherRecordFactory;
import org.apache.poi.ddf.EscherContainerRecord;
@@ -55,7 +55,10 @@ import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFTestHelper;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
public class TestDrawingAggregate {
/**
@@ -123,82 +126,69 @@ public class TestDrawingAggregate {
}
}
+ public static Stream<Arguments> samples() {
+ File testData = new File(System.getProperty("POI.testdata.path"), "spreadsheet");
+ File[] files = testData.listFiles((dir, name) -> name.endsWith(".xls"));
+ assertNotNull(files, "Need to find files in test-data path, had path: " + testData);
+ return Stream.of(files).map(Arguments::of);
+ }
+
/**
+ * test that we correctly read and write drawing aggregates in all .xls files in POI test samples.
* iterate over all sheets, aggregate drawing records (if there are any)
* and remember information about the aggregated data.
* Then serialize the workbook, read back and assert that the aggregated data is preserved.
*
* The assertion is strict meaning that the drawing data before and after save must be equal.
*/
- private static void assertWriteAndReadBack(HSSFWorkbook wb) throws IOException {
- // map aggregate info by sheet index
- Map<Integer, DrawingAggregateInfo> aggs = new HashMap<>();
- for(int i = 0; i < wb.getNumberOfSheets(); i++){
- HSSFSheet sheet = wb.getSheetAt(i);
- DrawingAggregateInfo info = DrawingAggregateInfo.get(sheet);
- if(info != null) {
- aggs.put(i, info);
- HSSFPatriarch p = sheet.getDrawingPatriarch();
-
- // compare aggregate.serialize() with raw bytes from the record stream
- EscherAggregate agg = HSSFTestHelper.getEscherAggregate(p);
-
- byte[] dgBytes1 = info.getRawBytes();
- byte[] dgBytes2 = agg.serialize();
-
- assertEquals("different size of raw data ande aggregate.serialize()", dgBytes1.length, dgBytes2.length);
- assertArrayEquals("raw drawing data (" + dgBytes1.length + " bytes) and aggregate.serialize() are different.", dgBytes1, dgBytes2);
- }
- }
-
- if(aggs.size() != 0){
- HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
- for(int i = 0; i < wb2.getNumberOfSheets(); i++){
- DrawingAggregateInfo info1 = aggs.get(i);
- if(info1 != null) {
- HSSFSheet sheet2 = wb2.getSheetAt(i);
- DrawingAggregateInfo info2 = DrawingAggregateInfo.get(sheet2);
- byte[] dgBytes1 = info1.getRawBytes();
- byte[] dgBytes2 = info2.getRawBytes();
- assertEquals("different size of drawing data before and after save", dgBytes1.length, dgBytes2.length);
- assertArrayEquals("drawing data (" + dgBytes1.length + " bytes) before and after save is different.", dgBytes1, dgBytes2);
+ @ParameterizedTest
+ @MethodSource("samples")
+ public void testAllTestSamples(File file) throws IOException {
+ boolean ignoreParse = true;
+ try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(file.getName())) {
+ ignoreParse = false;
+
+ // map aggregate info by sheet index
+ Map<Integer, DrawingAggregateInfo> aggs = new HashMap<>();
+ for (int i = 0; i < wb.getNumberOfSheets(); i++){
+ HSSFSheet sheet = wb.getSheetAt(i);
+ DrawingAggregateInfo info = DrawingAggregateInfo.get(sheet);
+ if(info != null) {
+ aggs.put(i, info);
+ HSSFPatriarch p = sheet.getDrawingPatriarch();
+
+ // compare aggregate.serialize() with raw bytes from the record stream
+ EscherAggregate agg = HSSFTestHelper.getEscherAggregate(p);
+
+ byte[] dgBytes1 = info.getRawBytes();
+ byte[] dgBytes2 = agg.serialize();
+
+ assertEquals(dgBytes1.length, dgBytes2.length, "different size of raw data ande aggregate.serialize()");
+ assertArrayEquals(dgBytes1, dgBytes2, "raw drawing data (" + dgBytes1.length + " bytes) and aggregate.serialize() are different.");
}
}
- wb2.close();
- }
- }
- /**
- * test that we correctly read and write drawing aggregates
- * in all .xls files in POI test samples
- */
- @Test
- public void testAllTestSamples() throws IOException {
- File[] xls = new File(System.getProperty("POI.testdata.path"), "spreadsheet").listFiles(
- (dir, name) -> name.endsWith(".xls")
- );
- assertNotNull(
- "Need to find files in test-data path, had path: " + new File(System.getProperty("POI.testdata.path"), "spreadsheet"),
- xls);
- for(File file : xls) {
- HSSFWorkbook wb;
- try {
- wb = HSSFTestDataSamples.openSampleWorkbook(file.getName());
- } catch (Throwable e){
- // don't bother about files we cannot read - they are different bugs
- // System.out.println("[WARN] Cannot read " + file.getName());
- continue;
+ if(aggs.size() != 0){
+ try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb)) {
+ for (int i = 0; i < wb2.getNumberOfSheets(); i++) {
+ DrawingAggregateInfo info1 = aggs.get(i);
+ if (info1 != null) {
+ HSSFSheet sheet2 = wb2.getSheetAt(i);
+ DrawingAggregateInfo info2 = DrawingAggregateInfo.get(sheet2);
+ byte[] dgBytes1 = info1.getRawBytes();
+ byte[] dgBytes2 = info2.getRawBytes();
+ assertEquals(dgBytes1.length, dgBytes2.length, "different size of drawing data before and after save");
+ assertArrayEquals(dgBytes1, dgBytes2, "drawing data (" + dgBytes1.length + " bytes) before and after save is different.");
+ }
+ }
+ }
}
- try {
- assertWriteAndReadBack(wb);
- } catch (Exception e) {
- String filename = file.getName();
- System.out.println("Drawing Aggregate re-write test failed for " + filename);
- e.printStackTrace(System.out);
- fail("Error when writing and re-reading workbook " + filename + "\n" + e);
+ } catch (Throwable e) {
+ // don't bother about files we cannot read - they are different bugs
+ if (!ignoreParse) {
+ throw e;
}
- wb.close();
}
}
@@ -223,7 +213,7 @@ public class TestDrawingAggregate {
records.add(r);
pos += bytesRead;
}
- assertEquals("data was not fully read", dgBytes.length, pos);
+ assertEquals(dgBytes.length, pos, "data was not fully read");
// serialize to byte array
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -292,8 +282,8 @@ public class TestDrawingAggregate {
agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertNotNull(agg);
byte[] dgBytesAfterSave = agg.serialize();
- assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
- assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
+ assertEquals(dgBytes.length, dgBytesAfterSave.length, "different size of drawing data before and after save");
+ assertArrayEquals(dgBytes, dgBytesAfterSave, "drawing data before and after save is different");
}
}
}
@@ -313,8 +303,8 @@ public class TestDrawingAggregate {
EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertNotNull(agg);
byte[] dgBytesAfterSave = agg.serialize();
- assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
- assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
+ assertEquals(dgBytes.length, dgBytesAfterSave.length, "different size of drawing data before and after save");
+ assertArrayEquals(dgBytes, dgBytesAfterSave, "drawing data before and after save is different");
}
}
@@ -333,13 +323,13 @@ public class TestDrawingAggregate {
EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertNotNull(agg);
byte[] dgBytesAfterSave = agg.serialize();
- assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
+ assertEquals(dgBytes.length, dgBytesAfterSave.length, "different size of drawing data before and after save");
for (int i = 0; i < dgBytes.length; i++) {
if (dgBytes[i] != dgBytesAfterSave[i]) {
System.out.println("pos = " + i);
}
}
- assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
+ assertArrayEquals(dgBytes, dgBytesAfterSave, "drawing data before and after save is different");
}
}
@@ -357,11 +347,10 @@ public class TestDrawingAggregate {
List<RecordBase> records = isheet.getRecords();
// the sheet's drawing is not aggregated
- assertEquals("wrong size of sheet records stream", 394, records.size());
+ assertEquals(394, records.size(), "wrong size of sheet records stream");
// the last record before the drawing block
- assertTrue(
- "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
- records.get(18) instanceof RowRecordsAggregate);
+ assertTrue(records.get(18) instanceof RowRecordsAggregate,
+ "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName());
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 389);
@@ -381,9 +370,7 @@ public class TestDrawingAggregate {
}
// the first record after the drawing block
- assertTrue(
- "records.get(389) is expected to be Window2",
- records.get(389) instanceof WindowTwoRecord);
+ assertTrue(records.get(389) instanceof WindowTwoRecord, "records.get(389) is expected to be Window2");
// aggregate drawing records.
// The subrange [19, 388] is expected to be replaced with a EscherAggregate object
@@ -391,18 +378,17 @@ public class TestDrawingAggregate {
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
- assertEquals("wrong size of the aggregated sheet records stream", 25, records.size());
- assertTrue(
- "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
- records.get(18) instanceof RowRecordsAggregate);
- assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(),
- records.get(19) instanceof EscherAggregate);
- assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(),
- records.get(20) instanceof WindowTwoRecord);
+ assertEquals(25, records.size(), "wrong size of the aggregated sheet records stream");
+ assertTrue(records.get(18) instanceof RowRecordsAggregate,
+ "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName());
+ assertTrue(records.get(19) instanceof EscherAggregate,
+ "records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName());
+ assertTrue(records.get(20) instanceof WindowTwoRecord,
+ "records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName());
byte[] dgBytesAfterSave = agg.serialize();
- assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
- assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
+ assertEquals(dgBytes.length, dgBytesAfterSave.length, "different size of drawing data before and after save");
+ assertArrayEquals(dgBytes, dgBytesAfterSave, "drawing data before and after save is different");
}
}
@@ -425,11 +411,10 @@ public class TestDrawingAggregate {
List<RecordBase> records = isheet.getRecords();
// the sheet's drawing is not aggregated
- assertEquals("wrong size of sheet records stream", 32, records.size());
+ assertEquals(32, records.size(), "wrong size of sheet records stream");
// the last record before the drawing block
- assertTrue(
- "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
- records.get(18) instanceof RowRecordsAggregate);
+ assertTrue(records.get(18) instanceof RowRecordsAggregate,
+ "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName());
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 26);
@@ -449,9 +434,7 @@ public class TestDrawingAggregate {
byte[] dgBytes = toByteArray(dgRecords);
// the first record after the drawing block
- assertTrue(
- "records.get(26) is expected to be Window2",
- records.get(26) instanceof WindowTwoRecord);
+ assertTrue(records.get(26) instanceof WindowTwoRecord, "records.get(26) is expected to be Window2");
// aggregate drawing records.
// The subrange [19, 38] is expected to be replaced with a EscherAggregate object
@@ -459,18 +442,17 @@ public class TestDrawingAggregate {
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
- assertEquals("wrong size of the aggregated sheet records stream", 26, records.size());
- assertTrue(
- "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
- records.get(18) instanceof RowRecordsAggregate);
- assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(),
- records.get(19) instanceof EscherAggregate);
- assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(),
- records.get(20) instanceof WindowTwoRecord);
+ assertEquals(26, records.size(), "wrong size of the aggregated sheet records stream");
+ assertTrue(records.get(18) instanceof RowRecordsAggregate,
+ "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName());
+ assertTrue(records.get(19) instanceof EscherAggregate,
+ "records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName());
+ assertTrue(records.get(20) instanceof WindowTwoRecord,
+ "records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName());
byte[] dgBytesAfterSave = agg.serialize();
- assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
- assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
+ assertEquals(dgBytes.length, dgBytesAfterSave.length, "different size of drawing data before and after save");
+ assertArrayEquals(dgBytes, dgBytesAfterSave, "drawing data before and after save is different");
}
}
@@ -510,11 +492,10 @@ public class TestDrawingAggregate {
List<RecordBase> records = isheet.getRecords();
// the sheet's drawing is not aggregated
- assertEquals("wrong size of sheet records stream", 46, records.size());
+ assertEquals(46, records.size(), "wrong size of sheet records stream");
// the last record before the drawing block
- assertTrue(
- "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
- records.get(18) instanceof RowRecordsAggregate);
+ assertTrue(records.get(18) instanceof RowRecordsAggregate,
+ "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName());
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 39);
@@ -534,9 +515,7 @@ public class TestDrawingAggregate {
byte[] dgBytes = toByteArray(dgRecords);
// the first record after the drawing block
- assertTrue(
- "records.get(39) is expected to be Window2",
- records.get(39) instanceof WindowTwoRecord);
+ assertTrue(records.get(39) instanceof WindowTwoRecord, "records.get(39) is expected to be Window2");
// aggregate drawing records.
// The subrange [19, 38] is expected to be replaced with a EscherAggregate object
@@ -544,18 +523,17 @@ public class TestDrawingAggregate {
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
- assertEquals("wrong size of the aggregated sheet records stream", 27, records.size());
- assertTrue(
- "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
- records.get(18) instanceof RowRecordsAggregate);
- assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(),
- records.get(19) instanceof EscherAggregate);
- assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(),
- records.get(20) instanceof WindowTwoRecord);
+ assertEquals(27, records.size(), "wrong size of the aggregated sheet records stream");
+ assertTrue(records.get(18) instanceof RowRecordsAggregate,
+ "records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName());
+ assertTrue(records.get(19) instanceof EscherAggregate,
+ "records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName());
+ assertTrue(records.get(20) instanceof WindowTwoRecord,
+ "records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName());
byte[] dgBytesAfterSave = agg.serialize();
- assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
- assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
+ assertEquals(dgBytes.length, dgBytesAfterSave.length, "different size of drawing data before and after save");
+ assertArrayEquals(dgBytes, dgBytesAfterSave, "drawing data before and after save is different");
}
}
@@ -571,11 +549,10 @@ public class TestDrawingAggregate {
List<RecordBase> records = isheet.getRecords();
// the sheet's drawing is not aggregated
- assertEquals("wrong size of sheet records stream", 315, records.size());
+ assertEquals(315, records.size(), "wrong size of sheet records stream");
// the last record before the drawing block
- assertTrue(
- "records.get(21) is expected to be RowRecordsAggregate but was " + records.get(21).getClass().getSimpleName(),
- records.get(21) instanceof RowRecordsAggregate);
+ assertTrue(records.get(21) instanceof RowRecordsAggregate,
+ "records.get(21) is expected to be RowRecordsAggregate but was " + records.get(21).getClass().getSimpleName());
// records to be aggregated
List<RecordBase> dgRecords = records.subList(22, 300);
@@ -594,9 +571,7 @@ public class TestDrawingAggregate {
byte[] dgBytes = toByteArray(dgRecords);
// the first record after the drawing block
- assertTrue(
- "records.get(300) is expected to be Window2",
- records.get(300) instanceof WindowTwoRecord);
+ assertTrue(records.get(300) instanceof WindowTwoRecord, "records.get(300) is expected to be Window2");
// aggregate drawing records.
// The subrange [19, 299] is expected to be replaced with a EscherAggregate object
@@ -604,18 +579,17 @@ public class TestDrawingAggregate {
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
- assertEquals("wrong size of the aggregated sheet records stream", 38, records.size());
- assertTrue(
- "records.get(21) is expected to be RowRecordsAggregate but was " + records.get(21).getClass().getSimpleName(),
- records.get(21) instanceof RowRecordsAggregate);
- assertTrue("records.get(22) is expected to be EscherAggregate but was " + records.get(22).getClass().getSimpleName(),
- records.get(22) instanceof EscherAggregate);
- assertTrue("records.get(23) is expected to be Window2 but was " + records.get(23).getClass().getSimpleName(),
- records.get(23) instanceof WindowTwoRecord);
+ assertEquals(38, records.size(), "wrong size of the aggregated sheet records stream");
+ assertTrue(records.get(21) instanceof RowRecordsAggregate,
+ "records.get(21) is expected to be RowRecordsAggregate but was " + records.get(21).getClass().getSimpleName());
+ assertTrue(records.get(22) instanceof EscherAggregate,
+ "records.get(22) is expected to be EscherAggregate but was " + records.get(22).getClass().getSimpleName());
+ assertTrue(records.get(23) instanceof WindowTwoRecord,
+ "records.get(23) is expected to be Window2 but was " + records.get(23).getClass().getSimpleName());
byte[] dgBytesAfterSave = agg.serialize();
- assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
- assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
+ assertEquals(dgBytes.length, dgBytesAfterSave.length, "different size of drawing data before and after save");
+ assertArrayEquals(dgBytes, dgBytesAfterSave, "drawing data before and after save is different");
}
}
@@ -739,7 +713,7 @@ public class TestDrawingAggregate {
};
int[] actualSids = dgRecords.stream().mapToInt(Record::getSid).toArray();
- assertArrayEquals("unexpected record.sid", expectedSids, actualSids);
+ assertArrayEquals(expectedSids, actualSids, "unexpected record.sid");
DrawingManager2 drawingManager = new DrawingManager2(new EscherDggRecord());
@@ -752,14 +726,14 @@ public class TestDrawingAggregate {
sheet.aggregateDrawingRecords(drawingManager, false);
- assertEquals("drawing was not fully aggregated", 2, records.size());
- assertTrue("expected EscherAggregate", records.get(0) instanceof EscherAggregate);
- assertTrue("expected EOFRecord", records.get(1) instanceof EOFRecord);
+ assertEquals(2, records.size(), "drawing was not fully aggregated");
+ assertTrue(records.get(0) instanceof EscherAggregate, "expected EscherAggregate");
+ assertTrue(records.get(1) instanceof EOFRecord, "expected EOFRecord");
EscherAggregate agg = (EscherAggregate) records.get(0);
byte[] dgBytesAfterSave = agg.serialize();
- assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
- assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
+ assertEquals(dgBytes.length, dgBytesAfterSave.length, "different size of drawing data before and after save");
+ assertArrayEquals(dgBytes, dgBytesAfterSave, "drawing data before and after save is different");
}
@Test
@@ -905,7 +879,7 @@ public class TestDrawingAggregate {
};
int[] actualSids = dgRecords.stream().mapToInt(Record::getSid).toArray();
- assertArrayEquals("unexpected record.sid", expectedSids, actualSids);
+ assertArrayEquals(expectedSids, actualSids, "unexpected record.sid");
DrawingManager2 drawingManager = new DrawingManager2(new EscherDggRecord());
@@ -917,14 +891,14 @@ public class TestDrawingAggregate {
records.add(EOFRecord.instance);
sheet.aggregateDrawingRecords(drawingManager, false);
- assertEquals("drawing was not fully aggregated", 2, records.size());
- assertTrue("expected EscherAggregate", records.get(0) instanceof EscherAggregate);
- assertTrue("expected EOFRecord", records.get(1) instanceof EOFRecord);
+ assertEquals(2, records.size(), "drawing was not fully aggregated");
+ assertTrue(records.get(0) instanceof EscherAggregate, "expected EscherAggregate");
+ assertTrue(records.get(1) instanceof EOFRecord, "expected EOFRecord");
EscherAggregate agg = (EscherAggregate) records.get(0);
byte[] dgBytesAfterSave = agg.serialize();
- assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
- assertArrayEquals("drawing data brefpore and after save is different", dgBytes, dgBytesAfterSave);
+ assertEquals(dgBytes.length, dgBytesAfterSave.length, "different size of drawing data before and after save");
+ assertArrayEquals(dgBytes, dgBytesAfterSave, "drawing data brefpore and after save is different");
}
}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingManager2.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingManager2.java
index ca4e8cf230..13ca011eb1 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestDrawingManager2.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingManager2.java
@@ -17,18 +17,18 @@
package org.apache.poi.hssf.model;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ddf.EscherDgRecord;
import org.apache.poi.ddf.EscherDggRecord;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public final class TestDrawingManager2 {
private DrawingManager2 drawingManager2;
private EscherDggRecord dgg;
- @Before
+ @BeforeEach
public void setUp() {
dgg = new EscherDggRecord();
dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[0] );
diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
index a6ef067cf2..16cfe133e1 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.model;
-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.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.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.assertTrue;
import java.io.IOException;
import java.util.List;
@@ -60,12 +60,12 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.HexDump;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test escher drawing
- *
+ *
* optionally the system setting "poi.deserialize.escher" can be set to {@code true}
*/
public class TestDrawingShapes {
@@ -107,7 +107,7 @@ public class TestDrawingShapes {
assertEquals(HSSFShape.LINEWIDTH_DEFAULT, shape.getLineWidth());
assertEquals(HSSFShape.LINESTYLE_SOLID, shape.getLineStyle());
assertFalse(shape.isNoFill());
-
+
EscherOptRecord opt = shape.getOptRecord();
assertEquals(7, opt.getEscherProperties().size());
@@ -284,7 +284,7 @@ public class TestDrawingShapes {
assertFalse(shape.isNoFill());
assertEquals(shape.getLineStyle(), HSSFShape.LINESTYLE_DASHDOTGEL);
assertEquals(shape.getLineStyleColor(), 0x616161);
- assertEquals(HexDump.toHex(shape.getFillColor()), shape.getFillColor(), 0x2CE03D);
+ assertEquals(shape.getFillColor(), 0x2CE03D, HexDump.toHex(shape.getFillColor()));
assertEquals(shape.getLineWidth(), HSSFShape.LINEWIDTH_ONE_PT * 2);
assertEquals(shape.getString().getString(), "POItest");
assertEquals(shape.getRotationDegree(), 27);
@@ -307,8 +307,8 @@ public class TestDrawingShapes {
EscherAggregate agg1 = HSSFTestHelper.getEscherAggregate(patriarch1);
// last shape ID cached in EscherDgRecord
- EscherDgRecord dg1 =
- agg1.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
+ EscherDgRecord dg1 = agg1.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
+ assertNotNull(dg1);
assertEquals(1026, dg1.getLastMSOSPID());
// iterate over shapes and check shapeId
@@ -319,14 +319,17 @@ public class TestDrawingShapes {
EscherSpRecord sp0 =
((EscherContainerRecord) spgrContainer.getChild(0)).getChildById(EscherSpRecord.RECORD_ID);
+ assertNotNull(sp0);
assertEquals(1024, sp0.getShapeId());
EscherSpRecord sp1 =
((EscherContainerRecord) spgrContainer.getChild(1)).getChildById(EscherSpRecord.RECORD_ID);
+ assertNotNull(sp1);
assertEquals(1025, sp1.getShapeId());
EscherSpRecord sp2 =
((EscherContainerRecord) spgrContainer.getChild(2)).getChildById(EscherSpRecord.RECORD_ID);
+ assertNotNull(sp2);
assertEquals(1026, sp2.getShapeId());
wb2.close();
}
@@ -380,22 +383,23 @@ public class TestDrawingShapes {
assertSame(opt1, opt2);
wb.close();
}
-
+
@Test
public void testCorrectOrderInOptRecord() throws IOException{
HSSFWorkbook wb = new HSSFWorkbook();
-
+
HSSFSheet sheet = wb.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
EscherOptRecord opt = HSSFTestHelper.getOptRecord(textbox);
-
+
String opt1Str = opt.toXml();
textbox.setFillColor(textbox.getFillColor());
EscherContainerRecord container = HSSFTestHelper.getEscherContainer(textbox);
EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
+ assertNotNull(optRecord);
assertEquals(opt1Str, optRecord.toXml());
textbox.setLineStyle(textbox.getLineStyle());
assertEquals(opt1Str, optRecord.toXml());
@@ -689,7 +693,7 @@ public class TestDrawingShapes {
@Test
public void testShapeContainerImplementsIterable() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
-
+
HSSFSheet sheet = wb.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
@@ -737,13 +741,13 @@ public class TestDrawingShapes {
assertEquals(patriarch.getChildren().size(), 0);
wb2.close();
}
-
+
@Test
public void testBug45312() throws Exception {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
-
+
{
HSSFClientAnchor a1 = new HSSFClientAnchor();
a1.setAnchor( (short)1, 1, 0, 0, (short) 1, 1, 512, 100);
@@ -771,7 +775,7 @@ public class TestDrawingShapes {
shape1.setFlipHorizontal(true);
shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
}
-
+
checkWorkbookBack(wb);
}
}
@@ -779,13 +783,13 @@ public class TestDrawingShapes {
private void checkWorkbookBack(HSSFWorkbook wb) throws IOException {
HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
assertNotNull(wbBack);
-
+
HSSFSheet sheetBack = wbBack.getSheetAt(0);
assertNotNull(sheetBack);
-
+
HSSFPatriarch patriarchBack = sheetBack.getDrawingPatriarch();
assertNotNull(patriarchBack);
-
+
List<HSSFShape> children = patriarchBack.getChildren();
assertEquals(4, children.size());
HSSFShape hssfShape = children.get(0);
@@ -843,7 +847,7 @@ public class TestDrawingShapes {
assertEquals(2, cAnchor.getCol2());
assertEquals(2, cAnchor.getRow1());
assertEquals(2, cAnchor.getRow2());
-
+
wbBack.close();
}
}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestEscherRecordFactory.java b/src/testcases/org/apache/poi/hssf/model/TestEscherRecordFactory.java
index a3776e5bdc..72e9e55941 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestEscherRecordFactory.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestEscherRecordFactory.java
@@ -17,17 +17,18 @@
package org.apache.poi.hssf.model;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.apache.poi.ddf.DefaultEscherRecordFactory.isContainer;
+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.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Random;
-import org.apache.poi.ddf.DefaultEscherRecordFactory;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherTextboxRecord;
import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -37,7 +38,7 @@ import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFTestHelper;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestEscherRecordFactory {
@@ -57,30 +58,30 @@ public class TestEscherRecordFactory {
@Test
public void testDetectContainer() {
Random rnd = new Random();
- assertTrue(DefaultEscherRecordFactory.isContainer((short) 0x0, EscherContainerRecord.DG_CONTAINER));
- assertTrue(DefaultEscherRecordFactory.isContainer((short) 0x0, EscherContainerRecord.SOLVER_CONTAINER));
- assertTrue(DefaultEscherRecordFactory.isContainer((short) 0x0, EscherContainerRecord.SP_CONTAINER));
- assertTrue(DefaultEscherRecordFactory.isContainer((short) 0x0, EscherContainerRecord.DGG_CONTAINER));
- assertTrue(DefaultEscherRecordFactory.isContainer((short) 0x0, EscherContainerRecord.BSTORE_CONTAINER));
- assertTrue(DefaultEscherRecordFactory.isContainer((short) 0x0, EscherContainerRecord.SPGR_CONTAINER));
+ assertTrue(isContainer((short) 0x0, EscherContainerRecord.DG_CONTAINER));
+ assertTrue(isContainer((short) 0x0, EscherContainerRecord.SOLVER_CONTAINER));
+ assertTrue(isContainer((short) 0x0, EscherContainerRecord.SP_CONTAINER));
+ assertTrue(isContainer((short) 0x0, EscherContainerRecord.DGG_CONTAINER));
+ assertTrue(isContainer((short) 0x0, EscherContainerRecord.BSTORE_CONTAINER));
+ assertTrue(isContainer((short) 0x0, EscherContainerRecord.SPGR_CONTAINER));
- for (Short i=EscherContainerRecord.DGG_CONTAINER; i<= EscherContainerRecord.SOLVER_CONTAINER; i++){
- assertTrue(DefaultEscherRecordFactory.isContainer(Integer.valueOf(rnd.nextInt(Short.MAX_VALUE)).shortValue(), i));
+ for (short i=EscherContainerRecord.DGG_CONTAINER; i<= EscherContainerRecord.SOLVER_CONTAINER; i++){
+ assertTrue(isContainer(Integer.valueOf(rnd.nextInt(Short.MAX_VALUE)).shortValue(), i));
}
- assertFalse(DefaultEscherRecordFactory.isContainer((short) 0x0, Integer.valueOf(EscherContainerRecord.DGG_CONTAINER - 1).shortValue()));
- assertFalse(DefaultEscherRecordFactory.isContainer((short) 0x0, Integer.valueOf(EscherContainerRecord.SOLVER_CONTAINER + 1).shortValue()));
+ assertFalse(isContainer((short) 0x0, Integer.valueOf(EscherContainerRecord.DGG_CONTAINER - 1).shortValue()));
+ assertFalse(isContainer((short) 0x0, Integer.valueOf(EscherContainerRecord.SOLVER_CONTAINER + 1).shortValue()));
- assertTrue(DefaultEscherRecordFactory.isContainer((short) 0x000F, Integer.valueOf(EscherContainerRecord.DGG_CONTAINER - 1).shortValue()));
- assertTrue(DefaultEscherRecordFactory.isContainer((short) 0xFFFF, Integer.valueOf(EscherContainerRecord.DGG_CONTAINER - 1).shortValue()));
- assertFalse(DefaultEscherRecordFactory.isContainer((short) 0x000C, Integer.valueOf(EscherContainerRecord.DGG_CONTAINER - 1).shortValue()));
- assertFalse(DefaultEscherRecordFactory.isContainer((short) 0xCCCC, Integer.valueOf(EscherContainerRecord.DGG_CONTAINER - 1).shortValue()));
- assertFalse(DefaultEscherRecordFactory.isContainer((short) 0x000F, EscherTextboxRecord.RECORD_ID));
- assertFalse(DefaultEscherRecordFactory.isContainer((short) 0xCCCC, EscherTextboxRecord.RECORD_ID));
+ assertTrue(isContainer((short) 0x000F, Integer.valueOf(EscherContainerRecord.DGG_CONTAINER - 1).shortValue()));
+ assertTrue(isContainer((short) 0xFFFF, Integer.valueOf(EscherContainerRecord.DGG_CONTAINER - 1).shortValue()));
+ assertFalse(isContainer((short) 0x000C, Integer.valueOf(EscherContainerRecord.DGG_CONTAINER - 1).shortValue()));
+ assertFalse(isContainer((short) 0xCCCC, Integer.valueOf(EscherContainerRecord.DGG_CONTAINER - 1).shortValue()));
+ assertFalse(isContainer((short) 0x000F, EscherTextboxRecord.RECORD_ID));
+ assertFalse(isContainer((short) 0xCCCC, EscherTextboxRecord.RECORD_ID));
}
@Test
- public void testDgContainerMustBeRootOfHSSFSheetEscherRecords() throws IOException {
+ public void testDgContainerMustBeRootOfHSSFSheetEscherRecords() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("47251.xls");
HSSFSheet sh = wb.getSheetAt(0);
InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
@@ -90,12 +91,14 @@ public class TestEscherRecordFactory {
byte[] dgBytes = toByteArray(dgRecords);
sh.getDrawingPatriarch();
EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
+ assertNotNull(agg);
assertTrue(agg.getEscherRecords().get(0) instanceof EscherContainerRecord);
assertEquals(EscherContainerRecord.DG_CONTAINER, agg.getEscherRecords().get(0).getRecordId());
assertEquals((short) 0x0, agg.getEscherRecords().get(0).getOptions());
agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
+ assertNotNull(agg);
byte[] dgBytesAfterSave = agg.serialize();
- assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
- assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
+ assertEquals(dgBytes.length, dgBytesAfterSave.length, "different size of drawing data before and after save");
+ assertArrayEquals(dgBytes, dgBytesAfterSave, "drawing data before and after save is different");
}
}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
index 5a88f460b8..db7f6f1862 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
@@ -17,11 +17,14 @@
package org.apache.poi.hssf.model;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.IOException;
import java.util.Locale;
@@ -48,7 +51,7 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the low level formula parser functionality. High level tests are to
@@ -61,7 +64,7 @@ public final class TestFormulaParser {
*/
/* package */ static Ptg[] parseFormula(String formula) {
Ptg[] result = HSSFFormulaParser.parse(formula, null);
- assertNotNull("Ptg array should not be null", result);
+ assertNotNull(result, "Ptg array should not be null");
return result;
}
private static String toFormulaString(Ptg[] ptgs) {
@@ -279,18 +282,18 @@ public final class TestFormulaParser {
String value = " hi ";
Ptg[] ptgs = parseFormula("\"" + value + "\"");
confirmTokenClasses(ptgs, StringPtg.class);
- assertEquals("ptg0 contains exact value", ((StringPtg) ptgs[0]).getValue(), value);
+ assertEquals(((StringPtg) ptgs[0]).getValue(), value, "ptg0 contains exact value");
}
@Test
public void testLookupAndMatchFunctionArgs() {
Ptg[] ptgs = parseFormula("lookup(A1, A3:A52, B3:B52)");
confirmTokenClasses(ptgs, RefPtg.class, AreaPtg.class, AreaPtg.class, FuncVarPtg.class);
- assertEquals("ptg0 has Value class", ptgs[0].getPtgClass(), Ptg.CLASS_VALUE);
+ assertEquals(ptgs[0].getPtgClass(), Ptg.CLASS_VALUE, "ptg0 has Value class");
ptgs = parseFormula("match(A1, A3:A52)");
confirmTokenClasses(ptgs, RefPtg.class, AreaPtg.class, FuncVarPtg.class);
- assertEquals("ptg0 has Value class", ptgs[0].getPtgClass(), Ptg.CLASS_VALUE);
+ assertEquals(ptgs[0].getPtgClass(), Ptg.CLASS_VALUE, "ptg0 has Value class");
}
/** bug 33160*/
@@ -394,63 +397,63 @@ public final class TestFormulaParser {
cell.setCellFormula("1.3E21/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "1.3E+21/3", formula);
+ assertEquals("1.3E+21/3", formula);
cell.setCellFormula("-1.3E21/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "-1.3E+21/3", formula);
+ assertEquals("-1.3E+21/3", formula);
cell.setCellFormula("1322E21/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "1.322E+24/3", formula);
+ assertEquals("1.322E+24/3", formula);
cell.setCellFormula("-1322E21/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "-1.322E+24/3", formula);
+ assertEquals("-1.322E+24/3", formula);
cell.setCellFormula("1.3E1/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "13/3", formula);
+ assertEquals("13/3", formula);
cell.setCellFormula("-1.3E1/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "-13/3", formula);
+ assertEquals("-13/3", formula);
cell.setCellFormula("1.3E-4/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "0.00013/3", formula);
+ assertEquals("0.00013/3", formula);
cell.setCellFormula("-1.3E-4/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "-0.00013/3", formula);
+ assertEquals("-0.00013/3", formula);
cell.setCellFormula("13E-15/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "0.000000000000013/3", formula);
+ assertEquals("0.000000000000013/3", formula);
cell.setCellFormula("-13E-15/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "-0.000000000000013/3", formula);
+ assertEquals("-0.000000000000013/3", formula);
cell.setCellFormula("1.3E3/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "1300/3", formula);
+ assertEquals("1300/3", formula);
cell.setCellFormula("-1.3E3/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "-1300/3", formula);
+ assertEquals("-1300/3", formula);
cell.setCellFormula("1300000000000000/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "1300000000000000/3", formula);
+ assertEquals("1300000000000000/3", formula);
cell.setCellFormula("-1300000000000000/3");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "-1300000000000000/3", formula);
+ assertEquals("-1300000000000000/3", formula);
cell.setCellFormula("-10E-1/3.1E2*4E3/3E4");
formula = cell.getCellFormula();
- assertEquals("Exponential formula string", "-1/310*4000/30000", formula);
+ assertEquals("-1/310*4000/30000", formula);
wb.close();
}
@@ -653,11 +656,10 @@ public final class TestFormulaParser {
private static void confirmTokenClasses(Ptg[] ptgs, Class<?>...expectedClasses) {
assertEquals(expectedClasses.length, ptgs.length);
for (int i = 0; i < expectedClasses.length; i++) {
- if(expectedClasses[i] != ptgs[i].getClass()) {
- fail("difference at token[" + i + "]: expected ("
- + expectedClasses[i].getName() + ") but got ("
- + ptgs[i].getClass().getName() + ")");
- }
+ assertEquals(expectedClasses[i], ptgs[i].getClass(),
+ "difference at token[" + i + "]: expected ("
+ + expectedClasses[i].getName() + ") but got ("
+ + ptgs[i].getClass().getName() + ")");
}
}
@@ -763,9 +765,7 @@ public final class TestFormulaParser {
HSSFCell cell = row.createCell(0);
cell.setCellFormula("right(\"test\"\"ing\", 3)");
String actualCellFormula = cell.getCellFormula();
- if ("RIGHT(\"test\"ing\",3)".equals(actualCellFormula)) {
- fail("Identified bug 28754b");
- }
+ assertNotEquals("RIGHT(\"test\"ing\",3)", actualCellFormula, "Identified bug 28754b");
assertEquals("RIGHT(\"test\"\"ing\",3)", actualCellFormula);
}
}
@@ -819,13 +819,8 @@ public final class TestFormulaParser {
}
private static void parseExpectedException(String formula) {
- try {
- parseFormula(formula);
- fail("Expected FormulaParseException: " + formula);
- } catch (FormulaParseException e) {
- // expected during successful test
- assertNotNull(e.getMessage());
- }
+ FormulaParseException e = assertThrows(FormulaParseException.class, () -> parseFormula(formula));
+ assertNotNull(e.getMessage());
}
@Test
@@ -838,9 +833,7 @@ public final class TestFormulaParser {
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellFormula("SUM(A32769:A32770)");
- if("SUM(A-32767:A-32766)".equals(cell.getCellFormula())) {
- fail("Identified bug 44539");
- }
+ assertNotEquals("SUM(A-32767:A-32766)", cell.getCellFormula(), "Identified bug 44539");
assertEquals("SUM(A32769:A32770)", cell.getCellFormula());
wb.close();
@@ -883,14 +876,10 @@ public final class TestFormulaParser {
new IntPtg(1),
DividePtg.instance,
};
- try {
- toFormulaString(ptgs);
- fail("Expected exception was not thrown");
- } catch (IllegalStateException e) {
- // expected during successful test
- assertTrue(e.getMessage().startsWith("Too few arguments supplied to operation"));
- }
+ IllegalStateException e = assertThrows(IllegalStateException.class, () -> toFormulaString(ptgs));
+ assertTrue(e.getMessage().startsWith("Too few arguments supplied to operation"));
}
+
/**
* Make sure that POI uses the right Func Ptg when encoding formulas. Functions with variable
* number of args should get FuncVarPtg, functions with fixed args should get FuncPtg.<p>
@@ -904,9 +893,7 @@ public final class TestFormulaParser {
Ptg[] ptgs = parseFormula("countif(A1:A2, 1)");
assertEquals(3, ptgs.length);
- if(ptgs[2] instanceof FuncVarPtg) {
- fail("Identified bug 44675");
- }
+ assertFalse(ptgs[2] instanceof FuncVarPtg, "Identified bug 44675");
confirmTokenClasses(ptgs, AreaPtg.class, IntPtg.class, FuncPtg.class);
confirmTokenClasses("sin(1)", IntPtg.class, FuncPtg.class);
@@ -921,34 +908,20 @@ public final class TestFormulaParser {
}
private static void confirmArgCountMsg(String formula, String expectedMessage) throws IOException {
- HSSFWorkbook book = new HSSFWorkbook();
- try {
- HSSFFormulaParser.parse(formula, book);
- fail("Didn't get parse exception as expected");
- } catch (FormulaParseException e) {
+ try (HSSFWorkbook book = new HSSFWorkbook()) {
+ FormulaParseException e = assertThrows(FormulaParseException.class, () -> HSSFFormulaParser.parse(formula, book));
confirmParseException(e, expectedMessage);
}
- book.close();
}
@Test
public void testParseErrorExpectedMsg() {
+ FormulaParseException e;
+ e = assertThrows(FormulaParseException.class, () -> parseFormula("round(3.14;2)"));
+ confirmParseException(e, "Parse error near char 10 ';' in specified formula 'round(3.14;2)'. Expected ',' or ')'");
- try {
- parseFormula("round(3.14;2)");
- fail("Didn't get parse exception as expected");
- } catch (FormulaParseException e) {
- confirmParseException(e,
- "Parse error near char 10 ';' in specified formula 'round(3.14;2)'. Expected ',' or ')'");
- }
-
- try {
- parseFormula(" =2+2");
- fail("Didn't get parse exception as expected");
- } catch (FormulaParseException e) {
- confirmParseException(e,
- "The specified formula ' =2+2' starts with an equals sign which is not allowed.");
- }
+ e = assertThrows(FormulaParseException.class, () -> parseFormula(" =2+2"));
+ confirmParseException(e, "The specified formula ' =2+2' starts with an equals sign which is not allowed.");
}
/**
@@ -972,36 +945,30 @@ public final class TestFormulaParser {
@Test
public void testNamedRangeThatLooksLikeCell() throws IOException {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet("Sheet1");
- HSSFName name = wb.createName();
- name.setRefersToFormula("Sheet1!B1");
- name.setNameName("pfy1");
-
- Ptg[] ptgs;
- try {
- ptgs = HSSFFormulaParser.parse("count(pfy1)", wb);
- } catch (IllegalArgumentException e) {
- if (e.getMessage().equals("Specified colIx (1012) is out of range")) {
- fail("Identified bug 45354");
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ HSSFSheet sheet = wb.createSheet("Sheet1");
+ HSSFName name = wb.createName();
+ name.setRefersToFormula("Sheet1!B1");
+ name.setNameName("pfy1");
+
+ Ptg[] ptgs;
+ try {
+ ptgs = HSSFFormulaParser.parse("count(pfy1)", wb);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage().equals("Specified colIx (1012) is out of range")) {
+ fail("Identified bug 45354");
+ }
+ throw e;
}
- wb.close();
- throw e;
- }
- confirmTokenClasses(ptgs, NamePtg.class, FuncVarPtg.class);
-
- HSSFCell cell = sheet.createRow(0).createCell(0);
- cell.setCellFormula("count(pfy1)");
- assertEquals("COUNT(pfy1)", cell.getCellFormula());
- try {
- cell.setCellFormula("count(pf1)");
- fail("Expected formula parse execption");
- } catch (FormulaParseException e) {
- confirmParseException(e,
- "Specified named range 'pf1' does not exist in the current workbook.");
+ confirmTokenClasses(ptgs, NamePtg.class, FuncVarPtg.class);
+
+ HSSFCell cell = sheet.createRow(0).createCell(0);
+ cell.setCellFormula("count(pfy1)");
+ assertEquals("COUNT(pfy1)", cell.getCellFormula());
+ FormulaParseException e = assertThrows(FormulaParseException.class, () -> cell.setCellFormula("count(pf1)"));
+ confirmParseException(e, "Specified named range 'pf1' does not exist in the current workbook.");
+ cell.setCellFormula("count(fp1)"); // plain cell ref, col is in range
}
- cell.setCellFormula("count(fp1)"); // plain cell ref, col is in range
- wb.close();
}
@Test
@@ -1014,9 +981,7 @@ public final class TestFormulaParser {
ptgs = HSSFFormulaParser.parse("Sheet1!A10:A40000", book);
aptg = (AreaI) ptgs[0];
- if (aptg.getLastRow() == -25537) {
- fail("Identified bug 45358");
- }
+ assertNotEquals(-25537, aptg.getLastRow(), "Identified bug 45358");
assertEquals(39999, aptg.getLastRow());
ptgs = HSSFFormulaParser.parse("Sheet1!A10:A65536", book);
@@ -1050,10 +1015,8 @@ public final class TestFormulaParser {
ptgs = parseFormula("MAX({\"5\"},3)");
confirmTokenClasses(ptgs, ArrayPtg.class, IntPtg.class, FuncVarPtg.class);
Object element = ((ArrayPtg)ptgs[0]).getTokenArrayValues()[0][0];
- if (element instanceof UnicodeString) {
- // this would cause ClassCastException below
- fail("Wrong encoding of array element value");
- }
+ // this would cause ClassCastException below
+ assertFalse(element instanceof UnicodeString, "Wrong encoding of array element value");
assertEquals(String.class, element.getClass());
// make sure the formula encodes OK
@@ -1354,28 +1317,27 @@ public final class TestFormulaParser {
@Test
public void testRangeFuncOperand_bug46951() throws IOException {
- HSSFWorkbook wb = new HSSFWorkbook();
- Ptg[] ptgs;
- try {
- ptgs = HSSFFormulaParser.parse("SUM(C1:OFFSET(C1,0,B1))", wb);
- } catch (RuntimeException e) {
- if (e.getMessage().equals("Specified named range 'OFFSET' does not exist in the current workbook.")) {
- fail("Identified bug 46951");
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ Ptg[] ptgs;
+ try {
+ ptgs = HSSFFormulaParser.parse("SUM(C1:OFFSET(C1,0,B1))", wb);
+ } catch (RuntimeException e) {
+ if (e.getMessage().equals("Specified named range 'OFFSET' does not exist in the current workbook.")) {
+ fail("Identified bug 46951");
+ }
+ throw e;
}
- wb.close();
- throw e;
+ confirmTokenClasses(ptgs,
+ MemFuncPtg.class, // [len=23]
+ RefPtg.class, // [C1]
+ RefPtg.class, // [C1]
+ IntPtg.class, // [0]
+ RefPtg.class, // [B1]
+ FuncVarPtg.class, // [OFFSET nArgs=3]
+ RangePtg.class, //
+ AttrPtg.class // [sum ]
+ );
}
- confirmTokenClasses(ptgs,
- MemFuncPtg.class, // [len=23]
- RefPtg.class, // [C1]
- RefPtg.class, // [C1]
- IntPtg.class, // [0]
- RefPtg.class, // [B1]
- FuncVarPtg.class, // [OFFSET nArgs=3]
- RangePtg.class, //
- AttrPtg.class // [sum ]
- );
- wb.close();
}
@Test
@@ -1507,13 +1469,8 @@ public final class TestFormulaParser {
}
private static void confirmParseError(HSSFWorkbook wb, String formula, String expectedMessage) {
-
- try {
- HSSFFormulaParser.parse(formula, wb);
- fail("Expected formula parse execption");
- } catch (FormulaParseException e) {
- confirmParseException(e, expectedMessage);
- }
+ FormulaParseException e = assertThrows(FormulaParseException.class, () -> HSSFFormulaParser.parse(formula, wb));
+ confirmParseException(e, expectedMessage);
}
/**
@@ -1524,29 +1481,27 @@ public final class TestFormulaParser {
public void testParseComplexName() throws IOException {
// Mock up a spreadsheet to match the critical details of the sample
- HSSFWorkbook wb = new HSSFWorkbook();
- wb.createSheet("Sheet1");
- HSSFName definedName = wb.createName();
- definedName.setNameName("foo");
- definedName.setRefersToFormula("Sheet1!B2");
-
- // Set the complex flag - POI doesn't usually manipulate this flag
- NameRecord nameRec = TestHSSFName.getNameRecord(definedName);
- nameRec.setOptionFlag((short)0x10); // 0x10 -> complex
-
- Ptg[] result;
- try {
- result = HSSFFormulaParser.parse("1+foo", wb);
- } catch (FormulaParseException e) {
- if (e.getMessage().equals("Specified name 'foo' is not a range as expected.")) {
- fail("Identified bug 47078c");
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ wb.createSheet("Sheet1");
+ HSSFName definedName = wb.createName();
+ definedName.setNameName("foo");
+ definedName.setRefersToFormula("Sheet1!B2");
+
+ // Set the complex flag - POI doesn't usually manipulate this flag
+ NameRecord nameRec = TestHSSFName.getNameRecord(definedName);
+ nameRec.setOptionFlag((short) 0x10); // 0x10 -> complex
+
+ Ptg[] result;
+ try {
+ result = HSSFFormulaParser.parse("1+foo", wb);
+ } catch (FormulaParseException e) {
+ if (e.getMessage().equals("Specified name 'foo' is not a range as expected.")) {
+ fail("Identified bug 47078c");
+ }
+ throw e;
}
- wb.close();
- throw e;
+ confirmTokenClasses(result, IntPtg.class, NamePtg.class, AddPtg.class);
}
- confirmTokenClasses(result, IntPtg.class, NamePtg.class, AddPtg.class);
-
- wb.close();
}
/**
@@ -1562,23 +1517,16 @@ public final class TestFormulaParser {
String leadingZeroCellRef = "B000001"; // this should get parsed as "B1"
HSSFWorkbook wb = new HSSFWorkbook();
- try {
- HSSFFormulaParser.parse(badCellRef, wb);
- fail("Identified bug 47312b - Shouldn't be able to parse cell ref '"
- + badCellRef + "'.");
- } catch (FormulaParseException e) {
- // expected during successful test
- confirmParseException(e, "Specified named range '"
- + badCellRef + "' does not exist in the current workbook.");
- }
+ FormulaParseException e = assertThrows(FormulaParseException.class, () -> HSSFFormulaParser.parse(badCellRef, wb),
+ "Identified bug 47312b - Shouldn't be able to parse cell ref '" + badCellRef + "'.");
+ confirmParseException(e, "Specified named range '" + badCellRef + "' does not exist in the current workbook.");
Ptg[] ptgs;
try {
ptgs = HSSFFormulaParser.parse(leadingZeroCellRef, wb);
assertEquals("B1", ptgs[0].toFormulaString());
- } catch (FormulaParseException e) {
- confirmParseException(e, "Specified named range '"
- + leadingZeroCellRef + "' does not exist in the current workbook.");
+ } catch (FormulaParseException e2) {
+ confirmParseException(e2, "Specified named range '" + leadingZeroCellRef + "' does not exist in the current workbook.");
// close but no cigar
fail("Identified bug 47312c - '" + leadingZeroCellRef + "' should parse as 'B1'.");
}
@@ -1601,7 +1549,7 @@ public final class TestFormulaParser {
public void test57196_Formula() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
Ptg[] ptgs = HSSFFormulaParser.parse("DEC2HEX(HEX2DEC(O8)-O2+D2)", wb, FormulaType.CELL, -1);
- assertNotNull("Ptg array should not be null", ptgs);
+ assertNotNull(ptgs, "Ptg array should not be null");
confirmTokenClasses(ptgs,
NameXPtg.class, // ??
diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
index aba91ad718..d948695620 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.model;
-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;
@@ -30,7 +30,7 @@ import org.apache.poi.ss.formula.ptg.NamePtg;
import org.apache.poi.ss.formula.ptg.Ptg;
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 the low level formula parser functionality,
@@ -70,7 +70,7 @@ public final class TestFormulaParserEval {
*/
private static void confirmParseFormula(HSSFWorkbook workbook) {
Ptg[] ptgs = HSSFFormulaParser.parse("SUM(testName)", workbook);
- assertEquals("two tokens expected, got " + ptgs.length, 2, ptgs.length);
+ assertEquals(2, ptgs.length, "two tokens expected, got " + ptgs.length);
assertEquals(NamePtg.class, ptgs[0].getClass());
assertEquals(AttrPtg.class, ptgs[1].getClass());
}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java
index 6897ccb88c..42f650a549 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.model;
-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.ptg.AddPtg;
import org.apache.poi.ss.formula.ptg.AttrPtg;
@@ -33,7 +33,7 @@ import org.apache.poi.ss.formula.ptg.NotEqualPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.RefPtg;
import org.apache.poi.ss.formula.ptg.StringPtg;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests <tt>FormulaParser</tt> specifically with respect to IF() functions
@@ -49,7 +49,7 @@ public final class TestFormulaParserIf {
private static void confirmAttrData(Ptg[] ptgs, int i, int expectedData) {
Ptg ptg = ptgs[i];
- assertTrue("Token[" + i + "] was not AttrPtg as expected", ptg instanceof AttrPtg);
+ assertTrue(ptg instanceof AttrPtg, "Token[" + i + "] was not AttrPtg as expected");
AttrPtg attrPtg = (AttrPtg) ptg;
assertEquals(expectedData, attrPtg.getData());
}
@@ -164,24 +164,24 @@ public final class TestFormulaParserIf {
Ptg[] ptgs = parseFormula("IF(3>=1,\"*\",IF(4<>1,\"first\",\"second\"))");
assertEquals(17, ptgs.length);
- assertEquals("6th Ptg is not a goto (Attr) ptg",AttrPtg.class,ptgs[5].getClass());
- assertEquals("9th Ptg is not a not equal ptg",NotEqualPtg.class,ptgs[8].getClass());
- assertEquals("15th Ptg is not the inner IF variable function ptg",FuncVarPtg.class,ptgs[14].getClass());
+ assertEquals(AttrPtg.class, ptgs[5].getClass(), "6th Ptg is not a goto (Attr) ptg");
+ assertEquals(NotEqualPtg.class, ptgs[8].getClass(), "9th Ptg is not a not equal ptg");
+ assertEquals(FuncVarPtg.class, ptgs[14].getClass(), "15th Ptg is not the inner IF variable function ptg");
}
@Test
public void testSimpleLogical() {
Ptg[] ptgs = parseFormula("IF(A1<A2,B1,B2)");
assertEquals(9, ptgs.length);
- assertEquals("3rd Ptg is less than", LessThanPtg.class, ptgs[2].getClass());
+ assertEquals(LessThanPtg.class, ptgs[2].getClass(), "3rd Ptg is less than");
}
@Test
public void testParenIf() {
Ptg[] ptgs = parseFormula("IF((A1+A2)<=3,\"yes\",\"no\")");
assertEquals(12, ptgs.length);
- assertEquals("6th Ptg is less than equal",LessEqualPtg.class,ptgs[5].getClass());
- assertEquals("11th Ptg is not a goto (Attr) ptg",AttrPtg.class,ptgs[10].getClass());
+ assertEquals(LessEqualPtg.class, ptgs[5].getClass(), "6th Ptg is less than equal");
+ assertEquals(AttrPtg.class, ptgs[10].getClass(), "11th Ptg is not a goto (Attr) ptg");
}
@Test
@@ -200,7 +200,7 @@ public final class TestFormulaParserIf {
assertEquals("Y", y.getValue());
assertEquals("N", n.getValue());
assertEquals("IF", funif.toFormulaString());
- assertTrue("tAttrSkip ptg exists", goto1.isSkip());
+ assertTrue(goto1.isSkip(), "tAttrSkip ptg exists");
}
/**
@@ -211,11 +211,11 @@ public final class TestFormulaParserIf {
Ptg[] ptgs = parseFormula("IF(A1=B1,AVERAGE(A1:B1),AVERAGE(A2:B2))");
assertEquals(11, ptgs.length);
- assertTrue("IF Attr set correctly", (ptgs[3] instanceof AttrPtg));
+ assertTrue((ptgs[3] instanceof AttrPtg), "IF Attr set correctly");
AttrPtg ifFunc = (AttrPtg)ptgs[3];
- assertTrue("It is not an if", ifFunc.isOptimizedIf());
+ assertTrue(ifFunc.isOptimizedIf(), "It is not an if");
- assertTrue("Average Function set correctly", (ptgs[5] instanceof FuncVarPtg));
+ assertTrue((ptgs[5] instanceof FuncVarPtg), "Average Function set correctly");
}
@Test
@@ -223,16 +223,16 @@ public final class TestFormulaParserIf {
Ptg[] ptgs = parseFormula("IF(1=1,10)");
assertEquals(7, ptgs.length);
- assertTrue("IF Attr set correctly", (ptgs[3] instanceof AttrPtg));
+ assertTrue((ptgs[3] instanceof AttrPtg), "IF Attr set correctly");
AttrPtg ifFunc = (AttrPtg)ptgs[3];
- assertTrue("It is not an if", ifFunc.isOptimizedIf());
+ assertTrue(ifFunc.isOptimizedIf(), "It is not an if");
- assertTrue("Single Value is not an IntPtg", (ptgs[4] instanceof IntPtg));
+ assertTrue((ptgs[4] instanceof IntPtg), "Single Value is not an IntPtg");
IntPtg intPtg = (IntPtg)ptgs[4];
- assertEquals("Result", (short)10, intPtg.getValue());
+ assertEquals((short)10, intPtg.getValue(), "Result");
- assertTrue("Ptg is not a Variable Function", (ptgs[6] instanceof FuncVarPtg));
+ assertTrue((ptgs[6] instanceof FuncVarPtg), "Ptg is not a Variable Function");
FuncVarPtg funcPtg = (FuncVarPtg)ptgs[6];
- assertEquals("Arguments", 2, funcPtg.getNumberOfOperands());
+ assertEquals(2, funcPtg.getNumberOfOperands(), "Arguments");
}
}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java b/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java
index c98d42cc35..c0bcf375ed 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java
@@ -17,11 +17,11 @@
package org.apache.poi.hssf.model;
-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.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.assertTrue;
import org.apache.poi.ddf.EscherChildAnchorRecord;
import org.apache.poi.ddf.EscherClientAnchorRecord;
@@ -39,7 +39,7 @@ import org.apache.poi.hssf.usermodel.HSSFSimpleShape;
import org.apache.poi.hssf.usermodel.HSSFTestHelper;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestHSSFAnchor {
@@ -326,10 +326,10 @@ public class TestHSSFAnchor {
@Test
public void testNullReferenceIsFalse() {
HSSFClientAnchor clientAnchor = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7);
- assertNotNull("Passing null to equals should return false", clientAnchor);
+ assertNotNull(clientAnchor, "Passing null to equals should return false");
HSSFChildAnchor childAnchor = new HSSFChildAnchor(0, 1, 2, 3);
- assertNotNull("Passing null to equals should return false", childAnchor);
+ assertNotNull(childAnchor, "Passing null to equals should return false");
}
@Test
diff --git a/src/testcases/org/apache/poi/hssf/model/TestLinkTable.java b/src/testcases/org/apache/poi/hssf/model/TestLinkTable.java
index 3ff44152ac..7c7f7ad05b 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestLinkTable.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestLinkTable.java
@@ -17,12 +17,12 @@
package org.apache.poi.hssf.model;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-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.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.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.Collections;
@@ -44,7 +44,7 @@ import org.apache.poi.hssf.record.SupBookRecord;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.ptg.NameXPtg;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link LinkTable}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java b/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java
index ec2158d315..8210d140df 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.model;
-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.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 org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
@@ -31,8 +31,8 @@ import org.apache.poi.ss.formula.functions.MatrixFunction;
import org.apache.poi.ss.formula.ptg.AbstractFunctionPtg;
import org.apache.poi.ss.formula.ptg.FuncVarPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* Tests specific formula examples in <tt>OperandClassTransformer</tt>.
@@ -41,7 +41,7 @@ public final class TestOperandClassTransformer {
private static Ptg[] parseFormula(String formula) {
Ptg[] result = HSSFFormulaParser.parse(formula, null);
- assertNotNull("Ptg array should not be null", result);
+ assertNotNull(result, "Ptg array should not be null");
return result;
}
@@ -79,7 +79,7 @@ public final class TestOperandClassTransformer {
* This test has been added but disabled in order to document this issue.
*/
@Test
- @Ignore
+ @Disabled
public void testIndexPi1() {
String formula = "INDEX(PI(),1)";
Ptg[] ptgs = parseFormula(formula);
@@ -144,7 +144,7 @@ public final class TestOperandClassTransformer {
private void confirmTokenClass(Ptg[] ptgs, int i, byte operandClass) {
Ptg ptg = ptgs[i];
- assertFalse("ptg[" + i + "] is a base token", ptg.isBaseToken());
+ assertFalse(ptg.isBaseToken(), "ptg[" + i + "] is a base token");
assertEquals(operandClass, ptg.getPtgClass());
}
}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestRVA.java b/src/testcases/org/apache/poi/hssf/model/TestRVA.java
index 20bc884622..8ca28bb6fc 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestRVA.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestRVA.java
@@ -17,12 +17,13 @@
package org.apache.poi.hssf.model;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+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.stream.Stream;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.FormulaExtractor;
@@ -34,19 +35,16 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.formula.ptg.AttrPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.usermodel.CellType;
-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 'operand class' transformation performed by
* <tt>OperandClassTransformer</tt> by comparing its results with those
* directly produced by Excel (in a sample spreadsheet).
*/
-@RunWith(Parameterized.class)
public final class TestRVA {
private static final String NEW_LINE = System.getProperty("line.separator");
@@ -54,25 +52,19 @@ public final class TestRVA {
private static HSSFWorkbook workbook;
- @Parameter(value = 0)
- public HSSFCell formulaCell;
- @Parameter(value = 1)
- public String formula;
-
- @AfterClass
+ @AfterAll
public static void closeResource() throws Exception {
workbook.close();
poifs.close();
}
- @Parameters(name="{1}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
poifs = new POIFSFileSystem(HSSFTestDataSamples.getSampleFile("testRVA.xls"), true);
workbook = new HSSFWorkbook(poifs);
HSSFSheet sheet = workbook.getSheetAt(0);
- List<Object[]> data = new ArrayList<>();
-
+ List<Arguments> data = new ArrayList<>();
+
for (int rowIdx = 0; true; rowIdx++) {
HSSFRow row = sheet.getRow(rowIdx);
if (row == null) {
@@ -84,29 +76,29 @@ public final class TestRVA {
}
String formula = cell.getCellFormula();
- data.add(new Object[]{cell,formula});
+ data.add(Arguments.of(cell,formula));
}
-
- return data;
+
+ return data.stream();
}
-
- @Test
- public void confirmCell() {
+
+ @ParameterizedTest
+ @MethodSource("data")
+ public void confirmCell(HSSFCell formulaCell, String formula) {
Ptg[] excelPtgs = FormulaExtractor.getPtgs(formulaCell);
Ptg[] poiPtgs = HSSFFormulaParser.parse(formula, workbook);
int nExcelTokens = excelPtgs.length;
int nPoiTokens = poiPtgs.length;
if (nExcelTokens != nPoiTokens) {
- if (nExcelTokens == nPoiTokens + 1 && excelPtgs[0].getClass() == AttrPtg.class) {
- // compensate for missing tAttrVolatile, which belongs in any formula
- // involving OFFSET() et al. POI currently does not insert where required
- Ptg[] temp = new Ptg[nExcelTokens];
- temp[0] = excelPtgs[0];
- System.arraycopy(poiPtgs, 0, temp, 1, nPoiTokens);
- poiPtgs = temp;
- } else {
- fail("Expected " + nExcelTokens + " tokens but got " + nPoiTokens);
- }
+ assertTrue(nExcelTokens == nPoiTokens + 1 && excelPtgs[0].getClass() == AttrPtg.class,
+ "Expected " + nExcelTokens + " tokens but got " + nPoiTokens);
+
+ // compensate for missing tAttrVolatile, which belongs in any formula
+ // involving OFFSET() et al. POI currently does not insert where required
+ Ptg[] temp = new Ptg[nExcelTokens];
+ temp[0] = excelPtgs[0];
+ System.arraycopy(poiPtgs, 0, temp, 1, nPoiTokens);
+ poiPtgs = temp;
}
boolean hasMismatch = false;
StringBuilder sb = new StringBuilder();
diff --git a/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java b/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java
index bf1fce7996..aa9b4c4c6a 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java
@@ -17,10 +17,11 @@
package org.apache.poi.hssf.model;
-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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays;
@@ -31,7 +32,7 @@ import org.apache.poi.hssf.record.UnknownRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link RowBlocksReader}
@@ -51,10 +52,9 @@ public final class TestRowBlocksReader {
};
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
RowBlocksReader rbr = new RowBlocksReader(rs);
- if (rs.peekNextClass() == WindowTwoRecord.class) {
- // Should have stopped at the SXVIEW record
- fail("Identified bug 46280b");
- }
+ assertNotEquals(WindowTwoRecord.class, rs.peekNextClass(),
+ "Should have stopped at the SXVIEW record - Identified bug 46280b");
+
RecordStream rbStream = rbr.getPlainRecordStream();
assertEquals(inRecs[0], rbStream.getNext());
assertEquals(inRecs[1], rbStream.getNext());
diff --git a/src/testcases/org/apache/poi/hssf/model/TestSheet.java b/src/testcases/org/apache/poi/hssf/model/TestSheet.java
index 8042be6e0e..bdc27459c6 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestSheet.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestSheet.java
@@ -17,12 +17,13 @@
package org.apache.poi.hssf.model;
-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.util.ArrayList;
import java.util.Arrays;
@@ -44,7 +45,7 @@ import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit test for the {@link InternalSheet} class.
@@ -112,7 +113,7 @@ public final class TestSheet {
for (int n = 0; n < regionsToAdd; n++)
{
int index = sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
- assertEquals("Merged region index expected to be " + n + " got " + index, index, n);
+ assertEquals(index, n, "Merged region index expected to be " + n + " got " + index);
}
//test all the regions were indeed added
@@ -127,23 +128,16 @@ public final class TestSheet {
if ((regionsToAdd % 1027) != 0) {
recordsExpected++;
}
- assertEquals("The " + regionsToAdd + " merged regions should have been spread out over "
- + recordsExpected + " records, not " + recordsAdded, recordsAdded, recordsExpected);
+ assertEquals(recordsAdded, recordsExpected,
+ "The " + regionsToAdd + " merged regions should have been spread out over "
+ + recordsExpected + " records, not " + recordsAdded);
// Check we can't add one with invalid date
- try {
- sheet.addMergedRegion(10, (short)10, 9, (short)12);
- fail("Expected an exception to occur");
- } catch(IllegalArgumentException e) {
- // occurs during successful test
- assertEquals("The 'to' row (9) must not be less than the 'from' row (10)", e.getMessage());
- }
- try {
- sheet.addMergedRegion(10, (short)10, 12, (short)9);
- fail("Expected an exception to occur");
- } catch(IllegalArgumentException e) {
- // occurs during successful test
- assertEquals("The 'to' col (9) must not be less than the 'from' col (10)", e.getMessage());
- }
+ IllegalArgumentException e;
+ e = assertThrows(IllegalArgumentException.class, () -> sheet.addMergedRegion(10, (short)10, 9, (short)12));
+ assertEquals("The 'to' row (9) must not be less than the 'from' row (10)", e.getMessage());
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheet.addMergedRegion(10, (short)10, 12, (short)9));
+ assertEquals("The 'to' col (9) must not be less than the 'from' col (10)", e.getMessage());
}
@Test
@@ -162,12 +156,12 @@ public final class TestSheet {
{
sheet.removeMergedRegion(0);
//assert they have been deleted
- assertEquals("Num of regions", regionsToAdd - n - 1, sheet.getNumMergedRegions());
+ assertEquals(regionsToAdd - n - 1, sheet.getNumMergedRegions(), "Num of regions");
}
// merge records are removed from within the MergedCellsTable,
// so the sheet record count should not change
- assertEquals("Sheet Records", nSheetRecords, sheet.getRecords().size());
+ assertEquals(nSheetRecords, sheet.getRecords().size(), "Sheet Records");
}
/**
@@ -199,7 +193,7 @@ public final class TestSheet {
//stub object to throw off list INDEX operations
sheet.removeMergedRegion(0);
- assertEquals("Should be no more merged regions", 0, sheet.getNumMergedRegions());
+ assertEquals(0, sheet.getNumMergedRegions(), "Should be no more merged regions");
}
// @Test
@@ -233,7 +227,7 @@ public final class TestSheet {
records.add(EOFRecord.instance);
InternalSheet sheet = createSheet(records);
- assertNotNull("Row [2] was skipped", sheet.getRow(2));
+ assertNotNull(sheet.getRow(2), "Row [2] was skipped");
}
/**
@@ -249,21 +243,21 @@ public final class TestSheet {
PageSettingsBlock sheet = worksheet.getPageSettings();
sheet.setRowBreak(0, colFrom, colTo);
- assertTrue("no row break at 0", sheet.isRowBroken(0));
- assertEquals("1 row break available", 1, sheet.getNumRowBreaks());
+ assertTrue(sheet.isRowBroken(0), "no row break at 0");
+ assertEquals(1, sheet.getNumRowBreaks(), "1 row break available");
sheet.setRowBreak(0, colFrom, colTo);
sheet.setRowBreak(0, colFrom, colTo);
- assertTrue("no row break at 0", sheet.isRowBroken(0));
- assertEquals("1 row break available", 1, sheet.getNumRowBreaks());
+ assertTrue(sheet.isRowBroken(0), "no row break at 0");
+ assertEquals(1, sheet.getNumRowBreaks(), "1 row break available");
sheet.setRowBreak(10, colFrom, colTo);
sheet.setRowBreak(11, colFrom, colTo);
- assertTrue("no row break at 10", sheet.isRowBroken(10));
- assertTrue("no row break at 11", sheet.isRowBroken(11));
- assertEquals("3 row break available", 3, sheet.getNumRowBreaks());
+ assertTrue(sheet.isRowBroken(10), "no row break at 10");
+ assertTrue(sheet.isRowBroken(11), "no row break at 11");
+ assertEquals(3, sheet.getNumRowBreaks(), "3 row break available");
boolean is10 = false;
@@ -272,24 +266,24 @@ public final class TestSheet {
int[] rowBreaks = sheet.getRowBreaks();
for (int main : rowBreaks) {
- if (main != 0 && main != 10 && main != 11) fail("Invalid page break");
+ assertTrue(main == 0 || main == 10 || main == 11, "Invalid page break");
if (main == 0) is0 = true;
- if (main == 10) is10= true;
+ if (main == 10) is10 = true;
if (main == 11) is11 = true;
}
- assertTrue("one of the breaks didnt make it", is0 && is10 && is11);
+ assertTrue(is0 && is10 && is11, "one of the breaks didnt make it");
sheet.removeRowBreak(11);
- assertFalse("row should be removed", sheet.isRowBroken(11));
+ assertFalse(sheet.isRowBroken(11), "row should be removed");
sheet.removeRowBreak(0);
- assertFalse("row should be removed", sheet.isRowBroken(0));
+ assertFalse(sheet.isRowBroken(0), "row should be removed");
sheet.removeRowBreak(10);
- assertFalse("row should be removed", sheet.isRowBroken(10));
+ assertFalse(sheet.isRowBroken(10), "row should be removed");
- assertEquals("no more breaks", 0, sheet.getNumRowBreaks());
+ assertEquals(0, sheet.getNumRowBreaks(), "no more breaks");
}
/**
@@ -305,22 +299,22 @@ public final class TestSheet {
PageSettingsBlock sheet = worksheet.getPageSettings();
sheet.setColumnBreak((short)0, rowFrom, rowTo);
- assertTrue("no col break at 0", sheet.isColumnBroken(0));
- assertEquals("1 col break available", 1, sheet.getNumColumnBreaks());
+ assertTrue(sheet.isColumnBroken(0), "no col break at 0");
+ assertEquals(1, sheet.getNumColumnBreaks(), "1 col break available");
sheet.setColumnBreak((short)0, rowFrom, rowTo);
- assertTrue("no col break at 0", sheet.isColumnBroken(0));
- assertEquals("1 col break available", 1, sheet.getNumColumnBreaks());
+ assertTrue(sheet.isColumnBroken(0), "no col break at 0");
+ assertEquals(1, sheet.getNumColumnBreaks(), "1 col break available");
sheet.setColumnBreak((short)1, rowFrom, rowTo);
sheet.setColumnBreak((short)10, rowFrom, rowTo);
sheet.setColumnBreak((short)15, rowFrom, rowTo);
- assertTrue("no col break at 1", sheet.isColumnBroken(1));
- assertTrue("no col break at 10", sheet.isColumnBroken(10));
- assertTrue("no col break at 15", sheet.isColumnBroken(15));
- assertEquals("4 col break available", 4, sheet.getNumColumnBreaks());
+ assertTrue(sheet.isColumnBroken(1), "no col break at 1");
+ assertTrue(sheet.isColumnBroken(10), "no col break at 10");
+ assertTrue(sheet.isColumnBroken(15), "no col break at 15");
+ assertEquals(4, sheet.getNumColumnBreaks(), "4 col break available");
boolean is10 = false;
boolean is0 = false;
@@ -329,28 +323,28 @@ public final class TestSheet {
int[] colBreaks = sheet.getColumnBreaks();
for (int main : colBreaks) {
- if (main != 0 && main != 1 && main != 10 && main != 15) fail("Invalid page break");
+ assertTrue(main == 0 || main == 1 || main == 10 || main == 15, "Invalid page break");
if (main == 0) is0 = true;
if (main == 1) is1 = true;
if (main == 10) is10= true;
if (main == 15) is15 = true;
}
- assertTrue("one of the breaks didnt make it", is0 && is1 && is10 && is15);
+ assertTrue(is0 && is1 && is10 && is15, "one of the breaks didnt make it");
sheet.removeColumnBreak(15);
- assertFalse("column break should not be there", sheet.isColumnBroken(15));
+ assertFalse(sheet.isColumnBroken(15), "column break should not be there");
sheet.removeColumnBreak(0);
- assertFalse("column break should not be there", sheet.isColumnBroken(0));
+ assertFalse(sheet.isColumnBroken(0), "column break should not be there");
sheet.removeColumnBreak(1);
- assertFalse("column break should not be there", sheet.isColumnBroken(1));
+ assertFalse(sheet.isColumnBroken(1), "column break should not be there");
sheet.removeColumnBreak(10);
- assertFalse("column break should not be there", sheet.isColumnBroken(10));
+ assertFalse(sheet.isColumnBroken(10), "column break should not be there");
- assertEquals("no more breaks", 0, sheet.getNumColumnBreaks());
+ assertEquals(0, sheet.getNumColumnBreaks(), "no more breaks");
}
/**
@@ -447,7 +441,7 @@ public final class TestSheet {
sheet.visitContainedRecords(r -> {
int estimatedSize = r.getRecordSize();
int serializedSize = r.serialize(0, buf);
- assertEquals("serialized size mismatch for record (" + r.getClass().getName() + ")", estimatedSize, serializedSize);
+ assertEquals(estimatedSize, serializedSize, "serialized size mismatch for record (" + r.getClass().getName() + ")");
totalSize[0] += estimatedSize;
}, 0);
assertEquals(90, totalSize[0]);
@@ -540,17 +534,13 @@ public final class TestSheet {
@Test
public void testMisplacedMergedCellsRecords_bug45699() throws Exception {
- HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex45698-22488.xls");
-
- HSSFSheet sheet = wb.getSheetAt(0);
- HSSFRow row = sheet.getRow(3);
- HSSFCell cell = row.getCell(4);
- if (cell == null) {
- fail("Identified bug 45699");
+ try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex45698-22488.xls")) {
+ HSSFSheet sheet = wb.getSheetAt(0);
+ HSSFRow row = sheet.getRow(3);
+ HSSFCell cell = row.getCell(4);
+ assertNotNull(cell, "Identified bug 45699");
+ assertEquals("Informations", cell.getRichStringCellValue().getString());
}
- assertEquals("Informations", cell.getRichStringCellValue().getString());
-
- wb.close();
}
/**
* In 3.1, setting margins between creating first row and first cell caused an exception.
diff --git a/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java b/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java
index c0ef0fd7dc..974a336553 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java
@@ -17,11 +17,11 @@
package org.apache.poi.hssf.model;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.poi.hssf.record.ColumnInfoRecord;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestSheetAdditional {
@Test
diff --git a/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java
index bc8db67c85..ee9b06d0fd 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java
@@ -17,12 +17,12 @@
package org.apache.poi.hssf.model;
-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.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.assertTrue;
import java.io.IOException;
@@ -36,7 +36,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;
/**
* Unit test for the Workbook class.
@@ -161,15 +161,13 @@ public final class TestWorkbook {
InternalWorkbook iwb = TestHSSFWorkbook.getInternalWorkbook(wb);
int oldRecordsCount = iwb.getNumRecords();
- //System.out.println("records count = " + oldRecordsCount);
- assertEquals("records count", 68, oldRecordsCount);
+ assertEquals(68, oldRecordsCount, "records count");
WriteAccessRecord writeAccess = iwb.getWriteAccess();
assertNotNull(writeAccess);
assertEquals(WriteAccessRecord.sid, writeAccess.getSid());
int newRecordsCount = iwb.getNumRecords();
- //System.out.println("records count after 'getWriteAccess' = " + newRecordsCount);
- assertEquals("records count after getWriteAccess", oldRecordsCount, newRecordsCount);
+ assertEquals(oldRecordsCount, newRecordsCount, "records count after getWriteAccess");
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
deleted file mode 100644
index e32816756c..0000000000
--- a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
+++ /dev/null
@@ -1,96 +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.hssf.record;
-
-import org.apache.poi.hssf.record.aggregates.AllRecordAggregateTests;
-import org.apache.poi.hssf.record.cf.TestCellRange;
-import org.apache.poi.hssf.record.chart.AllChartRecordTests;
-import org.apache.poi.hssf.record.common.TestUnicodeString;
-import org.apache.poi.hssf.record.pivot.AllPivotRecordTests;
-import org.apache.poi.poifs.crypt.AllEncryptionTests;
-import org.apache.poi.ss.formula.constant.TestConstantValueParser;
-import org.apache.poi.ss.formula.ptg.AllFormulaTests;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for package <tt>org.apache.poi.hssf.record</tt> and sub-packages.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- AllChartRecordTests.class,
- AllEncryptionTests.class,
- AllFormulaTests.class,
- AllPivotRecordTests.class,
- AllRecordAggregateTests.class,
- TestArrayRecord.class,
- TestBOFRecord.class,
- TestBoolErrRecord.class,
- TestBoundSheetRecord.class,
- TestCellRange.class,
- TestCFHeaderRecord.class,
- TestCFRuleRecord.class,
- TestColumnInfoRecord.class,
- TestCommonObjectDataSubRecord.class,
- TestConstantValueParser.class,
- TestDVALRecord.class,
- TestDrawingGroupRecord.class,
- TestDrawingRecord.class,
- TestEmbeddedObjectRefSubRecord.class,
- TestEndSubRecord.class,
- TestEscherAggregate.class,
- TestExtendedFormatRecord.class,
- TestExternalNameRecord.class,
- TestFeatRecord.class,
- TestFontRecord.class,
- TestFormulaRecord.class,
- TestHyperlinkRecord.class,
- TestInterfaceEndRecord.class,
- TestLabelRecord.class,
- TestLbsDataSubRecord.class,
- TestMergeCellsRecord.class,
- TestNameRecord.class,
- TestNoteRecord.class,
- TestNoteStructureSubRecord.class,
- TestObjRecord.class,
- //TestPaletteRecord.class, //converted to junit4
- TestPaneRecord.class,
- TestPLVRecord.class,
- TestRecalcIdRecord.class,
- TestRecordFactory.class,
- TestRecordFactoryInputStream.class,
- TestRecordInputStream.class,
- TestSCLRecord.class,
- TestSSTDeserializer.class,
- TestSSTRecord.class,
- TestSSTRecordSizeCalculator.class,
- TestSharedFormulaRecord.class,
- TestStringRecord.class,
- TestStyleRecord.class,
- TestSubRecord.class,
- TestSupBookRecord.class,
- TestTableRecord.class,
- TestTextObjectBaseRecord.class,
- TestTextObjectRecord.class,
- TestUnicodeNameRecord.class,
- TestUnicodeString.class,
- TestWriteAccessRecord.class,
- TestDConRefRecord.class
-})
-public final class AllRecordTests {
-}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestArrayRecord.java b/src/testcases/org/apache/poi/hssf/record/TestArrayRecord.java
index d84b514b08..a7da3501f7 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestArrayRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestArrayRecord.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.record;
-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.HSSFSheet;
@@ -31,7 +31,7 @@ import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestArrayRecord {
diff --git a/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java b/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java
index 2baf72b8a4..daa41fc8d2 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the AutoFilterInfoRecord class.
diff --git a/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java b/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java
index f63993e424..a73e0aacf6 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java
@@ -17,14 +17,14 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestBOFRecord {
@Test
diff --git a/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java b/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java
index ee5d8af5c3..a281b5f009 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link BoolErrRecord}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java b/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java
index 4f2f32904f..48b2796d2c 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java
@@ -17,16 +17,17 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.util.ArrayList;
import java.util.List;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests BoundSheetRecord.
@@ -45,10 +46,10 @@ public final class TestBoundSheetRecord {
assertEquals(24, record.getRecordSize());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testName() {
BoundSheetRecord record = new BoundSheetRecord("1234567890223456789032345678904");
- record.setSheetname("s//*s");
+ assertThrows(IllegalArgumentException.class, () -> record.setSheetname("s//*s"));
}
@Test
diff --git a/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java
index 484cfc0b7d..68b5bad564 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java
@@ -18,12 +18,12 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.util.CellRangeAddress;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the {@link CFHeaderRecord}
@@ -133,7 +133,7 @@ public final class TestCFHeaderRecord {
CFHeaderRecord record = new CFHeaderRecord(TestcaseRecordInputStream.create(CFHeaderRecord.sid, recordData));
- assertEquals("#CFRULES", 3, record.getNumberOfConditionalFormats());
+ assertEquals(3, record.getNumberOfConditionalFormats(), "#CFRULES");
assertTrue(record.getNeedRecalculation());
confirm(record.getEnclosingCellRange(), 0, 3, 0, 3);
CellRangeAddress[] ranges = record.getCellRanges();
@@ -180,7 +180,7 @@ public final class TestCFHeaderRecord {
// bug 44739b - invalid cell range (-25536, 2, -15536, 2)
CFHeaderRecord record = new CFHeaderRecord(TestcaseRecordInputStream.create(CFHeaderRecord.sid, recordData));
- assertEquals("#CFRULES", 19, record.getNumberOfConditionalFormats());
+ assertEquals(19, record.getNumberOfConditionalFormats(), "#CFRULES");
assertFalse(record.getNeedRecalculation());
confirm(record.getEnclosingCellRange(), 0, 65535, 0, 255);
CellRangeAddress[] ranges = record.getCellRanges();
@@ -194,9 +194,9 @@ public final class TestCFHeaderRecord {
}
private static void confirm(CellRangeAddress cr, int expFirstRow, int expLastRow, int expFirstCol, int expLastColumn) {
- assertEquals("first row", expFirstRow, cr.getFirstRow());
- assertEquals("last row", expLastRow, cr.getLastRow());
- assertEquals("first column", expFirstCol, cr.getFirstColumn());
- assertEquals("last column", expLastColumn, cr.getLastColumn());
+ assertEquals(expFirstRow, cr.getFirstRow(), "first row");
+ assertEquals(expLastRow, cr.getLastRow(), "last row");
+ assertEquals(expFirstCol, cr.getFirstColumn(), "first column");
+ assertEquals(expLastColumn, cr.getLastColumn(), "last column");
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
index c0aa3629ea..ea5462dd33 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
@@ -18,12 +18,12 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.assertSame;
-import static org.junit.Assert.assertTrue;
+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.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.Arrays;
@@ -42,7 +42,7 @@ import org.apache.poi.ss.formula.ptg.RefPtg;
import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
import org.apache.poi.util.LittleEndian;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the TestCFRuleRecord
@@ -387,8 +387,9 @@ public final class TestCFRuleRecord {
assertEquals(3, LittleEndian.getShort(data, 8));
int flags = LittleEndian.getInt(data, 10);
- assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000);
- assertEquals("undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy
+ assertEquals(0x00380000, flags & 0x00380000, "unused flags should be 111");
+ // Otherwise Excel gets unhappy
+ assertEquals(0, flags & 0x03C00000, "undocumented flags should be 0000");
// check all remaining flag bits (some are not well understood yet)
assertEquals(0x203FFFFF, flags);
}
@@ -415,7 +416,7 @@ public final class TestCFRuleRecord {
CFRuleRecord rr = new CFRuleRecord(is);
Ptg[] ptgs = rr.getParsedExpression1();
assertEquals(3, ptgs.length);
- assertFalse("Identified bug 45234", ptgs[0] instanceof RefPtg);
+ assertFalse(ptgs[0] instanceof RefPtg, "Identified bug 45234");
assertEquals(RefNPtg.class, ptgs[0].getClass());
RefNPtg refNPtg = (RefNPtg) ptgs[0];
assertTrue(refNPtg.isColRelative());
diff --git a/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java b/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java
index 0d57714618..1910a96f7b 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java
@@ -17,12 +17,12 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+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.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link ColumnInfoRecord}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java
index d46cda971c..c79165fec2 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java
@@ -19,11 +19,11 @@ package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the {@link CommonObjectDataSubRecord}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java
index 259cd9b2a3..c9797cc6f0 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java
@@ -19,17 +19,17 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import org.apache.poi.util.LittleEndianOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit tests for DConRefRecord class.
@@ -214,7 +214,7 @@ public class TestDConRefRecord {
d.serialize(o);
o.flush();
- assertArrayEquals(message, data, bos.toByteArray());
+ assertArrayEquals(data, bos.toByteArray(), message);
}
/**
@@ -241,14 +241,14 @@ public class TestDConRefRecord {
DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1));
int expResult = data1.length;
int result = instance.getDataSize();
- assertEquals("single byte external reference, volume type path data size", expResult, result);
+ assertEquals(expResult, result, "single byte external reference, volume type path data size");
instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data2));
- assertEquals("double byte self reference data size", data2.length, instance.getDataSize());
+ assertEquals(data2.length, instance.getDataSize(), "double byte self reference data size");
instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data3));
- assertEquals("single byte self reference data size", data3.length, instance.getDataSize());
+ assertEquals(data3.length, instance.getDataSize(), "single byte self reference data size");
instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data4));
- assertEquals("double byte external reference, UNC volume type path data size", data4.length,
- instance.getDataSize());
+ assertEquals(data4.length, instance.getDataSize(),
+ "double byte external reference, UNC volume type path data size");
}
/**
@@ -259,7 +259,7 @@ public class TestDConRefRecord {
DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1));
short expResult = 81;
short result = instance.getSid();
- assertEquals("SID", expResult, result);
+ assertEquals(expResult, result, "SID");
}
/**
@@ -271,7 +271,7 @@ public class TestDConRefRecord {
DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1));
byte[] expResult = Arrays.copyOfRange(data1, 9, data1.length);
byte[] result = instance.getPath();
- assertArrayEquals("get path", expResult, result);
+ assertArrayEquals(expResult, result, "get path");
}
/**
@@ -280,8 +280,8 @@ public class TestDConRefRecord {
@Test
public void testIsExternalRef() {
DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1));
- assertTrue("external reference", instance.isExternalRef());
+ assertTrue(instance.isExternalRef(), "external reference");
instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data2));
- assertFalse("internal reference", instance.isExternalRef());
+ assertFalse(instance.isExternalRef(), "internal reference");
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java
index 3e8ab9811e..83fff74ae8 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.record;
-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.ByteArrayInputStream;
import org.apache.poi.util.LittleEndian;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestDVALRecord {
@Test
@@ -45,7 +45,7 @@ public final class TestDVALRecord {
assertEquals(56, dv.getHorizontalPos());
assertEquals(57, dv.getVerticalPos());
assertEquals(58, dv.getObjectID());
- assertNotEquals("Identified bug 44510",0, dv.getDVRecNo());
+ assertNotEquals(0, dv.getDVRecNo(), "Identified bug 44510");
assertEquals(59, dv.getDVRecNo());
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
index acee4f2727..042c3ec348 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
@@ -18,12 +18,12 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.cut;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.util.HexDump;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestDrawingGroupRecord {
private static final int MAX_RECORD_SIZE = 8228;
diff --git a/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java
index 9b2c650c42..1aa1cefa88 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+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 java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -27,7 +27,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestDrawingRecord {
diff --git a/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java
index b8b1e20bd8..ac3f6b56e7 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java
@@ -18,11 +18,11 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the TestEmbeddedObjectRefSubRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java
index fa5d9c7233..306c60d451 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java
@@ -18,9 +18,9 @@
package org.apache.poi.hssf.record;
-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 the serialization and deserialization of the EndSubRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java b/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java
index 32c0750336..761256479b 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.List;
@@ -27,7 +27,7 @@ import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the EscherAggregate class.
diff --git a/src/testcases/org/apache/poi/hssf/record/TestExtSSTRecord.java b/src/testcases/org/apache/poi/hssf/record/TestExtSSTRecord.java
index 0d6bf167af..5ad4a65830 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestExtSSTRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestExtSSTRecord.java
@@ -19,12 +19,12 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.poifs.storage.RawDataUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestExtSSTRecord {
diff --git a/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java
index 71de921dcc..632a6f1cf2 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java
@@ -18,9 +18,9 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestExtendedFormatRecord {
diff --git a/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java b/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java
index 3bb3c8394a..bca4bbe6fe 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java
@@ -18,15 +18,15 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.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.assertTrue;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestExternalNameRecord {
@@ -64,7 +64,7 @@ public final class TestExternalNameRecord {
@Test
public void testBasicSize() {
ExternalNameRecord enr = createSimpleENR(dataFDS);
- assertNotEquals("Identified bug 44695",13, enr.getRecordSize());
+ assertNotEquals(13, enr.getRecordSize(), "Identified bug 44695");
assertEquals(17, enr.getRecordSize());
assertNotNull(enr.serialize());
diff --git a/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java
index fe56976545..74b06b172e 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java
@@ -17,11 +17,11 @@
package org.apache.poi.hssf.record;
-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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
@@ -32,7 +32,7 @@ import org.apache.poi.hssf.record.common.FeatFormulaErr2;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFTestHelper;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for <tt>FeatRecord</tt>
diff --git a/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java
index 69f6254f96..2a24c80143 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java
@@ -19,13 +19,13 @@ package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the {@link FontRecord}
@@ -111,7 +111,7 @@ public final class TestFontRecord {
byte [] recordBytes = other.serialize();
assertEquals(recordBytes.length - 4, data.length);
for (int i = 0; i < data.length; i++)
- assertEquals("At offset " + i, data[i], recordBytes[i+4]);
+ assertEquals(data[i], recordBytes[i+4], "At offset " + i);
}
@Test
diff --git a/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java
index bd454365e1..180a8d0521 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.record;
-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.ptg.AttrPtg;
import org.apache.poi.ss.formula.ptg.FuncVarPtg;
@@ -28,7 +28,7 @@ import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.RefPtg;
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 FormulaRecord}
@@ -83,17 +83,18 @@ public final class TestFormulaRecord {
};
FormulaRecord record = new FormulaRecord(TestcaseRecordInputStream.create(FormulaRecord.sid, formulaByte));
- assertEquals("Row", 0, record.getRow());
- assertEquals("Column", 0, record.getColumn());
+ assertEquals(0, record.getRow(), "Row");
+ assertEquals(0, record.getColumn(), "Column");
//noinspection deprecation
assertEquals(CellType.ERROR.getCode(), record.getCachedResultType());
assertEquals(CellType.ERROR, record.getCachedResultTypeEnum());
byte[] output = record.serialize();
- assertEquals("Output size", 33, output.length); //includes sid+recordlength
+ // includes sid+recordlength
+ assertEquals(33, output.length, "Output size");
for (int i = 5; i < 13;i++) {
- assertEquals("FormulaByte NaN doesn't match", formulaByte[i], output[i+4]);
+ assertEquals(formulaByte[i], output[i+4], "FormulaByte NaN doesn't match");
}
}
@@ -111,11 +112,12 @@ public final class TestFormulaRecord {
formulaByte[20]=(byte)0x05;
formulaByte[22]=(byte)0x01;
FormulaRecord record = new FormulaRecord(TestcaseRecordInputStream.create(FormulaRecord.sid, formulaByte));
- assertEquals("Row", 0, record.getRow());
- assertEquals("Column", 0, record.getColumn());
+ assertEquals(0, record.getRow(), "Row");
+ assertEquals(0, record.getColumn(), "Column");
byte[] output = record.serialize();
- assertEquals("Output size", 31, output.length); //includes sid+recordlength
- assertEquals("Offset 22", 1, output[26]);
+ // includes sid+recordlength
+ assertEquals(31, output.length, "Output size");
+ assertEquals(1, output[26], "Offset 22");
}
@Test
@@ -191,7 +193,7 @@ public final class TestFormulaRecord {
fr0.setCachedResultBoolean(false);
fr1.setCachedResultBoolean(true);
- assertFalse("Identified bug 46479c", fr0.getCachedBooleanValue() && !fr1.getCachedBooleanValue());
+ assertFalse(fr0.getCachedBooleanValue() && !fr1.getCachedBooleanValue(), "Identified bug 46479c");
assertFalse(fr0.getCachedBooleanValue());
assertTrue(fr1.getCachedBooleanValue());
}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java
index 1a1204c2f5..985fe64eaa 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the FtCblsSubRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java b/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
index 269bbd1adb..cbcb0a493f 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
@@ -33,7 +33,7 @@ import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test HyperlinkRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestInterfaceEndRecord.java b/src/testcases/org/apache/poi/hssf/record/TestInterfaceEndRecord.java
index f085cf15c8..96e844486c 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestInterfaceEndRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestInterfaceEndRecord.java
@@ -18,14 +18,14 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.util.List;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the EndSubRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestLabelRecord.java b/src/testcases/org/apache/poi/hssf/record/TestLabelRecord.java
index ec5ed36689..f1f93ffe95 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestLabelRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestLabelRecord.java
@@ -17,14 +17,14 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
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 <tt>LabelRecord</tt>
diff --git a/src/testcases/org/apache/poi/hssf/record/TestLbsDataSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestLbsDataSubRecord.java
index ab54970fb1..71e2504761 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestLbsDataSubRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestLbsDataSubRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -33,7 +33,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.LittleEndianOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the LbsDataSubRecord class works correctly.
diff --git a/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java b/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java
index fa4dc0b1e5..f19e428355 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.record;
-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.util.ArrayList;
import java.util.List;
@@ -26,7 +26,7 @@ import java.util.List;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.aggregates.MergedCellsTable;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
@@ -43,15 +43,15 @@ public final class TestMergeCellsRecord {
MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length);
MergeCellsRecord clone = merge.copy();
- assertNotSame("Merged and cloned objects are the same", merge, clone);
+ assertNotSame(merge, clone, "Merged and cloned objects are the same");
CellRangeAddress mergeRegion = merge.getAreaAt(0);
CellRangeAddress cloneRegion = clone.getAreaAt(0);
- assertNotSame("Should not point to same objects when cloning", mergeRegion, cloneRegion);
- assertEquals("New Clone Row From doesnt match", mergeRegion.getFirstRow(), cloneRegion.getFirstRow());
- assertEquals("New Clone Row To doesnt match", mergeRegion.getLastRow(), cloneRegion.getLastRow());
- assertEquals("New Clone Col From doesnt match", mergeRegion.getFirstColumn(), cloneRegion.getFirstColumn());
- assertEquals("New Clone Col To doesnt match", mergeRegion.getLastColumn(), cloneRegion.getLastColumn());
+ assertNotSame(mergeRegion, cloneRegion, "Should not point to same objects when cloning");
+ assertEquals(mergeRegion.getFirstRow(), cloneRegion.getFirstRow(), "New Clone Row From doesnt match");
+ assertEquals(mergeRegion.getLastRow(), cloneRegion.getLastRow(), "New Clone Row To doesnt match");
+ assertEquals(mergeRegion.getFirstColumn(), cloneRegion.getFirstColumn(), "New Clone Col From doesnt match");
+ assertEquals(mergeRegion.getLastColumn(), cloneRegion.getLastColumn(), "New Clone Col To doesnt match");
assertNotSame(merge.getAreaAt(0), clone.getAreaAt(0));
}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestNameCommentRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNameCommentRecord.java
index 062784675f..20fa58db33 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestNameCommentRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestNameCommentRecord.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the NameCommentRecord serializes/deserializes correctly
diff --git a/src/testcases/org/apache/poi/hssf/record/TestNameRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNameRecord.java
index 7dfdf4f8ee..3c0f267bd7 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestNameRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestNameRecord.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.IOException;
@@ -34,7 +34,7 @@ import org.apache.poi.ss.formula.ptg.NamePtg;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.Ref3DPtg;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the NameRecord serializes/deserializes correctly
diff --git a/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java
index c2ccad9a4a..cbec6a7573 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java
@@ -18,14 +18,14 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
+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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the NoteRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java
index 358a1431c6..b1692389d7 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the NoteRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestObjRecord.java b/src/testcases/org/apache/poi/hssf/record/TestObjRecord.java
index c6cb9ac26f..54b9cd3cac 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestObjRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestObjRecord.java
@@ -18,16 +18,16 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.List;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the ObjRecord class works correctly.
@@ -111,11 +111,7 @@ public final class TestObjRecord {
@Test
public void testReadWriteWithPadding_bug45133() {
ObjRecord record = new ObjRecord(TestcaseRecordInputStream.create(recdataNeedingPadding));
-
- if (record.getRecordSize() == 34) {
- fail("Identified bug 45133");
- }
-
+ assertNotEquals(34, record.getRecordSize(), "Identified bug 45133");
assertEquals(36, record.getRecordSize());
List<SubRecord> subrecords = record.getSubRecords();
diff --git a/src/testcases/org/apache/poi/hssf/record/TestPLVRecord.java b/src/testcases/org/apache/poi/hssf/record/TestPLVRecord.java
index 94c8bca18d..653335cf69 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestPLVRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestPLVRecord.java
@@ -25,7 +25,7 @@ import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.util.CellRangeAddressList;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Verify that presence of PLV record doesn't break data
diff --git a/src/testcases/org/apache/poi/hssf/record/TestPaletteRecord.java b/src/testcases/org/apache/poi/hssf/record/TestPaletteRecord.java
index 321b6e3129..d1805300b1 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestPaletteRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestPaletteRecord.java
@@ -17,13 +17,14 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.poi.hssf.util.HSSFColor;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Verifies that custom palette editing works correctly
@@ -46,9 +47,10 @@ public final class TestPaletteRecord {
byte[] paletteTriplet = palette.getColor((short) index);
String msg = "Expected HSSFColor constant to match PaletteRecord at index" + (index == c.getIndex2() ? "2" : "") + " 0x"
+ Integer.toHexString(index);
- assertEquals(msg, rgbTriplet[0], paletteTriplet[0] & 0xff);
- assertEquals(msg, rgbTriplet[1], paletteTriplet[1] & 0xff);
- assertEquals(msg, rgbTriplet[2], paletteTriplet[2] & 0xff);
+ assertNotNull(paletteTriplet);
+ assertEquals(rgbTriplet[0], paletteTriplet[0] & 0xff, msg);
+ assertEquals(rgbTriplet[1], paletteTriplet[1] & 0xff, msg);
+ assertEquals(rgbTriplet[2], paletteTriplet[2] & 0xff, msg);
}
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestPaneRecord.java b/src/testcases/org/apache/poi/hssf/record/TestPaneRecord.java
index f787ef25e5..906a73f6fd 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestPaneRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestPaneRecord.java
@@ -19,9 +19,9 @@ package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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 the serialization and deserialization of the PaneRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestRecalcIdRecord.java b/src/testcases/org/apache/poi/hssf/record/TestRecalcIdRecord.java
index bbaeae4a23..7662a95d5b 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestRecalcIdRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestRecalcIdRecord.java
@@ -18,11 +18,11 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestRecalcIdRecord {
diff --git a/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java b/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java
index 2e67f25b7d..103eeace7d 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -27,7 +27,7 @@ import java.util.List;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the record factory
@@ -123,25 +123,19 @@ public final class TestRecordFactory {
ByteArrayInputStream bois = new ByteArrayInputStream(data);
Record[] records = RecordFactory.createRecords(bois).toArray(new Record[0]);
- assertEquals("Created record count", 3, records.length);
- assertEquals("1st record's type",
- UnknownRecord.class.getName(),
- records[ 0 ].getClass().getName());
- assertEquals("1st record's sid", (short)-256, records[0].getSid());
- assertEquals("2nd record's type",
- ContinueRecord.class.getName(),
- records[ 1 ].getClass().getName());
+ assertEquals(3, records.length, "Created record count");
+ assertEquals(UnknownRecord.class.getName(), records[ 0 ].getClass().getName(), "1st record's type");
+ assertEquals((short)-256, records[0].getSid(), "1st record's sid");
+ assertEquals(ContinueRecord.class.getName(), records[ 1 ].getClass().getName(), "2nd record's type");
ContinueRecord record = (ContinueRecord) records[1];
- assertEquals("2nd record's sid", 0x3C, record.getSid());
- assertEquals("1st data byte", 1, record.getData()[ 0 ]);
- assertEquals("2nd data byte", 2, record.getData()[ 1 ]);
- assertEquals("3rd data byte", 3, record.getData()[ 2 ]);
- assertEquals("3rd record's type",
- ContinueRecord.class.getName(),
- records[ 2 ].getClass().getName());
+ assertEquals(0x3C, record.getSid(), "2nd record's sid");
+ assertEquals(1, record.getData()[ 0 ], "1st data byte");
+ assertEquals(2, record.getData()[ 1 ], "2nd data byte");
+ assertEquals(3, record.getData()[ 2 ], "3rd data byte");
+ assertEquals(ContinueRecord.class.getName(), records[ 2 ].getClass().getName(), "3rd record's type");
record = (ContinueRecord) records[2];
- assertEquals("3nd record's sid", 0x3C, record.getSid());
- assertEquals("4th data byte", 4, record.getData()[ 0 ]);
+ assertEquals(0x3C, record.getSid(), "3nd record's sid");
+ assertEquals(4, record.getData()[ 0 ], "4th data byte");
}
/**
@@ -151,10 +145,8 @@ public final class TestRecordFactory {
*/
@Test
public void testMixedContinue() throws IOException {
- /**
- * Adapted from a real test sample file 39512.xls (Offset 0x4854).
- * See Bug 39512 for details.
- */
+ // Adapted from a real test sample file 39512.xls (Offset 0x4854).
+ // See Bug 39512 for details.
String dump =
//OBJ
"5D 00 48 00 15 00 12 00 0C 00 3C 00 11 00 A0 2E 03 01 CC 42 " +
diff --git a/src/testcases/org/apache/poi/hssf/record/TestRecordFactoryInputStream.java b/src/testcases/org/apache/poi/hssf/record/TestRecordFactoryInputStream.java
index 757da3c9ca..89604135b5 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestRecordFactoryInputStream.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestRecordFactoryInputStream.java
@@ -17,17 +17,17 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.ByteArrayInputStream;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link RecordFactoryInputStream}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestRecordInputStream.java b/src/testcases/org/apache/poi/hssf/record/TestRecordInputStream.java
index ebd0db6cf2..e01048fe24 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestRecordInputStream.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestRecordInputStream.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link RecordInputStream}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSCLRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSCLRecord.java
index 561a966861..cfe9f1ebea 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSCLRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSCLRecord.java
@@ -19,9 +19,9 @@ package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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 the serialization and deserialization of the SCLRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java b/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java
index 17a5a8852f..5c0c88c3b8 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.io.InputStream;
@@ -26,7 +26,7 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.IntMapper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Exercise the SSTDeserializer class.
@@ -42,7 +42,7 @@ public final class TestSSTDeserializer {
System.arraycopy(b, 0, result, a.length, b.length);
return result;
}
-
+
private static byte[] readSampleHexData(String sampleFileName, String sectionName, int recSid)
throws IOException {
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
@@ -57,7 +57,7 @@ public final class TestSSTDeserializer {
byte[] header = readSampleHexData("richtextdata.txt", "header", FAKE_SID);
byte[] continueBytes = readSampleHexData("richtextdata.txt", "continue1", ContinueRecord.sid);
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
-
+
IntMapper<UnicodeString> strings = new IntMapper<>();
SSTDeserializer deserializer = new SSTDeserializer( strings );
@@ -88,7 +88,7 @@ public final class TestSSTDeserializer {
byte[] header = readSampleHexData("stringacross2continuations.txt", "header", FAKE_SID);
byte[] continue1 = readSampleHexData("stringacross2continuations.txt", "continue1", ContinueRecord.sid);
byte[] continue2 = readSampleHexData("stringacross2continuations.txt", "continue2", ContinueRecord.sid);
-
+
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, concat(continue1, continue2)));
IntMapper<UnicodeString> strings = new IntMapper<>();
@@ -104,7 +104,7 @@ public final class TestSSTDeserializer {
byte[] header = readSampleHexData("extendedtextstrings.txt", "rich-header", FAKE_SID);
byte[] continueBytes = readSampleHexData("extendedtextstrings.txt", "rich-continue1", ContinueRecord.sid);
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
-
+
IntMapper<UnicodeString> strings = new IntMapper<>();
SSTDeserializer deserializer = new SSTDeserializer( strings );
deserializer.manufactureStrings( 1, in);
@@ -115,7 +115,7 @@ public final class TestSSTDeserializer {
header = readSampleHexData("extendedtextstrings.txt", "norich-header", FAKE_SID);
continueBytes = readSampleHexData("extendedtextstrings.txt", "norich-continue1", ContinueRecord.sid);
in = TestcaseRecordInputStream.create(concat(header, continueBytes));
-
+
strings = new IntMapper<>();
deserializer = new SSTDeserializer( strings );
deserializer.manufactureStrings( 1, in);
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
index 96ff3ad6ac..9b030894a8 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.fail;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
@@ -39,7 +39,7 @@ import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestSSTRecord {
@@ -339,9 +339,9 @@ public final class TestSSTRecord {
* deep comparison of two SST records
*/
private static void assertRecordEquals(SSTRecord expected, SSTRecord actual){
- assertEquals("number of strings", expected.getNumStrings(), actual.getNumStrings());
- assertEquals("number of unique strings", expected.getNumUniqueStrings(), actual.getNumUniqueStrings());
- assertEquals("count of strings", expected.countStrings(), actual.countStrings());
+ assertEquals(expected.getNumStrings(), actual.getNumStrings(), "number of strings");
+ assertEquals(expected.getNumUniqueStrings(), actual.getNumUniqueStrings(), "number of unique strings");
+ assertEquals(expected.countStrings(), actual.countStrings(), "count of strings");
Iterator<UnicodeString> iterA = expected.getStrings();
Iterator<UnicodeString> iterB = actual.getStrings();
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java b/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java
index e9dd0798fa..2c26a91f54 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
import org.apache.poi.util.IntMapper;
import org.apache.poi.util.LittleEndianConsts;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests that records size calculates correctly.
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java
index a5cc315975..b24f02af78 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.record;
-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.stream.Stream;
@@ -39,7 +39,7 @@ import org.apache.poi.ss.formula.ptg.RefPtg;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.util.LittleEndianInput;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestSharedFormulaRecord {
@@ -87,14 +87,14 @@ public final class TestSharedFormulaRecord {
RefPtg refPtg = (RefPtg) convertedFormula[1];
assertEquals("$C101", refPtg.toFormulaString());
- assertNotEquals("Identified bug 45123", Ptg.CLASS_REF, refPtg.getPtgClass());
+ assertNotEquals(Ptg.CLASS_REF, refPtg.getPtgClass(), "Identified bug 45123");
confirmOperandClasses(sharedFormula, convertedFormula);
}
private static void confirmOperandClasses(Ptg[] originalPtgs, Ptg[] convertedPtgs) {
int[] exp = Stream.of(originalPtgs).map(Ptg::getPtgClass).mapToInt(Byte::intValue).toArray();
int[] act = Stream.of(convertedPtgs).map(Ptg::getPtgClass).mapToInt(Byte::intValue).toArray();
- assertArrayEquals("Different operand class", exp, act);
+ assertArrayEquals(exp, act, "Different operand class");
}
@Test
diff --git a/src/testcases/org/apache/poi/hssf/record/TestStringRecord.java b/src/testcases/org/apache/poi/hssf/record/TestStringRecord.java
index e113837a2a..ed1282152d 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestStringRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestStringRecord.java
@@ -18,15 +18,16 @@
package org.apache.poi.hssf.record;
-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 java.io.IOException;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the StringRecord
@@ -58,10 +59,10 @@ public final class TestStringRecord {
byte [] recordBytes = record.serialize();
assertEquals(recordBytes.length - 4, data.length);
for (int i = 0; i < data.length; i++) {
- assertEquals("At offset " + i, data[i], recordBytes[i+4]);
+ assertEquals(data[i], recordBytes[i+4], "At offset " + i);
}
}
-
+
@Test
public void testContinue() throws IOException {
int MAX_BIFF_DATA = RecordInputStream.MAX_RECORD_DATA_SIZE;
@@ -77,9 +78,8 @@ public final class TestStringRecord {
sr.setString(sb.toString());
byte[] ser = sr.serialize();
assertEquals(StringRecord.sid, LittleEndian.getUShort(ser, 0));
- if (LittleEndian.getUShort(ser, 2) > MAX_BIFF_DATA) {
- fail("StringRecord should have been split with a continue record");
- }
+ assertTrue(LittleEndian.getUShort(ser, 2) <= MAX_BIFF_DATA,
+ "StringRecord should have been split with a continue record");
// Confirm expected size of first record, and ushort strLen.
assertEquals(MAX_BIFF_DATA, LittleEndian.getUShort(ser, 2));
assertEquals(TEXT_LEN, LittleEndian.getUShort(ser, 4));
diff --git a/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java b/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java
index a2236addc9..068ea327b2 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link StyleRecord}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java
index 10377c23f3..608e5a9050 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java
@@ -20,15 +20,15 @@ package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.Arrays;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndian;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests Subrecord components of an OBJ record. Test data taken directly
@@ -79,7 +79,7 @@ public final class TestSubRecord {
RecordInputStream in = TestcaseRecordInputStream.create(dataAutoFilter);
ObjRecord or = new ObjRecord(in);
byte[] data2 = or.serialize();
- assertNotEquals("Identified bug 45778", 8228, data2.length);
+ assertNotEquals(8228, data2.length, "Identified bug 45778");
assertEquals(74, data2.length);
assertArrayEquals(dataAutoFilter, data2);
}
@@ -100,9 +100,9 @@ public final class TestSubRecord {
RecordInputStream in = TestcaseRecordInputStream.create(data);
ObjRecord or = new ObjRecord(in);
byte[] data2 = or.serialize();
- assertNotEquals("Identified bug 45778", 8228, data2.length);
- assertEquals("Encoded length", data.length, data2.length);
- assertArrayEquals("Encoded data differs", data, data2);
+ assertNotEquals(8228, data2.length, "Identified bug 45778");
+ assertEquals(data.length, data2.length, "Encoded length");
+ assertArrayEquals(data, data2, "Encoded data differs");
}
/**
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java
index da8f6a1576..4ad7a39d35 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java
@@ -27,10 +27,10 @@ import static org.apache.poi.hssf.record.SupBookRecord.CH_UP_DIR;
import static org.apache.poi.hssf.record.SupBookRecord.CH_VOLUME;
import static org.apache.poi.hssf.record.SupBookRecord.PATH_SEPERATOR;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the SupBook record
diff --git a/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java
index 7f052df943..0ce1f53b92 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.util.CellRangeAddress8Bit;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the TableRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java
index dd327048b7..7823705ea9 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java
@@ -18,13 +18,13 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+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.usermodel.HSSFRichTextString;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the TextObjectBaseRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
index 2b57c2fc03..9456aa985a 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.record;
-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.io.ByteArrayInputStream;
@@ -28,7 +28,7 @@ import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.RefPtg;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndian;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests that serialization and deserialization of the TextObjectRecord .
@@ -97,7 +97,7 @@ public final class TestTextObjectRecord {
byte [] ser = record.serialize();
int formatDataLen = LittleEndian.getUShort(ser, 16);
- assertEquals("formatDataLength", 0, formatDataLen);
+ assertEquals(0, formatDataLen, "formatDataLength");
assertEquals(22, ser.length); // just the TXO record
diff --git a/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java b/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java
index 03e3a17919..55f80ed678 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java
@@ -18,14 +18,14 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestUnicodeNameRecord {
diff --git a/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java b/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java
index 38806d9020..2187479fc9 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link WriteAccessRecord}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java b/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java
index 4acc5f71e3..93c62912a9 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.record;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
@@ -85,7 +85,7 @@ public final class TestcaseRecordInputStream {
*/
public static void confirmRecordEncoding(String msgPrefix, int expectedSid, byte[] expectedData, byte[] actualRecordBytes) {
int expectedDataSize = expectedData.length;
- assertEquals("Size of encode data mismatch", actualRecordBytes.length - 4, expectedDataSize);
+ assertEquals(actualRecordBytes.length - 4, expectedDataSize, "Size of encode data mismatch");
assertEquals(expectedSid, LittleEndian.getShort(actualRecordBytes, 0));
assertEquals(expectedDataSize, LittleEndian.getShort(actualRecordBytes, 2));
assertArrayEquals(expectedData, cut(actualRecordBytes, 4));
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java b/src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java
deleted file mode 100644
index 4edf3eb9c0..0000000000
--- a/src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java
+++ /dev/null
@@ -1,37 +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.hssf.record.aggregates;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for package <tt>org.apache.poi.hssf.record.aggregates</tt>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestCFRecordsAggregate.class,
- TestColumnInfoRecordsAggregate.class,
- TestFormulaRecordAggregate.class,
- TestRowRecordsAggregate.class,
- TestSharedValueManager.class,
- TestValueRecordsAggregate.class,
- TestPageSettingsBlock.class
-})
-public final class AllRecordAggregateTests {
-}
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
index e5fb8e769d..f930fadf1d 100644
--- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
+++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
@@ -17,12 +17,12 @@
package org.apache.poi.hssf.record.aggregates;
-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 java.io.ByteArrayInputStream;
import java.io.InputStream;
@@ -36,13 +36,12 @@ import org.apache.poi.hssf.record.CFRule12Record;
import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator;
import org.apache.poi.hssf.record.CFRuleRecord;
-import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordFactory;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.LittleEndian;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the CFRecordsAggregate
@@ -138,7 +137,7 @@ public final class TestCFRecordsAggregate {
agg.serialize(0, serializedRecord);
int nRules = LittleEndian.getUShort(serializedRecord, 4);
- assertNotEquals("Identified bug 45682 b", 0, nRules);
+ assertNotEquals(0, nRules, "Identified bug 45682 b");
assertEquals(rules.length, nRules);
}
@@ -150,27 +149,20 @@ public final class TestCFRecordsAggregate {
new CellRangeAddress(0,1,0,0),
new CellRangeAddress(0,1,2,2),
};
- CFRuleBase[] rules = {
+ CFRuleBase[] rules1 = {
CFRuleRecord.create(sheet, "7"),
CFRule12Record.create(sheet, ComparisonOperator.BETWEEN, "2", "5"),
};
- try {
- new CFRecordsAggregate(cellRanges, rules);
- fail("Shouldn't be able to mix between types");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> new CFRecordsAggregate(cellRanges, rules1),
+ "Shouldn't be able to mix between types");
- rules = new CFRuleBase[] { CFRuleRecord.create(sheet, "7") };
- CFRecordsAggregate agg = new CFRecordsAggregate(cellRanges, rules);
+
+ CFRuleBase[] rules2 = { CFRuleRecord.create(sheet, "7") };
+ CFRecordsAggregate agg = new CFRecordsAggregate(cellRanges, rules2);
assertTrue(agg.getHeader().getNeedRecalculation());
- try {
- agg.addRule(CFRule12Record.create(sheet, "7"));
- fail("Shouldn't be able to mix between types");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> agg.addRule(CFRule12Record.create(sheet, "7")),
+ "Shouldn't be able to mix between types");
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java
index 569ffbc8fc..238f74e3b4 100644
--- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java
+++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java
@@ -17,16 +17,15 @@
package org.apache.poi.hssf.record.aggregates;
-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.ArrayList;
import java.util.List;
import org.apache.poi.hssf.record.ColumnInfoRecord;
-import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestColumnInfoRecordsAggregate {
@@ -109,7 +108,7 @@ public final class TestColumnInfoRecordsAggregate {
cirs.clear();
agg.visitContainedRecords(cirs::add);
assertEquals(4, cirs.size());
- assertTrue("Inner group should still be hidden", ((ColumnInfoRecord)cirs.get(1)).getHidden());
+ assertTrue(((ColumnInfoRecord)cirs.get(1)).getHidden(), "Inner group should still be hidden");
confirmCIR(cirs, 0, 1, 3, 1, true, false);
confirmCIR(cirs, 1, 4, 12, 2, true, false);
confirmCIR(cirs, 2, 13, 15, 1, true, false);
@@ -119,10 +118,10 @@ public final class TestColumnInfoRecordsAggregate {
private static void confirmCIR(List<org.apache.poi.hssf.record.Record> cirs, int ix, int startColIx, int endColIx, int level, boolean isHidden, boolean isCollapsed) {
assertTrue(cirs.get(ix) instanceof ColumnInfoRecord);
ColumnInfoRecord cir = (ColumnInfoRecord)cirs.get(ix);
- assertEquals("startColIx", startColIx, cir.getFirstColumn());
- assertEquals("endColIx", endColIx, cir.getLastColumn());
- assertEquals("level", level, cir.getOutlineLevel());
- assertEquals("hidden", isHidden, cir.getHidden());
- assertEquals("collapsed", isCollapsed, cir.getCollapsed());
+ assertEquals(startColIx, cir.getFirstColumn(), "startColIx");
+ assertEquals(endColIx, cir.getLastColumn(), "endColIx");
+ assertEquals(level, cir.getOutlineLevel(), "level");
+ assertEquals(isHidden, cir.getHidden(), "hidden");
+ assertEquals(isCollapsed, cir.getCollapsed(), "collapsed");
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java
index 798fa54b5a..d31f3d837f 100644
--- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java
+++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java
@@ -17,23 +17,22 @@
package org.apache.poi.hssf.record.aggregates;
-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.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.record.FormulaRecord;
-import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.StringRecord;
import org.apache.poi.ss.formula.FormulaRenderer;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.ptg.ExpPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestFormulaRecordAggregate {
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestPageSettingsBlock.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestPageSettingsBlock.java
index 2f4217400b..c7822c28f0 100644
--- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestPageSettingsBlock.java
+++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestPageSettingsBlock.java
@@ -17,12 +17,12 @@
package org.apache.poi.hssf.record.aggregates;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
@@ -55,7 +55,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.RecordFormatException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tess for {@link PageSettingsBlock}
@@ -228,7 +228,7 @@ public final class TestPageSettingsBlock {
List<org.apache.poi.hssf.record.Record> outRecs = new ArrayList<>();
psb.visitContainedRecords(outRecs::add);
- assertNotEquals("PageSettingsBlock didn't add missing header/footer records", 2, outRecs.size());
+ assertNotEquals(2, outRecs.size(), "PageSettingsBlock didn't add missing header/footer records");
Class<?>[] act = outRecs.stream().map(Object::getClass).toArray(Class[]::new);
Class<?>[] exp = { HeaderRecord.class, FooterRecord.class, HCenterRecord.class, VCenterRecord.class};
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java
index c6b44be8f4..f0b2b671f6 100644
--- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java
+++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java
@@ -17,10 +17,11 @@
package org.apache.poi.hssf.record.aggregates;
-import static org.junit.Assert.assertEquals;
-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.assertNotNull;
+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.util.ArrayList;
import java.util.Arrays;
@@ -41,7 +42,7 @@ import org.apache.poi.hssf.record.UnknownRecord;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress8Bit;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link RowRecordsAggregate}
@@ -58,8 +59,8 @@ public final class TestRowRecordsAggregate {
RowRecord rr1 = rra.getRow(4);
assertNotNull(rr1);
- assertEquals("Row number is 1", 4, rr1.getRowNumber());
- assertSame("Row record retrieved is identical ", rr1, rr);
+ assertEquals(4, rr1.getRowNumber(), "Row number is 1");
+ assertSame(rr1, rr, "Row record retrieved is identical ");
}
/**
@@ -108,11 +109,8 @@ public final class TestRowRecordsAggregate {
if (rec.getClass() == shfClass) {
result++;
Record prevRec = recs.get(i-1);
- if (!(prevRec instanceof FormulaRecord)) {
- fail("Bad record order at index "
- + i + ": Formula record expected but got ("
- + prevRec.getClass().getName() + ")");
- }
+ assertTrue(prevRec instanceof FormulaRecord,
+ "Bad record order at index " + i + ": Formula record expected but got (" + prevRec.getClass().getName() + ")");
verifySharedFormula((FormulaRecord) prevRec, rec);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java
index 8c2a47e14c..2790da2cc9 100644
--- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java
+++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.record.aggregates;
-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.util.Collection;
import java.util.HashMap;
@@ -28,7 +28,7 @@ import org.apache.poi.hssf.record.SharedFormulaRecord;
import org.apache.poi.hssf.usermodel.HSSFCell;
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 SharedValueManager}
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
index 477affdbf0..44f9656e19 100644
--- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
+++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
@@ -17,11 +17,11 @@
package org.apache.poi.hssf.record.aggregates;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.IOException;
import java.io.InputStream;
@@ -44,7 +44,7 @@ import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link ValueRecordsAggregate}
@@ -78,8 +78,8 @@ public final class TestValueRecordsAggregate {
assertEquals(1, cvrs.size());
CellValueRecordInterface record = cvrs.get(0);
- assertNotNull( "Row contains a value", record );
- assertTrue( "First record is a FormulaRecordsAggregate", ( record instanceof FormulaRecordAggregate ) );
+ assertNotNull( record, "Row contains a value" );
+ assertTrue( ( record instanceof FormulaRecordAggregate ), "First record is a FormulaRecordsAggregate");
}
private void constructValueRecord(List<org.apache.poi.hssf.record.Record> records) {
@@ -258,13 +258,13 @@ public final class TestValueRecordsAggregate {
String cellFormula;
cellFormula = getFormulaFromFirstCell(s, 0); // row "1"
// the problem is not observable in the first row of the shared formula
- assertEquals("Something else wrong with this test case", "\"first formula\"", cellFormula);
+ assertEquals("\"first formula\"", cellFormula, "Something else wrong with this test case");
// but the problem is observable in rows 2,3,4
cellFormula = getFormulaFromFirstCell(s, 1); // row "2"
- assertNotEquals("found bug 44449 (Wrong SharedFormulaRecord was used).", "\"second formula\"", cellFormula);
+ assertNotEquals("\"second formula\"", cellFormula, "found bug 44449 (Wrong SharedFormulaRecord was used).");
- assertEquals("Something else wrong with this test case", "\"first formula\"", cellFormula);
+ assertEquals("\"first formula\"", cellFormula, "Something else wrong with this test case");
wb.close();
}
diff --git a/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java b/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java
index 639edca2b3..aa59f19b88 100644
--- a/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java
+++ b/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java
@@ -17,15 +17,15 @@ limitations under the License.
package org.apache.poi.hssf.record.cf;
-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.util.Arrays;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests CellRange operations.
@@ -78,7 +78,7 @@ public final class TestCellRange {
for(int j=0; j!=ranges.length;j++)
{
boolean expectedResult = containsExpectedResults[i][j];
- assertEquals("("+i+","+j+"): ", expectedResult, CellRangeUtil.contains(ranges[i], ranges[j]));
+ assertEquals(expectedResult, CellRangeUtil.contains(ranges[i], ranges[j]), "("+i+","+j+"): ");
}
}
}
@@ -169,8 +169,8 @@ public final class TestCellRange {
public void testCreate() {
CellRangeAddress cr = createCR(0, -1, 2, 255); // $C:$IV
- assertFalse("isFullRowRange", cr.isFullRowRange());
- assertTrue("isFullColumnRange", cr.isFullColumnRange());
+ assertFalse(cr.isFullRowRange(), "isFullRowRange");
+ assertTrue(cr.isFullColumnRange(), "isFullColumnRange");
createCR(0, 7, 1, 1); // $B$1:$B$8
@@ -249,11 +249,11 @@ public final class TestCellRange {
// }
private void verifyExpectedResult(CellRangeAddress[] result, String... expectedOutput) {
- assertEquals("\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result),
- expectedOutput.length, result.length);
+ assertEquals(expectedOutput.length, result.length,
+ "\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result));
for(int i = 0;i < expectedOutput.length;i++) {
- assertEquals("\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result),
- expectedOutput[i], result[i].formatAsString());
+ assertEquals(expectedOutput[i], result[i].formatAsString(),
+ "\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result));
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/AllChartRecordTests.java b/src/testcases/org/apache/poi/hssf/record/chart/AllChartRecordTests.java
deleted file mode 100644
index 0f0c698681..0000000000
--- a/src/testcases/org/apache/poi/hssf/record/chart/AllChartRecordTests.java
+++ /dev/null
@@ -1,66 +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.hssf.record.chart;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for package <tt>org.apache.poi.hssf.record.class</tt>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestAreaFormatRecord.class,
- TestAreaRecord.class,
- TestAxisLineFormatRecord.class,
- TestAxisOptionsRecord.class,
- TestAxisParentRecord.class,
- TestAxisRecord.class,
- TestAxisUsedRecord.class,
- TestBarRecord.class,
- TestCategorySeriesAxisRecord.class,
- TestChartFormatRecord.class,
- TestChartRecord.class,
- TestChartTitleFormatRecord.class,
- TestDatRecord.class,
- TestDataFormatRecord.class,
- TestDefaultDataLabelTextPropertiesRecord.class,
- TestFontBasisRecord.class,
- TestFontIndexRecord.class,
- TestFrameRecord.class,
- TestLegendRecord.class,
- TestLineFormatRecord.class,
- TestLinkedDataRecord.class,
- TestNumberFormatIndexRecord.class,
- TestObjectLinkRecord.class,
- TestPlotAreaRecord.class,
- TestPlotGrowthRecord.class,
- TestSeriesChartGroupIndexRecord.class,
- TestSeriesIndexRecord.class,
- TestSeriesLabelsRecord.class,
- TestSeriesListRecord.class,
- TestSeriesRecord.class,
- TestSeriesTextRecord.class,
- TestSheetPropertiesRecord.class,
- TestTextRecord.class,
- TestTickRecord.class,
- TestUnitsRecord.class,
- TestValueRangeRecord.class
-})
-public class AllChartRecordTests {
-}
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAreaFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAreaFormatRecord.java
index 9df58a8427..c8684fd20d 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestAreaFormatRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAreaFormatRecord.java
@@ -19,12 +19,12 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the AreaFormatRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAreaRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAreaRecord.java
index 1bf68f0558..0143a3fe0b 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestAreaRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAreaRecord.java
@@ -19,12 +19,12 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the AreaRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisLineFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisLineFormatRecord.java
index ac12f27119..d7cd652e46 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisLineFormatRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisLineFormatRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the AxisLineFormatRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java
index d17dcfa765..906544cf0a 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java
@@ -19,12 +19,12 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the AxisOptionsRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisParentRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisParentRecord.java
index 7f12260a89..581611161f 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisParentRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisParentRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the AxisParentRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisRecord.java
index 56ba5d58a3..7065c50f89 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the AxisRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisUsedRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisUsedRecord.java
index b2907aa5ea..13bc7826e7 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisUsedRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisUsedRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the AxisUsedRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestBarRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestBarRecord.java
index ca4f581612..911e72828b 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestBarRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestBarRecord.java
@@ -19,11 +19,11 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the BarRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestCategorySeriesAxisRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestCategorySeriesAxisRecord.java
index d23783b755..52ea943d21 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestCategorySeriesAxisRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestCategorySeriesAxisRecord.java
@@ -19,12 +19,12 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the CategorySeriesAxisRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java
index 8d497e8699..ce6ede8437 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java
@@ -17,14 +17,14 @@
package org.apache.poi.hssf.record.chart;
-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.record.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link ChartFormatRecord} Test data taken directly from a real
@@ -48,7 +48,7 @@ public final class TestChartFormatRecord {
public void testLoad() {
RecordInputStream in = TestcaseRecordInputStream.create(data);
ChartFormatRecord record = new ChartFormatRecord(in);
- assertNotEquals("Identified bug 44693d", 2, in.remaining());
+ assertNotEquals(2, in.remaining(), "Identified bug 44693d");
assertEquals(0, in.remaining());
assertEquals(24, record.getRecordSize());
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestChartRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestChartRecord.java
index 545e236623..621fa7676d 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestChartRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestChartRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the ChartRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestChartTitleFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestChartTitleFormatRecord.java
index 53774be9ac..eb3894ba4a 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestChartTitleFormatRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestChartTitleFormatRecord.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.chart;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.InputStream;
import java.util.ArrayList;
@@ -27,10 +27,9 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
import org.apache.poi.hssf.eventusermodel.HSSFListener;
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
-import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestChartTitleFormatRecord {
@@ -38,10 +37,10 @@ public final class TestChartTitleFormatRecord {
public void testRecord() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(
HSSFTestDataSamples.getSampleFile("WithFormattedGraphTitle.xls"));
-
+
// Check we can open the file via usermodel
HSSFWorkbook hssf = new HSSFWorkbook(fs);
-
+
// Now process it through eventusermodel, and
// look out for the title records
ChartTitleFormatRecordGrabber grabber = new ChartTitleFormatRecordGrabber();
@@ -51,21 +50,21 @@ public final class TestChartTitleFormatRecord {
HSSFEventFactory factory = new HSSFEventFactory();
factory.processEvents(req, din);
din.close();
-
+
// Should've found one
assertEquals(1, grabber.chartTitleFormatRecords.size());
// And it should be of something interesting
ChartTitleFormatRecord r = grabber.chartTitleFormatRecords.get(0);
assertEquals(3, r.getFormatCount());
-
+
hssf.close();
fs.close();
-
+
}
-
+
private static final class ChartTitleFormatRecordGrabber implements HSSFListener {
private final List<ChartTitleFormatRecord> chartTitleFormatRecords;
-
+
ChartTitleFormatRecordGrabber() {
chartTitleFormatRecords = new ArrayList<>();
}
@@ -76,6 +75,6 @@ public final class TestChartTitleFormatRecord {
chartTitleFormatRecords.add((ChartTitleFormatRecord)record);
}
}
-
+
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestDatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestDatRecord.java
index adce7880dc..71b0c6901c 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestDatRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestDatRecord.java
@@ -19,12 +19,12 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the DatRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestDataFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestDataFormatRecord.java
index 47b22d6a5d..b304166a5d 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestDataFormatRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestDataFormatRecord.java
@@ -19,11 +19,11 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the DataFormatRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestDefaultDataLabelTextPropertiesRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestDefaultDataLabelTextPropertiesRecord.java
index 1dd31d92d6..fe54c3d6c2 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestDefaultDataLabelTextPropertiesRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestDefaultDataLabelTextPropertiesRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the DefaultDataLabelTextPropertiesRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestFontBasisRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestFontBasisRecord.java
index d478945fbd..ce95d58328 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestFontBasisRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestFontBasisRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the FontBasisRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestFontIndexRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestFontIndexRecord.java
index 1f055491af..0bb9d954e7 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestFontIndexRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestFontIndexRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the FontIndexRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestFrameRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestFrameRecord.java
index 86e2729d4c..86ab6691fc 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestFrameRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestFrameRecord.java
@@ -19,12 +19,12 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the FrameRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestLegendRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestLegendRecord.java
index 16eaf33b72..1965bcf776 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestLegendRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestLegendRecord.java
@@ -18,12 +18,12 @@
package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the LegendRecord class works
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestLineFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestLineFormatRecord.java
index 7305134f35..dd2e5a60c5 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestLineFormatRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestLineFormatRecord.java
@@ -19,12 +19,12 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the LineFormatRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java
index ae5b652b9a..91bb43f998 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java
@@ -19,13 +19,13 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the LinkedDataRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestNumberFormatIndexRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestNumberFormatIndexRecord.java
index c5efa00df4..b2fe6db59c 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestNumberFormatIndexRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestNumberFormatIndexRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the NumberFormatIndexRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java
index 8913ca60d6..1641270e37 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the ObjectLinkRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestPlotAreaRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestPlotAreaRecord.java
index ece7eefd91..119cf47117 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestPlotAreaRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestPlotAreaRecord.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.record.chart;
-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;
/**
* Tests the serialization and deserialization of the PlotAreaRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestPlotGrowthRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestPlotGrowthRecord.java
index f12474fa54..235d144bbc 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestPlotGrowthRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestPlotGrowthRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the PlotGrowthRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesChartGroupIndexRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesChartGroupIndexRecord.java
index ea674198c9..27aec2c93b 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesChartGroupIndexRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesChartGroupIndexRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the SeriesChartGroupIndexRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java
index 1607f88cbd..92c54e4a47 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the SeriesIndexRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesLabelsRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesLabelsRecord.java
index 232a1f7b70..1454da7474 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesLabelsRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesLabelsRecord.java
@@ -19,12 +19,12 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the SeriesLabelsRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesListRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesListRecord.java
index fe310f233b..49cf366d84 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesListRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesListRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the SeriesListRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesRecord.java
index dd6c944881..2fd3d4384c 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the SeriesRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java
index 138415f49f..59dcb4b2ac 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java
@@ -18,13 +18,13 @@
package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.record.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the SeriesTextRecord class
@@ -88,7 +88,7 @@ public final class TestSeriesTextRecord {
// "Bad requested string length (-126)"
SeriesTextRecord str = new SeriesTextRecord(in);
- assertTrue("Identified bug 45784b", str.getRecordSize() >= 0);
+ assertTrue(str.getRecordSize() >= 0, "Identified bug 45784b");
byte[] ser = str.serialize();
confirmRecordEncoding(SeriesTextRecord.sid, data, ser);
}
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java
index fb9273fb30..2fc545854e 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java
@@ -19,14 +19,14 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link SheetPropertiesRecord}
@@ -43,7 +43,7 @@ public final class TestSheetPropertiesRecord {
public void testLoad() {
RecordInputStream in = TestcaseRecordInputStream.create(0x1044, data);
SheetPropertiesRecord record = new SheetPropertiesRecord(in);
- assertNotEquals("Identified bug 44693c", 1, in.remaining());
+ assertNotEquals(1, in.remaining(), "Identified bug 44693c");
assertEquals(0, in.remaining());
assertEquals( 10, record.getFlags());
assertFalse(record.isChartTypeManuallyFormatted());
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestTextRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestTextRecord.java
index 5e0b854743..99de874822 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestTextRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestTextRecord.java
@@ -19,12 +19,12 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the TextRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java
index 7b64608cda..7e5395f583 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java
@@ -19,11 +19,11 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the TickRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestUnitsRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestUnitsRecord.java
index f99c6a4e87..5996f909c5 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestUnitsRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestUnitsRecord.java
@@ -19,10 +19,10 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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;
/**
* Tests the serialization and deserialization of the UnitsRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestValueRangeRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestValueRangeRecord.java
index 5c5fe7bf69..d0314e1ae5 100644
--- a/src/testcases/org/apache/poi/hssf/record/chart/TestValueRangeRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/chart/TestValueRangeRecord.java
@@ -19,12 +19,12 @@ package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.hssf.record.TestcaseRecordInputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the serialization and deserialization of the ValueRangeRecord
diff --git a/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java b/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
index f1016745bb..ab43d21e3d 100644
--- a/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
+++ b/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.common;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -41,7 +41,7 @@ import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.LittleEndianOutputStream;
import org.apache.poi.util.StringUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests that {@link UnicodeString} record size calculates correctly. The record size
diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.java b/src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.java
deleted file mode 100644
index 3f25e99398..0000000000
--- a/src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.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.hssf.record.pivot;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for <tt>org.apache.poi.hssf.record.pivot</tt>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestExtendedPivotTableViewFieldsRecord.class,
- TestPageItemRecord.class,
- TestViewFieldsRecord.class
-})
-public final class AllPivotRecordTests {
-}
diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java b/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java
index 113951d32c..314fbdd686 100644
--- a/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java
@@ -18,13 +18,13 @@
package org.apache.poi.hssf.record.pivot;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.record.pivottable.ExtendedPivotTableViewFieldsRecord;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link ExtendedPivotTableViewFieldsRecord}
diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java b/src/testcases/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java
index 1468fc1401..e9f7ff1f36 100644
--- a/src/testcases/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java
@@ -18,14 +18,14 @@
package org.apache.poi.hssf.record.pivot;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.record.pivottable.PageItemRecord;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link PageItemRecord}
@@ -36,7 +36,7 @@ public final class TestPageItemRecord {
byte[] data = HexRead.readFromString("01 02 03 04 05 06 07 08 09 0A 0B 0C");
RecordInputStream in = TestcaseRecordInputStream.create(PageItemRecord.sid, data);
PageItemRecord rec = new PageItemRecord(in);
- assertNotEquals("Identified bug 46917", 6, in.remaining());
+ assertNotEquals(6, in.remaining(), "Identified bug 46917");
assertEquals(0, in.remaining());
assertEquals(4+data.length, rec.getRecordSize());
diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java b/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java
index 3ab92651b3..c51da99e2e 100644
--- a/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java
@@ -18,14 +18,14 @@
package org.apache.poi.hssf.record.pivot;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
-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.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.record.pivottable.ViewFieldsRecord;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link ViewFieldsRecord}
@@ -37,7 +37,7 @@ public final class TestViewFieldsRecord {
byte[] data = HexRead.readFromString("01 00 01 00 01 00 04 00 05 00 00 6D 61 72 63 6F");
RecordInputStream in = TestcaseRecordInputStream.create(ViewFieldsRecord.sid, data);
ViewFieldsRecord rec = new ViewFieldsRecord(in);
- assertNotEquals("Identified bug 46693b", 1, in.remaining());
+ assertNotEquals(1, in.remaining(), "Identified bug 46693b");
assertEquals(0, in.remaining());
assertEquals(4+data.length, rec.getRecordSize());
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java b/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
deleted file mode 100644
index bcbddf0551..0000000000
--- a/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
+++ /dev/null
@@ -1,76 +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.hssf.usermodel;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for the <tt>org.apache.poi.hssf.usermodel</tt> package.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestBug42464.class,
- TestBugs.class,
- TestCellStyle.class,
- TestCloneSheet.class,
- TestDataValidation.class,
- TestEscherGraphics.class,
- TestEscherGraphics2d.class,
- TestFontDetails.class,
- TestFormulaEvaluatorBugs.class,
- TestFormulaEvaluatorDocs.class,
- TestFormulas.class,
- TestHSSFCell.class,
- TestHSSFClientAnchor.class,
- //TestHSSFComment.class, //converted to junit4
- TestHSSFConditionalFormatting.class,
- TestHSSFDataFormat.class,
- TestHSSFDataFormatter.class,
- TestHSSFDateUtil.class,
- TestHSSFFont.class,
- TestHSSFFormulaEvaluator.class,
- TestHSSFHeaderFooter.class,
- TestHSSFHyperlink.class,
- TestHSSFName.class,
- TestHSSFOptimiser.class,
- TestHSSFPalette.class,
- TestHSSFPatriarch.class,
- TestHSSFPicture.class,
- TestHSSFPictureData.class,
- TestHSSFRichTextString.class,
- TestHSSFRow.class,
- TestHSSFSheet.class,
- TestHSSFSheetShiftRows.class,
- TestHSSFSheetUpdateArrayFormulas.class,
- TestHSSFTextbox.class,
- TestHSSFWorkbook.class,
- TestOLE2Embeding.class,
- TestPOIFSProperties.class,
- TestReadWriteChart.class,
- TestRowStyle.class,
- TestSanityChecker.class,
- TestSheetHiding.class,
- /* deliberately avoiding this one
- TestUnfixedBugs.class,*/
- TestUnicodeWorkbook.class,
- TestNonStandardWorkbookStreamNames.class,
- TestWorkbook.class
-})
-public class AllUserModelTests {
-}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/SanityChecker.java b/src/testcases/org/apache/poi/hssf/usermodel/SanityChecker.java
index 04ac448d25..0f67a86c10 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/SanityChecker.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/SanityChecker.java
@@ -19,188 +19,107 @@
package org.apache.poi.hssf.usermodel;
-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.assertTrue;
import java.util.List;
import org.apache.poi.hssf.model.InternalSheet;
import org.apache.poi.hssf.model.InternalWorkbook;
-import org.apache.poi.hssf.record.BOFRecord;
-import org.apache.poi.hssf.record.BackupRecord;
-import org.apache.poi.hssf.record.BookBoolRecord;
-import org.apache.poi.hssf.record.BoundSheetRecord;
-import org.apache.poi.hssf.record.CalcModeRecord;
-import org.apache.poi.hssf.record.CodepageRecord;
-import org.apache.poi.hssf.record.CountryRecord;
-import org.apache.poi.hssf.record.DSFRecord;
-import org.apache.poi.hssf.record.DateWindow1904Record;
-import org.apache.poi.hssf.record.DefaultColWidthRecord;
-import org.apache.poi.hssf.record.DefaultRowHeightRecord;
-import org.apache.poi.hssf.record.DeltaRecord;
-import org.apache.poi.hssf.record.DimensionsRecord;
-import org.apache.poi.hssf.record.EOFRecord;
-import org.apache.poi.hssf.record.ExtSSTRecord;
-import org.apache.poi.hssf.record.ExtendedFormatRecord;
-import org.apache.poi.hssf.record.ExternSheetRecord;
-import org.apache.poi.hssf.record.FnGroupCountRecord;
-import org.apache.poi.hssf.record.FontRecord;
-import org.apache.poi.hssf.record.FormatRecord;
-import org.apache.poi.hssf.record.GridsetRecord;
-import org.apache.poi.hssf.record.GutsRecord;
-import org.apache.poi.hssf.record.HideObjRecord;
-import org.apache.poi.hssf.record.InterfaceEndRecord;
-import org.apache.poi.hssf.record.InterfaceHdrRecord;
-import org.apache.poi.hssf.record.IterationRecord;
-import org.apache.poi.hssf.record.MMSRecord;
-import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.PasswordRev4Record;
-import org.apache.poi.hssf.record.PrecisionRecord;
-import org.apache.poi.hssf.record.PrintGridlinesRecord;
-import org.apache.poi.hssf.record.PrintHeadersRecord;
-import org.apache.poi.hssf.record.ProtectRecord;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.RecordBase;
-import org.apache.poi.hssf.record.RefModeRecord;
-import org.apache.poi.hssf.record.RefreshAllRecord;
-import org.apache.poi.hssf.record.SSTRecord;
-import org.apache.poi.hssf.record.SaveRecalcRecord;
-import org.apache.poi.hssf.record.SelectionRecord;
-import org.apache.poi.hssf.record.StyleRecord;
-import org.apache.poi.hssf.record.SupBookRecord;
-import org.apache.poi.hssf.record.TabIdRecord;
-import org.apache.poi.hssf.record.UseSelFSRecord;
-import org.apache.poi.hssf.record.WSBoolRecord;
-import org.apache.poi.hssf.record.WindowOneRecord;
-import org.apache.poi.hssf.record.WindowProtectRecord;
-import org.apache.poi.hssf.record.WindowTwoRecord;
-import org.apache.poi.hssf.record.WriteAccessRecord;
+import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
/**
* Designed to check wither the records written actually make sense.
*/
public class SanityChecker {
- static class CheckRecord
- {
+ static class CheckRecord {
Class<? extends RecordBase> record;
char occurance; // 1 = one time, M = 1..many times, * = 0..many, 0 = optional
private final boolean together;
- public CheckRecord( Class<? extends RecordBase> record, char occurance )
- {
+ public CheckRecord(Class<? extends RecordBase> record, char occurance) {
this(record, occurance, true);
}
/**
- * @param record The record type to check
- * @param occurance The occurance 1 = occurs once, M = occurs many times
+ * @param record The record type to check
+ * @param occurance The occurance 1 = occurs once, M = occurs many times
* @param together
*/
- public CheckRecord(Class<? extends RecordBase> record, char occurance, boolean together)
- {
+ public CheckRecord(Class<? extends RecordBase> record, char occurance, boolean together) {
this.record = record;
this.occurance = occurance;
this.together = together;
}
- public Class<? extends RecordBase> getRecord()
- {
+ public Class<? extends RecordBase> getRecord() {
return record;
}
- public char getOccurance()
- {
- return occurance;
- }
-
- public boolean isRequired()
- {
+ public boolean isRequired() {
return occurance == '1' || occurance == 'M';
}
- public boolean isOptional()
- {
+ public boolean isOptional() {
return occurance == '0' || occurance == '*';
}
- public boolean isTogether()
- {
- return together;
- }
-
- public boolean isMany()
- {
+ public boolean isMany() {
return occurance == '*' || occurance == 'M';
}
- public int match( List<? extends RecordBase> records, int recordIdx )
- {
+ public int match(List<? extends RecordBase> records, int recordIdx) {
int firstRecord = findFirstRecord(records, getRecord(), recordIdx);
- if (isRequired())
- {
- return matchRequired( firstRecord, records, recordIdx );
+ if (isRequired()) {
+ return matchRequired(firstRecord, records, recordIdx);
}
- return matchOptional( firstRecord, records, recordIdx );
+ return matchOptional(firstRecord, records, recordIdx);
}
- private int matchOptional( int firstRecord, List<? extends RecordBase> records, int recordIdx )
- {
- if (firstRecord == -1)
- {
+ private int matchOptional(int firstRecord, List<? extends RecordBase> records, int recordIdx) {
+ if (firstRecord == -1) {
return recordIdx;
}
- return matchOneOrMany( records, firstRecord );
+ return matchOneOrMany(records, firstRecord);
}
- private int matchRequired( int firstRecord, List<? extends RecordBase> records, int recordIdx )
- {
- if (firstRecord == -1)
- {
- fail("Manditory record missing or out of order: " + record);
- }
+ private int matchRequired(int firstRecord, List<? extends RecordBase> records, int recordIdx) {
+ assertNotEquals(-1, firstRecord, "Manditory record missing or out of order: " + record);
- return matchOneOrMany( records, firstRecord );
+ return matchOneOrMany(records, firstRecord);
}
- private int matchOneOrMany( List<? extends RecordBase> records, int recordIdx )
- {
- if (isZeroOrOne())
- {
+ private int matchOneOrMany(List<? extends RecordBase> records, int recordIdx) {
+ if (isZeroOrOne()) {
// check no other records
- if (findFirstRecord(records, getRecord(), recordIdx+1) != -1)
- fail("More than one record matched for " + getRecord().getName());
- }
- else if (isZeroToMany())
- {
- if (together)
- {
- int nextIdx = findFirstRecord(records, record, recordIdx+1);
- while (nextIdx != -1)
- {
- if (nextIdx - 1 != recordIdx)
- fail("Records are not together " + record.getName());
+ assertEquals(-1, findFirstRecord(records, getRecord(), recordIdx + 1),
+ "More than one record matched for " + getRecord().getName());
+ } else if (isZeroToMany()) {
+ if (together) {
+ int nextIdx = findFirstRecord(records, record, recordIdx + 1);
+ while (nextIdx != -1) {
+ assertEquals(recordIdx+1, nextIdx, "Records are not together " + record.getName());
recordIdx = nextIdx;
- nextIdx = findFirstRecord(records, record, recordIdx+1);
+ nextIdx = findFirstRecord(records, record, recordIdx + 1);
}
}
}
- return recordIdx+1;
+ return recordIdx + 1;
}
- private boolean isZeroToMany()
- {
+ private boolean isZeroToMany() {
return occurance == '*' || occurance == 'M';
}
- private boolean isZeroOrOne()
- {
+ private boolean isZeroOrOne() {
return occurance == '0' || occurance == '1';
}
}
- CheckRecord[] workbookRecords = new CheckRecord[] {
+ CheckRecord[] workbookRecords = {
new CheckRecord(BOFRecord.class, '1'),
new CheckRecord(InterfaceHdrRecord.class, '1'),
new CheckRecord(MMSRecord.class, '1'),
@@ -235,7 +154,7 @@ public class SanityChecker {
new CheckRecord(EOFRecord.class, '1'),
};
- CheckRecord[] sheetRecords = new CheckRecord[] {
+ CheckRecord[] sheetRecords = {
new CheckRecord(BOFRecord.class, '1'),
new CheckRecord(CalcModeRecord.class, '1'),
new CheckRecord(RefModeRecord.class, '1'),
@@ -256,14 +175,12 @@ public class SanityChecker {
new CheckRecord(EOFRecord.class, '1')
};
- private void checkWorkbookRecords(InternalWorkbook workbook)
- {
+ private void checkWorkbookRecords(InternalWorkbook workbook) {
List<org.apache.poi.hssf.record.Record> records = workbook.getRecords();
assertTrue(records.get(0) instanceof BOFRecord);
assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
checkRecordOrder(records, workbookRecords);
-// checkRecordsTogether(records, workbookRecords);
}
private void checkSheetRecords(InternalSheet sheet) {
@@ -272,104 +189,27 @@ public class SanityChecker {
assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
checkRecordOrder(records, sheetRecords);
-// checkRecordsTogether(records, sheetRecords);
}
- public void checkHSSFWorkbook(HSSFWorkbook wb)
- {
+ public void checkHSSFWorkbook(HSSFWorkbook wb) {
checkWorkbookRecords(wb.getWorkbook());
for (int i = 0; i < wb.getNumberOfSheets(); i++)
checkSheetRecords(wb.getSheetAt(i).getSheet());
}
- /*
- private void checkRecordsTogether(List records, CheckRecord[] check)
- {
- for ( int checkIdx = 0; checkIdx < check.length; checkIdx++ )
- {
- int recordIdx = findFirstRecord(records, check[checkIdx].getRecord());
- boolean notFoundAndRecordRequired = (recordIdx == -1 && check[checkIdx].isRequired());
- if (notFoundAndRecordRequired)
- {
- fail("Expected to find record of class " + check.getClass() + " but did not");
- }
- else if (recordIdx >= 0)
- {
- if (check[checkIdx].isMany())
- {
- // Skip records that are together
- while (recordIdx < records.size() && check[checkIdx].getRecord().isInstance(records.get(recordIdx)))
- recordIdx++;
- }
-
- // Make sure record does not occur in remaining records (after the next)
- recordIdx++;
- for (int recordIdx2 = recordIdx; recordIdx2 < records.size(); recordIdx2++)
- {
- if (check[checkIdx].getRecord().isInstance(records.get(recordIdx2)))
- fail("Record occurs scattered throughout record chain:\n" + records.get(recordIdx2));
- }
- }
- }
- } */
-
- /* package */ static int findFirstRecord( List<? extends RecordBase> records, Class<? extends RecordBase> record, int startIndex )
- {
- for (int i = startIndex; i < records.size(); i++)
- {
+ static int findFirstRecord(List<? extends RecordBase> records, Class<? extends RecordBase> record, int startIndex) {
+ for (int i = startIndex; i < records.size(); i++) {
if (record.getName().equals(records.get(i).getClass().getName()))
return i;
}
return -1;
}
- void checkRecordOrder(List<? extends RecordBase> records, CheckRecord[] check)
- {
+ void checkRecordOrder(List<? extends RecordBase> records, CheckRecord[] check) {
int recordIdx = 0;
for (CheckRecord element : check) {
recordIdx = element.match(records, recordIdx);
}
}
-
- /*
- void checkRecordOrder(List records, CheckRecord[] check)
- {
- int checkIndex = 0;
- for (int recordIndex = 0; recordIndex < records.size(); recordIndex++)
- {
- Record record = (org.apache.poi.hssf.record.Record) records.get(recordIndex);
- if (check[checkIndex].getRecord().isInstance(record))
- {
- if (check[checkIndex].getOccurance() == 'M')
- {
- // skip over duplicate records if multiples are allowed
- while (recordIndex+1 < records.size() && check[checkIndex].getRecord().isInstance(records.get(recordIndex+1)))
- recordIndex++;
-// lastGoodMatch = recordIndex;
- }
- else if (check[checkIndex].getOccurance() == '1')
- {
- // Check next record to make sure there's not more than one
- if (recordIndex != records.size() - 1)
- {
- if (check[checkIndex].getRecord().isInstance(records.get(recordIndex+1)))
- {
- fail("More than one occurance of record found:\n" + records.get(recordIndex).toString());
- }
- }
-// lastGoodMatch = recordIndex;
- }
-// else if (check[checkIndex].getOccurance() == '0')
-// {
-//
-// }
- checkIndex++;
- }
- if (checkIndex >= check.length)
- return;
- }
- fail("Could not find required record: " + check[checkIndex]);
- } */
-
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
index 5e414f08a7..6f51abef42 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
@@ -17,19 +17,19 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Iterator;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
-import org.apache.poi.ss.util.CellReference;
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.Row;
-import org.junit.Test;
+import org.apache.poi.ss.util.CellReference;
+import org.junit.jupiter.api.Test;
/**
*
@@ -42,7 +42,7 @@ public final class TestBug42464 {
process(wb);
wb.close();
}
-
+
@Test
public void testExpSharedBadFile() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-bad.xls");
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index 24c5bf4c92..342335e267 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -20,7 +20,7 @@ package org.apache.poi.hssf.usermodel;
import static org.apache.poi.POITestCase.assertContains;
import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
import static org.apache.poi.hssf.HSSFTestDataSamples.writeOutAndReadBack;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
@@ -88,11 +88,11 @@ import org.apache.poi.ss.usermodel.SheetVisibility;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.LocaleUtil;
-import org.junit.AfterClass;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* Testcases for bugs entered in bugzilla
@@ -110,7 +110,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
private static final Map<String,HSSFFormulaEvaluator> SIMPLE_REFS = new LinkedHashMap<>();
// References used for the simpleTest convenience method
- @BeforeClass
+ @BeforeAll
public static void initSimpleRefs() {
String[] refs = {
"Calculations",
@@ -138,7 +138,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
LocaleUtil.setUserLocale(Locale.US);
}
- @AfterClass
+ @AfterAll
public static void cleanUpRefs() {
SIMPLE_REFS.clear();
}
@@ -837,7 +837,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
* Problems with extracting check boxes from
* HSSFObjectData
*/
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void bug44840() throws Exception {
try (HSSFWorkbook wb = openSampleWorkbook("WithCheckBoxes.xls")) {
@@ -863,7 +863,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
assertEquals(12, obj.getObjectData().length);
assertEquals("Forms.CheckBox.1", obj.getOLE2ClassName());
- obj.getDirectory();
+ assertThrows(IllegalArgumentException.class, obj::getDirectory);
}
}
@@ -1001,13 +1001,8 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// formula cells, so we can see it updates properly
c3.setCellValue(new HSSFRichTextString("test"));
confirmCachedValue("test", c3);
- try {
- c3.getNumericCellValue();
- fail("exception should have been thrown");
- } catch (IllegalStateException e) {
- assertEquals("Cannot get a NUMERIC value from a STRING formula cell", e.getMessage());
- }
-
+ IllegalStateException e = assertThrows(IllegalStateException.class, c3::getNumericCellValue);
+ assertEquals("Cannot get a NUMERIC value from a STRING formula cell", e.getMessage());
// Now evaluate, they should all be changed
HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb1);
@@ -1082,7 +1077,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
* <p>
* Expected ExpPtg to be converted from Shared to Non-Shared...
*/
- @Ignore("For now, blows up with an exception from ExtPtg")
+ @Disabled("For now, blows up with an exception from ExtPtg")
@Test
public void test43623() throws Exception {
try (HSSFWorkbook wb1 = openSampleWorkbook("43623.xls")) {
@@ -1913,12 +1908,10 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Will show as the center, as that is what excel does
// with an invalid footer lacking left/right/center details
- assertEquals("Left text should be empty", "", f.getLeft());
- assertEquals("Right text should be empty", "", f.getRight());
- assertEquals(
- "Center text should contain the illegal value",
- "BlahBlah blah blah ", f.getCenter()
- );
+ assertEquals("", f.getLeft(), "Left text should be empty");
+ assertEquals("", f.getRight(), "Right text should be empty");
+ assertEquals("BlahBlah blah blah ", f.getCenter(),
+ "Center text should contain the illegal value");
}
}
@@ -2226,9 +2219,9 @@ public final class TestBugs extends BaseTestBugzillaIssues {
* Normally encrypted files have BOF then FILEPASS, but
* some may squeeze a WRITEPROTECT in the middle
*/
- @Test(expected = EncryptedDocumentException.class)
- public void bug51832() throws IOException {
- simpleTest("51832.xls");
+ @Test
+ public void bug51832() {
+ assertThrows(EncryptedDocumentException.class, () -> simpleTest("51832.xls"));
}
@Test
@@ -2265,9 +2258,9 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Problem 3: These used to fail, now pass
HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb);
- assertEquals("evaluating c1", 30.0, eval.evaluate(c1).getNumberValue(), 0.001);
- assertEquals("evaluating d1", 30.0, eval.evaluate(d1).getNumberValue(), 0.001);
- assertEquals("evaluating e1", 30.0, eval.evaluate(e1).getNumberValue(), 0.001);
+ assertEquals(30.0, eval.evaluate(c1).getNumberValue(), 0.001, "evaluating c1");
+ assertEquals(30.0, eval.evaluate(d1).getNumberValue(), 0.001, "evaluating d1");
+ assertEquals(30.0, eval.evaluate(e1).getNumberValue(), 0.001, "evaluating e1");
}
}
@@ -2697,7 +2690,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
try {
bimage = ImageIO.read(structURL);
} catch (IOException e) {
- Assume.assumeNoException("Downloading a jpg from poi.apache.org should work", e);
+ Assumptions.assumeFalse(true, "Downloading a jpg from poi.apache.org should work");
return;
}
@@ -2711,7 +2704,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Pop structure into Structure HSSFSheet
int pict = wb.addPicture(imageBytes, HSSFWorkbook.PICTURE_TYPE_JPEG);
Sheet sheet = wb.getSheet("Structure");
- assertNotNull("Did not find sheet", sheet);
+ assertNotNull(sheet, "Did not find sheet");
HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 10, 22);
anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
index 1bac320643..4f856657fb 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.usermodel;
-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.assertNotSame;
-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.assertNotEquals;
+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.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
@@ -45,7 +45,7 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.TempFile;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test cell styling functionality
@@ -97,8 +97,8 @@ public final class TestCellStyle {
SanityChecker sanityChecker = new SanityChecker();
sanityChecker.checkHSSFWorkbook(wb);
- assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
- assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
+ assertEquals(99, s.getLastRowNum(), "LAST ROW == 99");
+ assertEquals(0, s.getFirstRowNum(), "FIRST ROW == 0");
}
// assert((s.getLastRowNum() == 99));
@@ -134,8 +134,8 @@ public final class TestCellStyle {
SanityChecker sanityChecker = new SanityChecker();
sanityChecker.checkHSSFWorkbook(wb);
- assertEquals("LAST ROW ", 0, s.getLastRowNum());
- assertEquals("FIRST ROW ", 0, s.getFirstRowNum());
+ assertEquals(0, s.getLastRowNum(), "LAST ROW");
+ assertEquals(0, s.getFirstRowNum(), "FIRST ROW");
}
}
@@ -185,8 +185,6 @@ public final class TestCellStyle {
File file = TempFile.createTempFile("testWriteSheetStyle", ".xls");
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet s = wb.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
HSSFFont fnt = wb.createFont();
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
@@ -203,10 +201,10 @@ public final class TestCellStyle {
cs2.setFillPattern(FillPatternType.DIAMONDS);
cs2.setFont(fnt);
for (int rownum = 0; rownum < 100; rownum++) {
- r = s.createRow(rownum);
+ HSSFRow r = s.createRow(rownum);
for (int cellnum = 0; cellnum < 50; cellnum += 2) {
- c = r.createCell(cellnum);
+ HSSFCell c = r.createCell(cellnum);
c.setCellValue(rownum * 10000 + cellnum
+ (((double) rownum / 1000)
+ ((double) cellnum / 10000)));
@@ -221,8 +219,8 @@ public final class TestCellStyle {
}
SanityChecker sanityChecker = new SanityChecker();
sanityChecker.checkHSSFWorkbook(wb);
- assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
- assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
+ assertEquals(99, s.getLastRowNum(), "LAST ROW == 99");
+ assertEquals(0, s.getFirstRowNum(), "FIRST ROW == 0");
}
}
@@ -455,13 +453,13 @@ public final class TestCellStyle {
Sheet sheet = wb.getSheetAt(0);
for (Row row : sheet) {
- for (Integer idxCell = 0; idxCell < row.getLastCellNum(); idxCell++) {
+ for (int idxCell = 0; idxCell < row.getLastCellNum(); idxCell++) {
Cell cell = row.getCell(idxCell);
cell.getCellStyle().getDataFormatString();
if (cell.getCellType() == CellType.NUMERIC) {
boolean isDate = DateUtil.isCellDateFormatted(cell);
- assertFalse("cell " + idxCell + " is not a date.", idxCell > 0 && isDate);
+ assertFalse(idxCell > 0 && isDate, "cell " + idxCell + " is not a date.");
}
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
index 5bdfe6227b..d8e6ea92e8 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
@@ -17,18 +17,21 @@
package org.apache.poi.hssf.usermodel;
+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.assertNull;
+
+import java.io.IOException;
+import java.util.Arrays;
+
import org.apache.poi.ddf.EscherDgRecord;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
import org.apache.poi.hssf.record.EscherAggregate;
import org.apache.poi.ss.usermodel.BaseTestCloneSheet;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.util.Arrays;
-
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.Test;
/**
* Test the ability to clone a sheet.
@@ -46,7 +49,7 @@ public final class TestCloneSheet extends BaseTestCloneSheet {
HSSFWorkbook b = new HSSFWorkbook();
HSSFSheet s = b.createSheet("Test");
HSSFSheet s2 = s.cloneSheet(b);
-
+
assertNull(s.getDrawingPatriarch());
assertNull(s2.getDrawingPatriarch());
assertEquals(HSSFTestHelper.getSheetForTest(s).getRecords().size(), HSSFTestHelper.getSheetForTest(s2).getRecords().size());
@@ -97,7 +100,7 @@ public final class TestCloneSheet extends BaseTestCloneSheet {
c.setColumn(1);
c.setRow(2);
c.setString(new HSSFRichTextString("qwertyuio"));
-
+
HSSFSheet sh2 = wb.cloneSheet(0);
HSSFPatriarch p2 = sh2.getDrawingPatriarch();
HSSFComment c2 = (HSSFComment) p2.getChildren().get(0);
@@ -106,11 +109,11 @@ public final class TestCloneSheet extends BaseTestCloneSheet {
assertEquals(c.getRow(), c2.getRow());
assertEquals(c.getColumn(), c2.getColumn());
- // The ShapeId is not equal?
+ // The ShapeId is not equal?
// assertEquals(c.getNoteRecord().getShapeId(), c2.getNoteRecord().getShapeId());
-
+
assertArrayEquals(c2.getTextObjectRecord().serialize(), c.getTextObjectRecord().serialize());
-
+
// ShapeId is different
CommonObjectDataSubRecord subRecord = (CommonObjectDataSubRecord) c2.getObjRecord().getSubRecords().get(0);
subRecord.setObjectId(1025);
@@ -126,7 +129,7 @@ public final class TestCloneSheet extends BaseTestCloneSheet {
EscherSpRecord sp = (EscherSpRecord) c2.getEscherContainer().getChild(0);
sp.setShapeId(1025);
assertArrayEquals(c2.getEscherContainer().serialize(), c.getEscherContainer().serialize());
-
+
wb.close();
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCryptoAPI.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCryptoAPI.java
index 92e5f64472..b03292cd71 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestCryptoAPI.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCryptoAPI.java
@@ -24,8 +24,7 @@ import java.io.IOException;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
-import org.junit.AfterClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestCryptoAPI {
final HSSFITestDataProvider ssTests = HSSFITestDataProvider.instance;
@@ -44,7 +43,7 @@ public class TestCryptoAPI {
// CryptoAPI
validateContent("35897-type4.xls", "freedom", "Sheet1\nhello there!\n");
}
-
+
private void validateContent(String wbFile, String password, String textExpected) throws IOException {
Biff8EncryptionKey.setCurrentUserPassword(password);
try (HSSFWorkbook wb = ssTests.openSampleWorkbook(wbFile);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java b/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java
index 1e3fc381cc..51bca0f4af 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java
@@ -17,11 +17,12 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -45,7 +46,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.CellRangeAddressList;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class for testing Excel's data validation mechanism
@@ -164,9 +165,7 @@ public final class TestDataValidation extends BaseTestDataValidation {
// nextSid should be for a DVRecord. If anything comes between the DV header record
// and the DV records, Excel will not be able to open the workbook without error.
- if (nextSid == 0x0867) {
- fail("Identified bug 45519");
- }
+ assertNotEquals(0x0867, nextSid, "Identified bug 45519");
assertEquals(DVRecord.sid, nextSid);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestEmbeddedObjects.java b/src/testcases/org/apache/poi/hssf/usermodel/TestEmbeddedObjects.java
index 51a5c64847..af2c703582 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestEmbeddedObjects.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestEmbeddedObjects.java
@@ -17,14 +17,14 @@
package org.apache.poi.hssf.usermodel;
-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;
import java.util.List;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for the embedded object fetching support in HSSF
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java
index f8c4c65c7e..4f4cce473e 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.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.awt.Color;
import java.awt.Font;
@@ -28,9 +28,9 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-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;
/**
* Tests the capabilities of the EscherGraphics class.
@@ -45,7 +45,7 @@ public final class TestEscherGraphics {
private HSSFShapeGroup escherGroupA;
private EscherGraphics graphics;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
workbook = new HSSFWorkbook();
@@ -55,8 +55,8 @@ public final class TestEscherGraphics {
patriarch.createGroup(new HSSFClientAnchor(20,30,500,200,(short)0,0,(short) 0,0));
graphics = new EscherGraphics(escherGroupA, workbook, Color.black, 1.0f);
}
-
- @After
+
+ @AfterEach
public void closeResources() throws IOException {
workbook.close();
}
@@ -268,9 +268,9 @@ public final class TestEscherGraphics {
assertEquals(40, patriarch.getY2());
// Check the two groups and the text
- // Result of patriarch.countOfAllChildren() makes no sense:
+ // Result of patriarch.countOfAllChildren() makes no sense:
// Returns 4 for 2 empty groups + 1 TextBox.
- //assertEquals(3, patriarch.countOfAllChildren());
+ //assertEquals(3, patriarch.countOfAllChildren());
assertEquals(3, patriarch.getChildren().size());
// Should be two groups and a text
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java
index e765936b01..f207b9a117 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java
@@ -17,9 +17,8 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
-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.assertThrows;
import java.awt.Color;
import java.awt.Font;
@@ -27,9 +26,9 @@ import java.awt.FontMetrics;
import java.awt.geom.Line2D;
import java.io.IOException;
-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;
/**
* Tests the Graphics2d drawing capability.
@@ -39,7 +38,7 @@ public final class TestEscherGraphics2d {
private HSSFShapeGroup escherGroup;
private EscherGraphics2d graphics;
- @Before
+ @BeforeEach
public void setUp() {
workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("test");
@@ -48,8 +47,8 @@ public final class TestEscherGraphics2d {
EscherGraphics g = new EscherGraphics(escherGroup, workbook, Color.black, 1.0f);
graphics = new EscherGraphics2d(g);
}
-
- @After
+
+ @AfterEach
public void closeResources() throws IOException {
workbook.close();
}
@@ -77,12 +76,7 @@ public final class TestEscherGraphics2d {
// But with an invalid font, we get an exception
font = new Font("IamAmadeUPfont", Font.PLAIN, 22);
graphics.setFont(font);
- try {
- graphics.drawString("This is another test", 10, 10);
- fail();
- } catch(IllegalArgumentException e) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> graphics.drawString("This is another test", 10, 10));
}
@Test
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestExternalReferenceChange.java b/src/testcases/org/apache/poi/hssf/usermodel/TestExternalReferenceChange.java
index 39d7e13d90..b60b5c10c1 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestExternalReferenceChange.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestExternalReferenceChange.java
@@ -16,16 +16,16 @@
==================================================================== */
package org.apache.poi.hssf.usermodel;
-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 java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.CellType;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestExternalReferenceChange {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java
index 724ffb29d0..0b469d64a8 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java
@@ -17,12 +17,12 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Properties;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests the implementation of the FontDetails class.
@@ -30,7 +30,7 @@ import org.junit.Test;
public final class TestFontDetails {
private FontDetails fontDetails;
- @Before
+ @BeforeEach
public void setUp() {
Properties properties = new Properties();
properties.setProperty("font.Arial.height", "13");
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
index 61103829af..dc03e67cfd 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
-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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.FileOutputStream;
@@ -45,8 +45,8 @@ import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.LocaleUtil;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
*
@@ -55,7 +55,7 @@ public final class TestFormulaEvaluatorBugs {
private static boolean OUTPUT_TEST_FILES;
private static String tmpDirName;
- @BeforeClass
+ @BeforeAll
public static void setUp() {
tmpDirName = System.getProperty("java.io.tmpdir");
OUTPUT_TEST_FILES = Boolean.parseBoolean(
@@ -95,7 +95,7 @@ public final class TestFormulaEvaluatorBugs {
System.err.println("Existing file for bug #44636 written to " + existing);
}
wb.close();
-
+
// Now, do a new file from scratch
wb = new HSSFWorkbook();
sheet = wb.createSheet();
@@ -182,7 +182,7 @@ public final class TestFormulaEvaluatorBugs {
cell = row.getCell(0);
assertEquals("-1000000-3000000", cell.getCellFormula());
assertEquals(-4000000, eva.evaluate(cell).getNumberValue(), 0);
-
+
wb.close();
}
@@ -243,7 +243,7 @@ public final class TestFormulaEvaluatorBugs {
HSSFCell cellSUM2D = rowSUM2D.getCell(0);
assertEquals("SUM(C:D)", cellSUM2D.getCellFormula());
assertEquals(66, eva.evaluate(cellSUM2D).getNumberValue(), 0);
-
+
wb.close();
}
@@ -267,7 +267,7 @@ public final class TestFormulaEvaluatorBugs {
fail("Identified bug 44508");
}
assertTrue(cell.getBooleanCellValue());
-
+
wb.close();
}
@@ -292,27 +292,24 @@ public final class TestFormulaEvaluatorBugs {
}
}
}
-
+
wb.close();
}
@Test
public void testEvaluateInCellWithErrorCode_bug44950() throws Exception {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet("Sheet1");
- HSSFRow row = sheet.createRow(1);
- HSSFCell cell = row.createCell(0);
- cell.setCellFormula("na()"); // this formula evaluates to an Excel error code '#N/A'
- HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
- try {
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ HSSFSheet sheet = wb.createSheet("Sheet1");
+ HSSFRow row = sheet.createRow(1);
+ HSSFCell cell = row.createCell(0);
+ cell.setCellFormula("na()"); // this formula evaluates to an Excel error code '#N/A'
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
fe.evaluateInCell(cell);
} catch (NumberFormatException e) {
if (e.getMessage().equals("You cannot get an error value from a non-error cell")) {
fail("Identified bug 44950 b");
}
throw e;
- } finally {
- wb.close();
}
}
@@ -357,7 +354,7 @@ public final class TestFormulaEvaluatorBugs {
cell.setCellFormula("DATE(2012,2-12,1+4)");
fe.notifyUpdateCell(cell);
assertEquals(40579.0, fe.evaluate(cell).getNumberValue(), 0);
-
+
wb.close();
}
@@ -420,13 +417,11 @@ public final class TestFormulaEvaluatorBugs {
WorkbookEvaluator evaluator = WorkbookEvaluatorTestHelper.createEvaluator(wb, evalListener);
ValueEval ve = evaluator.evaluate(HSSFEvaluationTestHelper.wrapCell(cell));
int evalCount = evalListener.getCountCacheMisses();
- if (evalCount > 10) {
- // Without caching, evaluating cell 'A9' takes 21845 evaluations which consumes
- // much time (~3 sec on Core 2 Duo 2.2GHz)
- // short-circuit-if optimisation cuts this down to 255 evaluations which is still too high
- // System.err.println("Cell A9 took " + evalCount + " intermediate evaluations");
- fail("Identifed bug 45376 - Formula evaluator should cache values");
- }
+ // Without caching, evaluating cell 'A9' takes 21845 evaluations which consumes
+ // much time (~3 sec on Core 2 Duo 2.2GHz)
+ // short-circuit-if optimisation cuts this down to 255 evaluations which is still too high
+ // System.err.println("Cell A9 took " + evalCount + " intermediate evaluations");
+ assertTrue(evalCount <= 10, "Identifed bug 45376 - Formula evaluator should cache values");
// With caching, the evaluationCount is 8 which is exactly the
// number of formula cells that needed to be evaluated.
assertEquals(8, evalCount);
@@ -440,7 +435,7 @@ public final class TestFormulaEvaluatorBugs {
// confirm the evaluation result too
assertEquals(ErrorEval.NA, ve);
-
+
wb.close();
}
@@ -527,22 +522,22 @@ public final class TestFormulaEvaluatorBugs {
cell = row.getCell(CellReference.convertColStringToIndex("B"));
assertRefPtgA1('V', getPtgs(cell), 0);
// assertRefPtgA1('V', getPtgs(cell), 4); // FIXME!
-
+
cell = row.getCell(CellReference.convertColStringToIndex("D"));
assertRefPtgA1('V', getPtgs(cell), 0);
// assertRefPtgA1('V', getPtgs(cell), 6); // FIXME!
-
+
cell = row.getCell(CellReference.convertColStringToIndex("F"));
assertRefPtgA1('V', getPtgs(cell), 0);
// assertRefPtgA1('V', getPtgs(cell), 4); // FIXME!
// assertRefPtgA1('V', getPtgs(cell), 9); // FIXME!
-
+
cell = row.getCell(CellReference.convertColStringToIndex("G"));
assertRefPtgA1('V', getPtgs(cell), 0);
// assertRefPtgA1('V', getPtgs(cell), 4); // FIXME!
// assertRefPtgA1('V', getPtgs(cell), 9); // FIXME!
-
-
+
+
// Check our cached values were correctly evaluated
cell = row.getCell(CellReference.convertColStringToIndex("A"));
assertEquals("abc", cell.getStringCellValue());
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java
index 30c85cbe3d..c718fece8d 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
@@ -25,7 +25,7 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
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 to show that our documentation at
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
index d2aeaf3803..8ef9614e57 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.usermodel;
import static org.apache.poi.hssf.HSSFTestDataSamples.writeOutAndReadBack;
-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 java.io.File;
import java.io.FileOutputStream;
@@ -40,7 +40,7 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.TempFile;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestFormulas {
@@ -66,7 +66,7 @@ public final class TestFormulas {
r = s.getRow(1);
c = r.getCell(1);
- assertEquals("Formula is as expected", "1+1", c.getCellFormula());
+ assertEquals("1+1", c.getCellFormula(), "Formula is as expected");
}
}
}
@@ -201,9 +201,10 @@ public final class TestFormulas {
for (int y = 1; y < 256 && y > 0; y=(short)(y+2)) {
HSSFCell c = r.getCell(y);
- assertNotNull("got a formula", c.getCellFormula());
+ assertNotNull(c.getCellFormula(), "got a formula");
- assertEquals("loop Formula is as expected " + x + "." + y + operator + y + "." + x + "!=" + c.getCellFormula(), ("" + x + "." + y + operator + y + "." + x), c.getCellFormula());
+ assertEquals(("" + x + "." + y + operator + y + "." + x), c.getCellFormula(),
+ "loop Formula is as expected " + x + "." + y + operator + y + "." + x + "!=" + c.getCellFormula());
}
}
}
@@ -281,7 +282,8 @@ public final class TestFormulas {
HSSFRow r = s.getRow(0);
HSSFCell c = r.getCell(1);
//get our minimum values
- assertEquals("minval Formula is as expected A2" + operator + "A3 != " + c.getCellFormula(), ("A2" + operator + "A3"), c.getCellFormula());
+ assertEquals(("A2" + operator + "A3"), c.getCellFormula(),
+ "minval Formula is as expected A2" + operator + "A3 != " + c.getCellFormula());
for (int x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
@@ -301,7 +303,8 @@ public final class TestFormulas {
String ref2=cr.formatAsString();
- assertEquals("loop Formula is as expected " + ref + operator + ref2 + "!=" + c.getCellFormula(), ("" + ref + operator + ref2), c.getCellFormula());
+ assertEquals(("" + ref + operator + ref2), c.getCellFormula(),
+ "loop Formula is as expected " + ref + operator + ref2 + "!=" + c.getCellFormula());
}
}
@@ -332,7 +335,7 @@ public final class TestFormulas {
//get our minimum values
r = s.getRow(0);
c = r.getCell(1);
- assertEquals("minval Formula is as expected", formula, c.getCellFormula());
+ assertEquals(formula, c.getCellFormula(), "minval Formula is as expected");
}
}
}
@@ -382,14 +385,16 @@ public final class TestFormulas {
//get our minimum values
HSSFRow r = s.getRow(0);
HSSFCell c = r.getCell(1);
- assertEquals("minval Formula is as expected 1" + operator + "1 != " + c.getCellFormula(), ("1" + operator + "1"), c.getCellFormula());
+ assertEquals(("1" + operator + "1"), c.getCellFormula(),
+ "minval Formula is as expected 1" + operator + "1 != " + c.getCellFormula());
for (int x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
r = s.getRow(x);
for (int y = 1; y < 256 && y > 0; y++) {
c = r.getCell(y);
- assertEquals("loop Formula is as expected " + x + operator + y + "!=" + c.getCellFormula(), ("" + x + operator + y), c.getCellFormula());
+ assertEquals(("" + x + operator + y), c.getCellFormula(),
+ "loop Formula is as expected " + x + operator + y + "!=" + c.getCellFormula());
}
}
@@ -397,7 +402,8 @@ public final class TestFormulas {
r = s.getRow(0);
c = r.getCell(0);
- assertEquals("maxval Formula is as expected", ("" + Short.MAX_VALUE + operator + Short.MAX_VALUE), c.getCellFormula());
+ assertEquals(("" + Short.MAX_VALUE + operator + Short.MAX_VALUE), c.getCellFormula(),
+ "maxval Formula is as expected");
}
/**
@@ -415,7 +421,8 @@ public final class TestFormulas {
r = s.getRow(0);
c = r.getCell(0);
- assertEquals("function =" + function + "(A2:A3)", function + "(A2:A3)", c.getCellFormula());
+ assertEquals(function + "(A2:A3)", c.getCellFormula(),
+ "function =" + function + "(A2:A3)");
}
}
}
@@ -436,7 +443,7 @@ public final class TestFormulas {
r = s.getRow(0);
c = r.getCell(0);
- assertEquals("function =" + function + "(A2,A3)", (function + "(A2,A3)"), c.getCellFormula());
+ assertEquals((function + "(A2,A3)"), c.getCellFormula(), "function =" + function + "(A2,A3)");
}
}
}
@@ -461,10 +468,10 @@ public final class TestFormulas {
r = s.getRow(0);
c = r.getCell(0);
- assertEquals("function =" + function + "(A2:A4,B2:B4)", (function + "(A2:A4,B2:B4)"), c.getCellFormula());
+ assertEquals((function + "(A2:A4,B2:B4)"), c.getCellFormula(), "function =" + function + "(A2:A4,B2:B4)");
c = r.getCell(1);
- assertEquals("function =" + function + "($A$2:$A4,B$2:B4)", (function + "($A$2:$A4,B$2:B4)"), c.getCellFormula());
+ assertEquals((function + "($A$2:$A4,B$2:B4)"), c.getCellFormula(), "function =" + function + "($A$2:$A4,B$2:B4)");
}
}
}
@@ -490,15 +497,15 @@ public final class TestFormulas {
s = wb2.getSheetAt(0);
r = s.getRow(0);
c = r.getCell(0);
- assertEquals("A3+A2", ("A3+A2"), c.getCellFormula());
+ assertEquals("A3+A2", c.getCellFormula());
c = r.getCell(1);
- assertEquals("$A3+$A2", ("$A3+$A2"), c.getCellFormula());
+ assertEquals("$A3+$A2", c.getCellFormula());
c = r.getCell(2);
- assertEquals("A$3+A$2", ("A$3+A$2"), c.getCellFormula());
+ assertEquals("A$3+A$2", c.getCellFormula());
c = r.getCell(3);
- assertEquals("$A$3+$A$2", ("$A$3+$A$2"), c.getCellFormula());
+ assertEquals("$A$3+$A$2", c.getCellFormula());
c = r.getCell(4);
- assertEquals("SUM($A$3,$A$2)", ("SUM($A$3,$A$2)"), c.getCellFormula());
+ assertEquals("SUM($A$3,$A$2)", c.getCellFormula());
}
}
}
@@ -526,9 +533,11 @@ public final class TestFormulas {
s = wb2.getSheet("B");
r = s.getRow(0);
c = r.getCell(0);
- assertEquals("expected: AVERAGE(A!A1:B1) got: " + c.getCellFormula(), ("AVERAGE(A!A1:B1)"), c.getCellFormula());
+ assertEquals("AVERAGE(A!A1:B1)", c.getCellFormula(),
+ "expected: AVERAGE(A!A1:B1) got: " + c.getCellFormula());
c = r.getCell(1);
- assertEquals("expected: A!A1+A!B1 got: " + c.getCellFormula(), ("A!A1+A!B1"), c.getCellFormula());
+ assertEquals("A!A1+A!B1", c.getCellFormula(),
+ "expected: A!A1+A!B1 got: " + c.getCellFormula());
}
}
}
@@ -568,7 +577,7 @@ public final class TestFormulas {
try (FileOutputStream out = new FileOutputStream(file)) {
wb.write(out);
}
- assertTrue("file exists", file.exists());
+ assertTrue(file.exists());
}
}
@@ -607,7 +616,7 @@ public final class TestFormulas {
s = wb2.getSheetAt(0);
r = s.getRow(0);
c = r.getCell(1);
- assertEquals("Formula in cell 1 ", "IF(A1<A2,B1,B2)", c.getCellFormula());
+ assertEquals("IF(A1<A2,B1,B2)", c.getCellFormula(), "Formula in cell 1 ");
}
}
}
@@ -661,7 +670,8 @@ public final class TestFormulas {
r = s.getRow(0);
c = r.getCell(4);
- assertEquals("expected: IF(A1=D1,\"A1\",\"B1\") got " + c.getCellFormula(), ("IF(A1=D1,\"A1\",\"B1\")"), c.getCellFormula());
+ assertEquals("IF(A1=D1,\"A1\",\"B1\")", c.getCellFormula(),
+ "expected: IF(A1=D1,\"A1\",\"B1\") got " + c.getCellFormula());
}
}
@@ -669,7 +679,8 @@ public final class TestFormulas {
HSSFSheet s = wb1.getSheetAt(0);
HSSFRow r = s.getRow(3);
HSSFCell c = r.getCell(0);
- assertEquals("expected: IF(A3=A1,\"A1\",\"A2\") got " + c.getCellFormula(), ("IF(A3=A1,\"A1\",\"A2\")"), c.getCellFormula());
+ assertEquals("IF(A3=A1,\"A1\",\"A2\")", c.getCellFormula(),
+ "expected: IF(A3=A1,\"A1\",\"A2\") got " + c.getCellFormula());
//c = r.getCell((short)1);
//assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), ("A!A1+A!B1").equals(c.getCellFormula()));
}
@@ -805,7 +816,7 @@ public final class TestFormulas {
public void testStringFormulaRead() throws IOException {
try (HSSFWorkbook w = openSample("StringFormulas.xls")) {
HSSFCell c = w.getSheetAt(0).getRow(0).getCell(0);
- assertEquals("String Cell value", "XYZ", c.getRichStringCellValue().getString());
+ assertEquals("XYZ", c.getRichStringCellValue().getString(), "String Cell value");
}
}
@@ -834,7 +845,7 @@ public final class TestFormulas {
public void test27272_1() throws IOException {
try (HSSFWorkbook wb = openSample("27272_1.xls")) {
wb.getSheetAt(0);
- assertEquals("Reference for named range ", "Compliance!#REF!", wb.getNameAt(0).getRefersToFormula());
+ assertEquals("Compliance!#REF!", wb.getNameAt(0).getRefersToFormula(), "Reference for named range");
writeOutAndReadBack(wb).close();
}
}
@@ -843,7 +854,7 @@ public final class TestFormulas {
@Test
public void test27272_2() throws IOException {
try (HSSFWorkbook wb = openSample("27272_2.xls")) {
- assertEquals("Reference for named range ", "LOAD.POD_HISTORIES!#REF!", wb.getNameAt(0).getRefersToFormula());
+ assertEquals("LOAD.POD_HISTORIES!#REF!", wb.getNameAt(0).getRefersToFormula(), "Reference for named range");
writeOutAndReadBack(wb).close();
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
index e3372c629b..1873641e18 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
@@ -17,11 +17,11 @@
package org.apache.poi.hssf.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.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 java.io.IOException;
import java.util.ArrayList;
@@ -35,7 +35,6 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.InternalSheet;
import org.apache.poi.hssf.record.DBCellRecord;
import org.apache.poi.hssf.record.FormulaRecord;
-import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.StringRecord;
import org.apache.poi.ss.usermodel.BaseTestCell;
import org.apache.poi.ss.usermodel.Cell;
@@ -46,7 +45,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.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests various functionality having to do with {@link HSSFCell}. For instance support for
@@ -72,18 +71,18 @@ public final class TestHSSFCell extends BaseTestCell {
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("1900DateWindowing.xls")) {
HSSFSheet sheet = wb.getSheetAt(0);
- assertEquals("Date from file using 1900 Date Windowing",
- date.getTime(),
- sheet.getRow(0).getCell(0).getDateCellValue().getTime());
+ assertEquals(date.getTime(),
+ sheet.getRow(0).getCell(0).getDateCellValue().getTime(),
+ "Date from file using 1900 Date Windowing");
}
// now check a file with 1904 Date Windowing
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("1904DateWindowing.xls")) {
HSSFSheet sheet = wb.getSheetAt(0);
- assertEquals("Date from file using 1904 Date Windowing",
- date.getTime(),
- sheet.getRow(0).getCell(0).getDateCellValue().getTime());
+ assertEquals(date.getTime(),
+ sheet.getRow(0).getCell(0).getDateCellValue().getTime(),
+ "Date from file using 1904 Date Windowing");
}
}
@@ -106,9 +105,9 @@ public final class TestHSSFCell extends BaseTestCell {
setCell(wb1, 0, 1, date);
try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
- assertEquals("Date from file using 1900 Date Windowing",
- date.getTime(),
- readCell(wb2, 0, 1).getTime());
+ assertEquals(date.getTime(),
+ readCell(wb2, 0, 1).getTime(),
+ "Date from file using 1900 Date Windowing");
}
}
@@ -116,9 +115,9 @@ public final class TestHSSFCell extends BaseTestCell {
try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("1904DateWindowing.xls")) {
setCell(wb1, 0, 1, date);
try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
- assertEquals("Date from file using 1900 Date Windowing",
- date.getTime(),
- readCell(wb2, 0, 1).getTime());
+ assertEquals(date.getTime(),
+ readCell(wb2, 0, 1).getTime(),
+ "Date from file using 1900 Date Windowing");
}
}
}
@@ -152,28 +151,22 @@ public final class TestHSSFCell extends BaseTestCell {
//check initial position
HSSFSheet umSheet = wb1.getSheetAt(0);
InternalSheet s = umSheet.getSheet();
- assertEquals("Initial active cell should be in col 0",
- (short) 0, s.getActiveCellCol());
- assertEquals("Initial active cell should be on row 1",
- 1, s.getActiveCellRow());
+ assertEquals((short) 0, s.getActiveCellCol(), "Initial active cell should be in col 0");
+ assertEquals(1, s.getActiveCellRow(), "Initial active cell should be on row 1");
//modify position through HSSFCell
HSSFCell cell = umSheet.createRow(3).createCell(2);
cell.setAsActiveCell();
- assertEquals("After modify, active cell should be in col 2",
- (short) 2, s.getActiveCellCol());
- assertEquals("After modify, active cell should be on row 3",
- 3, s.getActiveCellRow());
+ assertEquals((short) 2, s.getActiveCellCol(), "After modify, active cell should be in col 2");
+ assertEquals(3, s.getActiveCellRow(), "After modify, active cell should be on row 3");
//write book to temp file; read and verify that position is serialized
try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
umSheet = wb2.getSheetAt(0);
s = umSheet.getSheet();
- assertEquals("After serialize, active cell should be in col 2",
- (short) 2, s.getActiveCellCol());
- assertEquals("After serialize, active cell should be on row 3",
- 3, s.getActiveCellRow());
+ assertEquals((short) 2, s.getActiveCellCol(), "After serialize, active cell should be in col 2");
+ assertEquals(3, s.getActiveCellRow(), "After serialize, active cell should be on row 3");
}
}
}
@@ -278,36 +271,16 @@ public final class TestHSSFCell extends BaseTestCell {
styA.verifyBelongsToWorkbook(wbA);
styB.verifyBelongsToWorkbook(wbB);
- try {
- styA.verifyBelongsToWorkbook(wbB);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
- try {
- styB.verifyBelongsToWorkbook(wbA);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
+ assertThrows(IllegalArgumentException.class, () -> styA.verifyBelongsToWorkbook(wbB));
+ assertThrows(IllegalArgumentException.class, () -> styB.verifyBelongsToWorkbook(wbA));
Cell cellA = wbA.createSheet().createRow(0).createCell(0);
Cell cellB = wbB.createSheet().createRow(0).createCell(0);
cellA.setCellStyle(styA);
cellB.setCellStyle(styB);
- try {
- cellA.setCellStyle(styB);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
- try {
- cellB.setCellStyle(styA);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
+ assertThrows(IllegalArgumentException.class, () -> cellA.setCellStyle(styB));
+ assertThrows(IllegalArgumentException.class, () -> cellB.setCellStyle(styA));
}
}
@@ -329,7 +302,7 @@ public final class TestHSSFCell extends BaseTestCell {
final List<org.apache.poi.hssf.record.Record> recs = new ArrayList<>();
sheet.getSheet().visitContainedRecords(recs::add, 0);
- assertFalse("Identified bug - leftover StringRecord", recs.size() == 28 && recs.get(23) instanceof StringRecord);
+ assertFalse(recs.size() == 28 && recs.get(23) instanceof StringRecord, "Identified bug - leftover StringRecord");
confirmStringRecord(sheet, false);
// string to error code
@@ -390,12 +363,7 @@ public final class TestHSSFCell extends BaseTestCell {
// cover some deprecated methods and other smaller stuff...
assertEquals(wb.getWorkbook(), cell.getBoundWorkbook());
- try {
- cell.getCachedFormulaResultType();
- fail("Should catch exception");
- } catch (IllegalStateException e) {
- // expected here
- }
+ assertThrows(IllegalStateException.class, cell::getCachedFormulaResultType);
cell.removeCellComment();
cell.removeCellComment();
@@ -410,7 +378,7 @@ public final class TestHSSFCell extends BaseTestCell {
Cell cell = row.createCell(0);
cell.setBlank();
- assertNull(null, cell.getDateCellValue());
+ assertNull(cell.getDateCellValue());
assertFalse(cell.getBooleanCellValue());
assertEquals("", cell.toString());
@@ -440,11 +408,11 @@ public final class TestHSSFCell extends BaseTestCell {
}
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void getErrorCellValue_throwsISE_onABlankCell() throws IOException {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
Cell cell = wb.createSheet().createRow(0).createCell(0);
- cell.getErrorCellValue();
+ assertThrows(IllegalStateException.class, cell::getErrorCellValue);
}
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java
index 987741f4ca..494072402c 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.IOException;
@@ -29,7 +29,7 @@ import org.apache.poi.hssf.record.chart.SeriesRecord;
import org.apache.poi.hssf.usermodel.HSSFChart.HSSFSeries;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressBase;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link HSSFChart}
@@ -139,26 +139,26 @@ public final class TestHSSFChart {
assertEquals("Base Numbers", charts[0].getSeries()[1].getSeriesTitle());
assertEquals("Sheet 3 Chart with Title", charts[0].getChartTitle());
}
-
+
@Test
public void testExistingSheet3() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
-
+
HSSFSheet sheet = wb.getSheetAt( 2 ) ;
HSSFChart[] charts = HSSFChart.getSheetCharts( sheet ) ;
assertEquals(1, charts.length);
-
+
for ( HSSFChart chart : charts ) {
for ( HSSFSeries series : chart.getSeries() ) {
chart.removeSeries( series ) ;
}
}
-
+
// Save and re-check
wb = HSSFITestDataProvider.instance.writeOutAndReadBack(wb);
sheet = wb.getSheetAt( 2 ) ;
assertEquals(1, HSSFChart.getSheetCharts(sheet).length);
-
+
HSSFChart c = HSSFChart.getSheetCharts(sheet)[0];
assertEquals(0, c.getSeries().length);
}
@@ -168,11 +168,11 @@ public final class TestHSSFChart {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
HSSFSheet sheet = wb.getSheetAt( 1 ) ;
HSSFChart[] charts = HSSFChart.getSheetCharts( sheet ) ;
-
+
assertEquals(1, charts.length);
for ( HSSFChart chart : charts ) {
HSSFSeries series ;
-
+
// Starts with one
assertEquals(1, chart.getSeries().length);
@@ -185,12 +185,12 @@ public final class TestHSSFChart {
series.setCategoryLabelsCellRange( new CellRangeAddress( 6, 7, 0, 0 ) ) ;
series.setValuesCellRange( new CellRangeAddress( 6, 7, 1, 1 ) ) ;
}
-
+
// Save and re-check
wb = HSSFITestDataProvider.instance.writeOutAndReadBack(wb);
sheet = wb.getSheetAt( 1 ) ;
assertEquals(1, HSSFChart.getSheetCharts(sheet).length);
-
+
HSSFChart c = HSSFChart.getSheetCharts(sheet)[0];
assertEquals(3, c.getSeries().length);
}
@@ -200,7 +200,7 @@ public final class TestHSSFChart {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
HSSFSheet sheet = wb.getSheetAt( 0 ) ;
HSSFChart[] charts = HSSFChart.getSheetCharts( sheet ) ;
-
+
for ( HSSFChart chart : charts ) {
//System.out.println( chart.getType() ) ;
HSSFSeries[] seriesArray = chart.getSeries() ;
@@ -237,7 +237,7 @@ public final class TestHSSFChart {
HSSFChart chart = charts[ 2 ] ;
chart.removeSeries( chart.getSeries()[ 0 ] ) ;
}
-
+
/**
* Bug 26862: HSSFWorkbook.cloneSheet copies charts
*/
@@ -248,10 +248,10 @@ public final class TestHSSFChart {
HSSFChart[] srcCharts = HSSFChart.getSheetCharts(srcSheet);
assertEquals(1, srcCharts.length);
HSSFChart srcChart = srcCharts[0];
-
+
// Clone the sheet
HSSFSheet clonedSheet = wb.cloneSheet(0);
-
+
// Verify the chart was copied
HSSFChart[] clonedCharts = HSSFChart.getSheetCharts(clonedSheet);
assertEquals(1, clonedCharts.length);
@@ -263,11 +263,11 @@ public final class TestHSSFChart {
assertEquals(srcChart.getChartHeight(), clonedChart.getChartHeight());
assertEquals(srcChart.getChartX(), clonedChart.getChartX());
assertEquals(srcChart.getChartY(), clonedChart.getChartY());
-
+
// Check if chart was shallow copied or deep copied
clonedChart.setChartWidth(clonedChart.getChartWidth()+10);
assertEquals(srcChart.getChartWidth()+10, clonedChart.getChartWidth());
-
+
wb.close();
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java
index 30c6fce97a..2d19ce1aaf 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java
@@ -17,13 +17,14 @@
package org.apache.poi.hssf.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.IOException;
import org.apache.poi.ddf.EscherClientAnchorRecord;
import org.apache.poi.hssf.model.ConvertAnchor;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Various tests for HSSFClientAnchor.
@@ -128,9 +129,10 @@ public final class TestHSSFClientAnchor {
assertEquals(65535, anchor.getRow2());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testCannotHaveRowGreaterThan65535() {
- new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 65536, (short) 0, 65536);
+ assertThrows(IllegalArgumentException.class, () ->
+ new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 65536, (short) 0, 65536));
}
/**
@@ -146,13 +148,15 @@ public final class TestHSSFClientAnchor {
assertEquals(65535, anchor.getRow2());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testCannotSetRow1GreaterThan65535() {
- new HSSFClientAnchor().setRow1(65536);
+ assertThrows(IllegalArgumentException.class, () ->
+ new HSSFClientAnchor().setRow1(65536));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testCannotSetRow2GreaterThan65535() {
- new HSSFClientAnchor().setRow2(65536);
+ assertThrows(IllegalArgumentException.class, () ->
+ new HSSFClientAnchor().setRow2(65536));
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
index 62ecf00a4f..ef4a2bc538 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
@@ -17,12 +17,12 @@
package org.apache.poi.hssf.usermodel;
import static org.apache.poi.poifs.storage.RawDataUtil.decompress;
-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.assertTrue;
+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.assertTrue;
import java.io.IOException;
@@ -44,7 +44,7 @@ import org.apache.poi.ss.usermodel.RichTextString;
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 TestHSSFCellComment.
@@ -97,10 +97,10 @@ public final class TestHSSFComment extends BaseTestCellComment {
cell = sheet.getRow(5).getCell(2);
comment = cell.getCellComment();
assertEquals("c6", comment.getString().getString());
-
+
wb.close();
}
-
+
@Test
public void testBug56380InsertComments() throws Exception {
HSSFWorkbook workbook = new HSSFWorkbook();
@@ -108,7 +108,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
Drawing<?> drawing = sheet.createDrawingPatriarch();
int noOfRows = 1025;
String comment = "c";
-
+
for(int i = 0; i < noOfRows; i++) {
Row row = sheet.createRow(i);
Cell cell = row.createCell(0);
@@ -125,14 +125,14 @@ public final class TestHSSFComment extends BaseTestCellComment {
} finally {
fs.close();
}*/
-
+
// save and recreate the workbook from the saved file
HSSFWorkbook workbookBack = HSSFTestDataSamples.writeOutAndReadBack(workbook);
sheet = workbookBack.getSheetAt(0);
-
+
// assert that the comments are created properly after reading back in
checkComments(sheet, noOfRows, comment);
-
+
workbook.close();
workbookBack.close();
}
@@ -173,7 +173,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
for(int i = 0; i < noOfRows; i++) {
assertNotNull(sheet.getRow(i));
assertNotNull(sheet.getRow(i).getCell(0));
- assertNotNull("Did not get a Cell Comment for row " + i, sheet.getRow(i).getCell(0).getCellComment());
+ assertNotNull(sheet.getRow(i).getCell(0).getCellComment(), "Did not get a Cell Comment for row " + i);
assertNotNull(sheet.getRow(i).getCell(0).getCellComment().getString());
assertEquals(comment + i, sheet.getRow(i).getCell(0).getCellComment().getString().getString());
}
@@ -181,27 +181,27 @@ public final class TestHSSFComment extends BaseTestCellComment {
private Comment insertComment(Drawing<?> drawing, Cell cell, String message) {
CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
-
+
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex() + 1);
anchor.setRow1(cell.getRowIndex());
anchor.setRow2(cell.getRowIndex() + 1);
- anchor.setDx1(100);
+ anchor.setDx1(100);
anchor.setDx2(100);
anchor.setDy1(100);
anchor.setDy2(100);
-
+
Comment comment = drawing.createCellComment(anchor);
-
+
RichTextString str = factory.createRichTextString(message);
comment.setString(str);
comment.setAuthor("fanfy");
cell.setCellComment(comment);
-
+
return comment;
}
-
+
@Test
public void resultEqualsToNonExistingAbstractShape() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
@@ -308,7 +308,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
assertEquals(((HSSFComment) patriarch.getChildren().get(0)).getString().getString(), "comment1");
assertEquals(((HSSFComment) patriarch.getChildren().get(1)).getString().getString(), "comment2");
assertEquals(((HSSFComment) patriarch.getChildren().get(2)).getString().getString(), "comment3");
-
+
wb.close();
wbBack.close();
wbBack2.close();
@@ -364,7 +364,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
assertEquals(comment.getColumn(), 32);
assertEquals(comment.getRow(), 42);
assertTrue(comment.isVisible());
-
+
wb.close();
wbBack.close();
wbBack2.close();
@@ -403,7 +403,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
assertNotNull(sh.findCellComment(5, 4));
assertNull(sh.findCellComment(5, 5));
-
+
wb.close();
wbBack.close();
}
@@ -424,7 +424,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
assertNotNull(shape);
assertEquals(comment.getOptRecord().getEscherProperties().size(), 10);
-
+
wb.close();
}
@@ -446,7 +446,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
assertEquals(2024, spRecord.getShapeId(), 2024);
assertEquals(2024, comment.getShapeId(), 2024);
assertEquals(2024, comment.getNoteRecord().getShapeId());
-
+
wb.close();
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
index 63ba22c935..0512d5a080 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
@@ -18,14 +18,19 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.ss.usermodel.*;
-import org.junit.Test;
+import org.apache.poi.ss.usermodel.BaseTestConditionalFormatting;
+import org.apache.poi.ss.usermodel.Color;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.junit.jupiter.api.Test;
/**
* HSSF-specific Conditional Formatting tests
@@ -35,8 +40,8 @@ public final class TestHSSFConditionalFormatting extends BaseTestConditionalForm
super(HSSFITestDataProvider.instance);
}
@Override
- protected void assertColour(String hexExpected, Color actual) {
- assertNotNull("Colour must be given", actual);
+ protected void assertColor(String hexExpected, Color actual) {
+ assertNotNull(actual, "Colour must be given");
if (actual instanceof HSSFColor) {
HSSFColor colour = (HSSFColor)actual;
assertEquals(hexExpected, colour.getHexString());
@@ -54,7 +59,7 @@ public final class TestHSSFConditionalFormatting extends BaseTestConditionalForm
public void testRead() throws IOException {
testRead("WithConditionalFormatting.xls");
}
-
+
@Test
public void testReadOffice2007() throws IOException {
testReadOffice2007("NewStyleConditionalFormattings.xls");
@@ -73,10 +78,10 @@ public final class TestHSSFConditionalFormatting extends BaseTestConditionalForm
}
wb.removeSheetAt(1);*/
-
+
// initially it is good
writeTemp53691(wb, "agood");
-
+
// clone sheet corrupts it
Sheet sheet = wb.cloneSheet(0);
writeTemp53691(wb, "bbad");
@@ -84,28 +89,28 @@ public final class TestHSSFConditionalFormatting extends BaseTestConditionalForm
// removing the sheet makes it good again
wb.removeSheetAt(wb.getSheetIndex(sheet));
writeTemp53691(wb, "cgood");
-
+
// cloning again and removing the conditional formatting makes it good again
sheet = wb.cloneSheet(0);
- removeConditionalFormatting(sheet);
+ removeConditionalFormatting(sheet);
writeTemp53691(wb, "dgood");
-
+
// cloning the conditional formatting manually makes it bad again
cf = sheet.getSheetConditionalFormatting();
SheetConditionalFormatting scf = wb.getSheetAt(0).getSheetConditionalFormatting();
for (int j = 0; j < scf.getNumConditionalFormattings(); j++) {
cf.addConditionalFormatting(scf.getConditionalFormattingAt(j));
- }
+ }
writeTemp53691(wb, "ebad");
// remove all conditional formatting for comparing BIFF output
- removeConditionalFormatting(sheet);
- removeConditionalFormatting(wb.getSheetAt(0));
+ removeConditionalFormatting(sheet);
+ removeConditionalFormatting(wb.getSheetAt(0));
writeTemp53691(wb, "fgood");
-
+
wb.close();
}
-
+
private void removeConditionalFormatting(Sheet sheet) {
SheetConditionalFormatting cf = sheet.getSheetConditionalFormatting();
for (int j = 0; j < cf.getNumConditionalFormattings(); j++) {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
index dd334b0183..2747b19d52 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.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.io.IOException;
@@ -32,7 +32,7 @@ import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link HSSFDataFormat}
@@ -62,12 +62,12 @@ public final class TestHSSFDataFormat extends BaseTestDataFormat {
short customFmtIdx = dataFormat.getFormat("\u00a3##.00[Yellow]");
assertTrue(customFmtIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX );
assertEquals("\u00a3##.00[Yellow]", dataFormat.getFormat(customFmtIdx));
-
+
wb.close();
}
/**
- * [Bug 58532] Handle formats that go numnum, numK, numM etc
+ * [Bug 58532] Handle formats that go numnum, numK, numM etc
*/
@Override
@Test
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
index 7ee4525989..035eeaa78a 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
@@ -35,9 +35,9 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil;
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;
/**
* Unit tests for HSSFDataFormatter.java
@@ -45,14 +45,14 @@ import org.junit.Test;
public final class TestHSSFDataFormatter {
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);
@@ -109,10 +109,10 @@ public final class TestHSSFDataFormatter {
String[] goodTimePatterns = {
"HH:MM",
"HH:MM:SS",
- "HH:MM;HH:MM;HH:MM",
+ "HH:MM;HH:MM;HH:MM",
// This is fun - blue if positive time,
// red if negative time or green for zero!
- "[BLUE]HH:MM;[RED]HH:MM;[GREEN]HH:MM",
+ "[BLUE]HH:MM;[RED]HH:MM;[GREEN]HH:MM",
"yyyy-mm-dd hh:mm",
"yyyy-mm-dd hh:mm:ss",
};
@@ -241,7 +241,7 @@ public final class TestHSSFDataFormatter {
// should not be equal to "555.555"
assertTrue( DateUtil.isCellDateFormatted(cell) );
- assertFalse("555.555".equals(fmtval));
+ assertNotEquals(fmtval, "555.555");
String fmt = cell.getCellStyle().getDataFormatString();
@@ -257,7 +257,7 @@ public final class TestHSSFDataFormatter {
jul = jul.substring(0,1);
}
// check we found july properly
- assertTrue("Format came out incorrect - " + fmt, fmtval.contains(jul));
+ assertTrue(fmtval.contains(jul), "Format came out incorrect - " + fmt);
}
row = wb.getSheetAt(0).getRow(1);
@@ -271,11 +271,11 @@ public final class TestHSSFDataFormatter {
// should not be equal to "555.47431"
assertTrue( DateUtil.isCellDateFormatted(cell) );
- assertFalse("555.47431".equals(fmtval));
+ assertNotEquals(fmtval, "555.47431");
// check we found the time properly
- assertTrue("Format came out incorrect - " + fmt + " - found " + fmtval +
- ", but expected to find '11:23'", fmtval.contains("11:23"));
+ assertTrue(fmtval.contains("11:23"),
+ "Format came out incorrect - " + fmt + " - found " + fmtval + ", but expected to find '11:23'");
}
// test number formats
@@ -367,10 +367,10 @@ public final class TestHSSFDataFormatter {
Cell cell = it.next();
cell.setCellValue(cell.getNumericCellValue() * Math.random() / 1000000 - 1000);
log(formatter.formatCellValue(cell));
-
- String formatted = formatter.formatCellValue(cell);
- assertTrue("Doesn't start with Balance: " + formatted, formatted.startsWith("Balance "));
- assertTrue("Doesn't end with USD: " + formatted, formatted.endsWith(" USD"));
+
+ String formatted = formatter.formatCellValue(cell);
+ assertTrue(formatted.startsWith("Balance "), "Doesn't start with Balance: " + formatted);
+ assertTrue(formatted.endsWith(" USD"), "Doesn't end with USD: " + formatted);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java
index 066f4bdf66..cbb6bfcdd8 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.usermodel;
-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 java.io.IOException;
import java.util.TimeZone;
@@ -29,9 +29,9 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.ss.usermodel.DateUtil;
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;
/**
* Class TestHSSFDateUtil
@@ -39,14 +39,14 @@ import org.junit.Test;
public class TestHSSFDateUtil {
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);
}
@@ -54,7 +54,7 @@ public class TestHSSFDateUtil {
/**
* Test that against a real, test file, we still do everything
* correctly
- * @throws IOException
+ * @throws IOException
*/
@Test
public void onARealFile() throws IOException {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java
index c53e01b4aa..538d266cf4 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java
@@ -17,15 +17,15 @@
package org.apache.poi.hssf.usermodel;
+import java.util.AbstractMap;
+import java.util.Map;
+
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.formula.EvaluationSheet;
import org.apache.poi.ss.usermodel.BaseTestXEvaluationSheet;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Sheet;
-import org.junit.Test;
-
-import java.util.AbstractMap;
-import java.util.Map;
+import org.junit.jupiter.api.Test;
public class TestHSSFEvaluationSheet extends BaseTestXEvaluationSheet {
@Override
@@ -33,7 +33,7 @@ public class TestHSSFEvaluationSheet extends BaseTestXEvaluationSheet {
HSSFSheet sheet = new HSSFWorkbook().createSheet();
return new AbstractMap.SimpleEntry<>(sheet, new HSSFEvaluationSheet(sheet));
}
-
+
@Test
public void testMissingExternalName() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("external_name.xls");
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFont.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFont.java
index 81f28d81fe..f05ebb5203 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFont.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFont.java
@@ -22,7 +22,7 @@ import java.io.IOException;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.ss.usermodel.BaseTestFont;
import org.apache.poi.ss.usermodel.Font;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests various functionality having to do with {@link org.apache.poi.ss.usermodel.Name}.
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java
index daae2cc6e4..c421e2cee5 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java
@@ -17,8 +17,10 @@
package org.apache.poi.hssf.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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
@@ -35,7 +37,7 @@ import org.apache.poi.ss.usermodel.BaseTestFormulaEvaluator;
import org.apache.poi.ss.usermodel.Cell;
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 TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
@@ -43,258 +45,249 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
super(HSSFITestDataProvider.instance);
}
- /**
- * Test that the HSSFFormulaEvaluator can evaluate simple named ranges
- * (single cells and rectangular areas)
- */
+ /**
+ * Test that the HSSFFormulaEvaluator can evaluate simple named ranges
+ * (single cells and rectangular areas)
+ */
@Test
- public void testEvaluateSimple() throws IOException {
- HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testNames.xls");
- HSSFSheet sheet = wb.getSheetAt(0);
- HSSFCell cell = sheet.getRow(8).getCell(0);
- HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
- CellValue cv = fe.evaluate(cell);
- assertEquals(CellType.NUMERIC, cv.getCellType());
- assertEquals(3.72, cv.getNumberValue(), 0.0);
- wb.close();
- }
-
- /**
- * When evaluating defined names, POI has to decide whether it is capable. Currently
- * (May2009) POI only supports simple cell and area refs.<br>
- * The sample spreadsheet (bugzilla attachment 23508) had a name flagged as 'complex'
- * which contained a simple area ref. It is not clear what the 'complex' flag is used
- * for but POI should look elsewhere to decide whether it can evaluate the name.
- */
+ public void testEvaluateSimple() throws IOException {
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testNames.xls");
+ HSSFSheet sheet = wb.getSheetAt(0);
+ HSSFCell cell = sheet.getRow(8).getCell(0);
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ CellValue cv = fe.evaluate(cell);
+ assertEquals(CellType.NUMERIC, cv.getCellType());
+ assertEquals(3.72, cv.getNumberValue(), 0.0);
+ wb.close();
+ }
+
+ /**
+ * When evaluating defined names, POI has to decide whether it is capable. Currently
+ * (May2009) POI only supports simple cell and area refs.<br>
+ * The sample spreadsheet (bugzilla attachment 23508) had a name flagged as 'complex'
+ * which contained a simple area ref. It is not clear what the 'complex' flag is used
+ * for but POI should look elsewhere to decide whether it can evaluate the name.
+ */
+ @Test
+ public void testDefinedNameWithComplexFlag_bug47048() throws IOException {
+ // Mock up a spreadsheet to match the critical details of the sample
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet = wb.createSheet("Input");
+ HSSFName definedName = wb.createName();
+ definedName.setNameName("Is_Multicar_Vehicle");
+ definedName.setRefersToFormula("Input!$B$17:$G$17");
+
+ // Set up some data and the formula
+ HSSFRow row17 = sheet.createRow(16);
+ row17.createCell(0).setCellValue(25.0);
+ row17.createCell(1).setCellValue(1.33);
+ row17.createCell(2).setCellValue(4.0);
+
+ HSSFRow row = sheet.createRow(0);
+ HSSFCell cellA1 = row.createCell(0);
+ cellA1.setCellFormula("SUM(Is_Multicar_Vehicle)");
+
+ // Set the complex flag - POI doesn't usually manipulate this flag
+ NameRecord nameRec = TestHSSFName.getNameRecord(definedName);
+ nameRec.setOptionFlag((short) 0x10); // 0x10 -> complex
+
+ HSSFFormulaEvaluator hsf = new HSSFFormulaEvaluator(wb);
+ CellValue value;
+ try {
+ value = hsf.evaluate(cellA1);
+
+ assertEquals(CellType.NUMERIC, value.getCellType());
+ assertEquals(5.33, value.getNumberValue(), 0.0);
+
+ } catch (RuntimeException e) {
+ if (e.getMessage().equals("Don't know how to evaluate name 'Is_Multicar_Vehicle'")) {
+ fail("Identified bug 47048a");
+ }
+ throw e;
+ } finally {
+ wb.close();
+ }
+ }
+
+ private static final class EvalCountListener extends EvaluationListener {
+ private int _evalCount;
+
+ public EvalCountListener() {
+ _evalCount = 0;
+ }
+
+ @Override
+ public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry) {
+ _evalCount++;
+ }
+
+ public int getEvalCount() {
+ return _evalCount;
+ }
+ }
+
+ /**
+ * The HSSFFormula evaluator performance benefits greatly from caching of intermediate cell values
+ */
@Test
- public void testDefinedNameWithComplexFlag_bug47048() throws IOException {
- // Mock up a spreadsheet to match the critical details of the sample
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet("Input");
- HSSFName definedName = wb.createName();
- definedName.setNameName("Is_Multicar_Vehicle");
- definedName.setRefersToFormula("Input!$B$17:$G$17");
-
- // Set up some data and the formula
- HSSFRow row17 = sheet.createRow(16);
- row17.createCell(0).setCellValue(25.0);
- row17.createCell(1).setCellValue(1.33);
- row17.createCell(2).setCellValue(4.0);
-
- HSSFRow row = sheet.createRow(0);
- HSSFCell cellA1 = row.createCell(0);
- cellA1.setCellFormula("SUM(Is_Multicar_Vehicle)");
-
- // Set the complex flag - POI doesn't usually manipulate this flag
- NameRecord nameRec = TestHSSFName.getNameRecord(definedName);
- nameRec.setOptionFlag((short)0x10); // 0x10 -> complex
-
- HSSFFormulaEvaluator hsf = new HSSFFormulaEvaluator(wb);
- CellValue value;
- try {
- value = hsf.evaluate(cellA1);
-
- assertEquals(CellType.NUMERIC, value.getCellType());
- assertEquals(5.33, value.getNumberValue(), 0.0);
-
- } catch (RuntimeException e) {
- if (e.getMessage().equals("Don't know how to evaluate name 'Is_Multicar_Vehicle'")) {
- fail("Identified bug 47048a");
+ public void testShortCircuitIfEvaluation() throws IOException {
+ // Set up a simple IF() formula that has measurable evaluation cost for its operands.
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ HSSFSheet sheet = wb.createSheet("Sheet1");
+ HSSFRow row = sheet.createRow(0);
+ HSSFCell cellA1 = row.createCell(0);
+ cellA1.setCellFormula("if(B1,C1,D1+E1+F1)");
+ // populate cells B1..F1 with simple formulas instead of plain values so we can use
+ // EvaluationListener to check which parts of the first formula get evaluated
+ for (int i = 1; i < 6; i++) {
+ // formulas are just literal constants "1".."5"
+ row.createCell(i).setCellFormula(String.valueOf(i));
+ }
+
+ EvalCountListener evalListener = new EvalCountListener();
+ WorkbookEvaluator evaluator = WorkbookEvaluatorTestHelper.createEvaluator(wb, evalListener);
+ ValueEval ve = evaluator.evaluate(HSSFEvaluationTestHelper.wrapCell(cellA1));
+ int evalCount = evalListener.getEvalCount();
+ // Without short-circuit-if evaluation, evaluating cell 'A1' takes 3 extra evaluations (for D1,E1,F1)
+ assertNotEquals(6, evalCount, "Identifed bug 48195 - Formula evaluator should short-circuit IF() calculations.");
+ assertEquals(3, evalCount);
+ assertEquals(2.0, ((NumberEval) ve).getNumberValue(), 0D);
+ }
+ }
+
+ /**
+ * Ensures that we can handle NameXPtgs in the formulas
+ * we parse.
+ */
+ @Test
+ public void testXRefs() throws IOException {
+ try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("XRefCalc.xls");
+ HSSFWorkbook wb2 = HSSFTestDataSamples.openSampleWorkbook("XRefCalcData.xls")) {
+ Cell cell;
+
+ // VLookup on a name in another file
+ cell = wb1.getSheetAt(0).getRow(1).getCell(2);
+ assertEquals(CellType.FORMULA, cell.getCellType());
+ assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
+ assertEquals(12.30, cell.getNumericCellValue(), 0.0001);
+ // WARNING - this is wrong!
+ // The file name should be showing, but bug #45970 is fixed
+ // we seem to loose it
+ assertEquals("VLOOKUP(PART,COSTS,2,FALSE)", cell.getCellFormula());
+
+
+ // Simple reference to a name in another file
+ cell = wb1.getSheetAt(0).getRow(1).getCell(4);
+ assertEquals(CellType.FORMULA, cell.getCellType());
+ assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
+ assertEquals(36.90, cell.getNumericCellValue(), 0.0001);
+ // TODO Correct this!
+ // The file name should be shown too, see bug #56742
+ assertEquals("Cost*Markup_Cost", cell.getCellFormula());
+
+
+ // Evaluate the cells
+ HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb1);
+ HSSFFormulaEvaluator.setupEnvironment(
+ new String[]{"XRefCalc.xls", "XRefCalcData.xls"},
+ new HSSFFormulaEvaluator[]{
+ eval,
+ new HSSFFormulaEvaluator(wb2)
+ }
+ );
+ eval.evaluateFormulaCell(
+ wb1.getSheetAt(0).getRow(1).getCell(2)
+ );
+ eval.evaluateFormulaCell(
+ wb1.getSheetAt(0).getRow(1).getCell(4)
+ );
+
+
+ // Re-check VLOOKUP one
+ cell = wb1.getSheetAt(0).getRow(1).getCell(2);
+ assertEquals(CellType.FORMULA, cell.getCellType());
+ assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
+ assertEquals(12.30, cell.getNumericCellValue(), 0.0001);
+
+ // Re-check ref one
+ cell = wb1.getSheetAt(0).getRow(1).getCell(4);
+ assertEquals(CellType.FORMULA, cell.getCellType());
+ assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
+ assertEquals(36.90, cell.getNumericCellValue(), 0.0001);
+
+
+ // Add a formula that refers to one of the existing external workbooks
+ cell = wb1.getSheetAt(0).getRow(1).createCell(40);
+ cell.setCellFormula("Cost*[XRefCalcData.xls]MarkupSheet!$B$1");
+
+ // Check is was stored correctly
+ assertEquals("Cost*[XRefCalcData.xls]MarkupSheet!$B$1", cell.getCellFormula());
+
+ // Check it evaluates correctly
+ eval.evaluateFormulaCell(cell);
+ assertEquals(24.60 * 1.8, cell.getNumericCellValue(), 0);
+
+ // Try to add a formula for a new external workbook, won't be allowed to start
+ cell = wb1.getSheetAt(0).getRow(1).createCell(42);
+ final Cell cell2 = cell;
+ assertThrows(Exception.class, () -> cell2.setCellFormula("[alt.xls]Sheet0!$A$1"),
+ "New workbook not linked, shouldn't be able to add");
+
+ // Link our new workbook
+ try (HSSFWorkbook wb3 = new HSSFWorkbook()) {
+ wb3.createSheet().createRow(0).createCell(0).setCellValue("In another workbook");
+ assertEquals(2, wb1.linkExternalWorkbook("alt.xls", wb3));
+
+ // Now add a formula that refers to our new workbook
+ cell.setCellFormula("[alt.xls]Sheet0!$A$1");
+ assertEquals("[alt.xls]Sheet0!$A$1", cell.getCellFormula());
+
+ HSSFFormulaEvaluator eval2 = eval;
+ assertThrows(Exception.class, () -> eval2.evaluate(cell2),
+ "No cached value and no link to workbook, shouldn't evaluate");
+
+ // Add a link, check it does
+ HSSFFormulaEvaluator.setupEnvironment(
+ new String[]{"XRefCalc.xls", "XRefCalcData.xls", "alt.xls"},
+ new HSSFFormulaEvaluator[]{
+ eval,
+ new HSSFFormulaEvaluator(wb2),
+ new HSSFFormulaEvaluator(wb3)
+ }
+ );
+ eval.evaluateFormulaCell(cell);
+ assertEquals("In another workbook", cell.getStringCellValue());
+
+
+ // Save and re-load
+ try (HSSFWorkbook wb4 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
+ eval = new HSSFFormulaEvaluator(wb4);
+ HSSFFormulaEvaluator.setupEnvironment(
+ new String[]{"XRefCalc.xls", "XRefCalcData.xls", "alt.xls"},
+ new HSSFFormulaEvaluator[]{
+ eval,
+ new HSSFFormulaEvaluator(wb2),
+ new HSSFFormulaEvaluator(wb3)
+ }
+ );
+
+ // Check the one referring to the previously existing workbook behaves
+ cell = wb4.getSheetAt(0).getRow(1).getCell(40);
+ assertEquals("Cost*[XRefCalcData.xls]MarkupSheet!$B$1", cell.getCellFormula());
+ eval.evaluateFormulaCell(cell);
+ assertEquals(24.60 * 1.8, cell.getNumericCellValue(), 0);
+
+ // Now check the newly added reference
+ cell = wb4.getSheetAt(0).getRow(1).getCell(42);
+ assertEquals("[alt.xls]Sheet0!$A$1", cell.getCellFormula());
+ eval.evaluateFormulaCell(cell);
+ assertEquals("In another workbook", cell.getStringCellValue());
+ }
}
- throw e;
- } finally {
- wb.close();
- }
- }
-
- private static final class EvalCountListener extends EvaluationListener {
- private int _evalCount;
- public EvalCountListener() {
- _evalCount = 0;
- }
- @Override
- public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry) {
- _evalCount++;
- }
- public int getEvalCount() {
- return _evalCount;
- }
- }
-
- /**
- * The HSSFFormula evaluator performance benefits greatly from caching of intermediate cell values
- */
- @Test
- public void testShortCircuitIfEvaluation() throws IOException {
- // Set up a simple IF() formula that has measurable evaluation cost for its operands.
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet("Sheet1");
- HSSFRow row = sheet.createRow(0);
- HSSFCell cellA1 = row.createCell(0);
- cellA1.setCellFormula("if(B1,C1,D1+E1+F1)");
- // populate cells B1..F1 with simple formulas instead of plain values so we can use
- // EvaluationListener to check which parts of the first formula get evaluated
- for (int i=1; i<6; i++) {
- // formulas are just literal constants "1".."5"
- row.createCell(i).setCellFormula(String.valueOf(i));
}
+ }
- EvalCountListener evalListener = new EvalCountListener();
- WorkbookEvaluator evaluator = WorkbookEvaluatorTestHelper.createEvaluator(wb, evalListener);
- ValueEval ve = evaluator.evaluate(HSSFEvaluationTestHelper.wrapCell(cellA1));
- int evalCount = evalListener.getEvalCount();
- if (evalCount == 6) {
- // Without short-circuit-if evaluation, evaluating cell 'A1' takes 3 extra evaluations (for D1,E1,F1)
- fail("Identifed bug 48195 - Formula evaluator should short-circuit IF() calculations.");
- }
- assertEquals(3, evalCount);
- assertEquals(2.0, ((NumberEval)ve).getNumberValue(), 0D);
-
- wb.close();
- }
-
- /**
- * Ensures that we can handle NameXPtgs in the formulas
- * we parse.
- */
- @Test
- public void testXRefs() throws IOException {
- HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("XRefCalc.xls");
- HSSFWorkbook wb2 = HSSFTestDataSamples.openSampleWorkbook("XRefCalcData.xls");
- Cell cell;
-
- // VLookup on a name in another file
- cell = wb1.getSheetAt(0).getRow(1).getCell(2);
- assertEquals(CellType.FORMULA, cell.getCellType());
- assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
- assertEquals(12.30, cell.getNumericCellValue(), 0.0001);
- // WARNING - this is wrong!
- // The file name should be showing, but bug #45970 is fixed
- // we seem to loose it
- assertEquals("VLOOKUP(PART,COSTS,2,FALSE)", cell.getCellFormula());
-
-
- // Simple reference to a name in another file
- cell = wb1.getSheetAt(0).getRow(1).getCell(4);
- assertEquals(CellType.FORMULA, cell.getCellType());
- assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
- assertEquals(36.90, cell.getNumericCellValue(), 0.0001);
- // TODO Correct this!
- // The file name should be shown too, see bug #56742
- assertEquals("Cost*Markup_Cost", cell.getCellFormula());
-
-
- // Evaluate the cells
- HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb1);
- HSSFFormulaEvaluator.setupEnvironment(
- new String[] { "XRefCalc.xls", "XRefCalcData.xls" },
- new HSSFFormulaEvaluator[] {
- eval,
- new HSSFFormulaEvaluator(wb2)
- }
- );
- eval.evaluateFormulaCell(
- wb1.getSheetAt(0).getRow(1).getCell(2)
- );
- eval.evaluateFormulaCell(
- wb1.getSheetAt(0).getRow(1).getCell(4)
- );
-
-
- // Re-check VLOOKUP one
- cell = wb1.getSheetAt(0).getRow(1).getCell(2);
- assertEquals(CellType.FORMULA, cell.getCellType());
- assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
- assertEquals(12.30, cell.getNumericCellValue(), 0.0001);
-
- // Re-check ref one
- cell = wb1.getSheetAt(0).getRow(1).getCell(4);
- assertEquals(CellType.FORMULA, cell.getCellType());
- assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
- assertEquals(36.90, cell.getNumericCellValue(), 0.0001);
-
-
- // Add a formula that refers to one of the existing external workbooks
- cell = wb1.getSheetAt(0).getRow(1).createCell(40);
- cell.setCellFormula("Cost*[XRefCalcData.xls]MarkupSheet!$B$1");
-
- // Check is was stored correctly
- assertEquals("Cost*[XRefCalcData.xls]MarkupSheet!$B$1", cell.getCellFormula());
-
- // Check it evaluates correctly
- eval.evaluateFormulaCell(cell);
- assertEquals(24.60*1.8, cell.getNumericCellValue(), 0);
-
- // Try to add a formula for a new external workbook, won't be allowed to start
- try {
- cell = wb1.getSheetAt(0).getRow(1).createCell(42);
- cell.setCellFormula("[alt.xls]Sheet0!$A$1");
- fail("New workbook not linked, shouldn't be able to add");
- } catch(Exception e) {
- // expected here
- }
-
- // Link our new workbook
- HSSFWorkbook wb3 = new HSSFWorkbook();
- wb3.createSheet().createRow(0).createCell(0).setCellValue("In another workbook");
- assertEquals(2, wb1.linkExternalWorkbook("alt.xls", wb3));
-
- // Now add a formula that refers to our new workbook
- cell.setCellFormula("[alt.xls]Sheet0!$A$1");
- assertEquals("[alt.xls]Sheet0!$A$1", cell.getCellFormula());
-
- // Evaluate it, without a link to that workbook
- try {
- eval.evaluate(cell);
- fail("No cached value and no link to workbook, shouldn't evaluate");
- } catch(Exception e) {
- // expected here
- }
-
- // Add a link, check it does
- HSSFFormulaEvaluator.setupEnvironment(
- new String[] { "XRefCalc.xls", "XRefCalcData.xls", "alt.xls" },
- new HSSFFormulaEvaluator[] {
- eval,
- new HSSFFormulaEvaluator(wb2),
- new HSSFFormulaEvaluator(wb3)
- }
- );
- eval.evaluateFormulaCell(cell);
- assertEquals("In another workbook", cell.getStringCellValue());
-
-
- // Save and re-load
- HSSFWorkbook wb4 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
- eval = new HSSFFormulaEvaluator(wb4);
- HSSFFormulaEvaluator.setupEnvironment(
- new String[] { "XRefCalc.xls", "XRefCalcData.xls", "alt.xls" },
- new HSSFFormulaEvaluator[] {
- eval,
- new HSSFFormulaEvaluator(wb2),
- new HSSFFormulaEvaluator(wb3)
- }
- );
-
- // Check the one referring to the previously existing workbook behaves
- cell = wb4.getSheetAt(0).getRow(1).getCell(40);
- assertEquals("Cost*[XRefCalcData.xls]MarkupSheet!$B$1", cell.getCellFormula());
- eval.evaluateFormulaCell(cell);
- assertEquals(24.60*1.8, cell.getNumericCellValue(), 0);
-
- // Now check the newly added reference
- cell = wb4.getSheetAt(0).getRow(1).getCell(42);
- assertEquals("[alt.xls]Sheet0!$A$1", cell.getCellFormula());
- eval.evaluateFormulaCell(cell);
- assertEquals("In another workbook", cell.getStringCellValue());
-
- wb4.close();
- wb3.close();
- wb2.close();
- wb1.close();
- }
-
- @Test
+ @Test
public void testSharedFormulas() throws IOException {
baseTestSharedFormulas("shared_formulas.xls");
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java
index a8e8b33ae9..6d2263dd9b 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java
@@ -18,12 +18,12 @@
package org.apache.poi.hssf.usermodel;
import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link HSSFHeader} / {@link HSSFFooter}
@@ -156,14 +156,14 @@ public final class TestHSSFHeaderFooter {
try (HSSFWorkbook wb = openSampleWorkbook("DBCSHeader.xls")) {
HSSFSheet s = wb.getSheetAt(0);
HSSFHeader h = s.getHeader();
- assertEquals("Header Left ", h.getLeft(), "\u090f\u0915");
- assertEquals("Header Center ", h.getCenter(), "\u0939\u094b\u0917\u093e");
- assertEquals("Header Right ", h.getRight(), "\u091c\u093e");
+ assertEquals(h.getLeft(), "\u090f\u0915", "Header Left");
+ assertEquals(h.getCenter(), "\u0939\u094b\u0917\u093e", "Header Center");
+ assertEquals(h.getRight(), "\u091c\u093e", "Header Right");
HSSFFooter f = s.getFooter();
- assertEquals("Footer Left ", f.getLeft(), "\u091c\u093e");
- assertEquals("Footer Center ", f.getCenter(), "\u091c\u093e");
- assertEquals("Footer Right ", f.getRight(), "\u091c\u093e");
+ assertEquals(f.getLeft(), "\u091c\u093e", "Footer Left");
+ assertEquals(f.getCenter(), "\u091c\u093e", "Footer Center");
+ assertEquals(f.getRight(), "\u091c\u093e", "Footer Right");
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
index 39d20c1ebd..180624a495 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.usermodel;
-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;
@@ -28,13 +28,7 @@ import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BaseTestHyperlink;
import org.apache.poi.ss.usermodel.Hyperlink;
-/*
-import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
-import org.apache.poi.xssf.usermodel.XSSFHyperlink;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-*/
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests HSSFHyperlink.
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
index 566e2f57c5..cc4d519c65 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
@@ -17,6 +17,12 @@
package org.apache.poi.hssf.usermodel;
+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 org.apache.poi.POITestCase;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -26,11 +32,8 @@ import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.usermodel.BaseTestNamedRange;
import org.apache.poi.ss.usermodel.Name;
-import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.Test;
/**
* Tests various functionality having to do with {@link org.apache.poi.ss.usermodel.Name}.
@@ -126,7 +129,7 @@ public final class TestHSSFName extends BaseTestNamedRange {
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
HSSFName nm = wb2.getNameAt(wb2.getNameIndex("RangeTest"));
- assertEquals("Name is " + nm.getNameName(), "RangeTest", nm.getNameName());
+ assertEquals("RangeTest", nm.getNameName(), "Name is " + nm.getNameName());
assertEquals(wb2.getSheetName(0)+"!$D$4:$E$8", nm.getRefersToFormula());
wb2.close();
wb1.close();
@@ -152,16 +155,16 @@ public final class TestHSSFName extends BaseTestNamedRange {
String reference = namedRange1.getRefersToFormula();
assertEquals(sheetName+"!$A$1:$D$10", reference);
- assertEquals(false, namedRange1.isDeleted());
- assertEquals(false, namedRange1.isHidden());
+ assertFalse(namedRange1.isDeleted());
+ assertFalse(namedRange1.isHidden());
HSSFName namedRange2 = wb.getNameAt(1);
assertEquals(sheetName+"!$D$17:$G$27", namedRange2.getRefersToFormula());
assertEquals("SecondNamedRange", namedRange2.getNameName());
- assertEquals(false, namedRange2.isDeleted());
- assertEquals(false, namedRange2.isHidden());
-
+ assertFalse(namedRange2.isDeleted());
+ assertFalse(namedRange2.isHidden());
+
wb.close();
}
@@ -184,7 +187,7 @@ public final class TestHSSFName extends BaseTestNamedRange {
name.setRefersToFormula(newReference);
assertEquals(newReference, name.getRefersToFormula());
-
+
wb.close();
}
@@ -204,26 +207,23 @@ public final class TestHSSFName extends BaseTestNamedRange {
@Test
public void testDeletedReference() throws Exception {
- HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("24207.xls");
- assertEquals(2, wb.getNumberOfNames());
-
- HSSFName name1 = wb.getNameAt(0);
- assertEquals("a", name1.getNameName());
- assertEquals("Sheet1!$A$1", name1.getRefersToFormula());
- wb.getCreationHelper().createAreaReference(name1.getRefersToFormula());
- assertTrue("Successfully constructed first reference", true);
-
- HSSFName name2 = wb.getNameAt(1);
- assertEquals("b", name2.getNameName());
- assertEquals("Sheet1!#REF!", name2.getRefersToFormula());
- assertTrue(name2.isDeleted());
- try {
- wb.getCreationHelper().createAreaReference(name2.getRefersToFormula());
- fail("attempt to supply an invalid reference to AreaReference constructor results in exception");
- } catch (IllegalArgumentException e) { // TODO - use a stronger typed exception for this condition
- // expected during successful test
+ try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("24207.xls")) {
+ assertEquals(2, wb.getNumberOfNames());
+
+ HSSFName name1 = wb.getNameAt(0);
+ assertEquals("a", name1.getNameName());
+ assertEquals("Sheet1!$A$1", name1.getRefersToFormula());
+ wb.getCreationHelper().createAreaReference(name1.getRefersToFormula());
+
+ HSSFName name2 = wb.getNameAt(1);
+ assertEquals("b", name2.getNameName());
+ assertEquals("Sheet1!#REF!", name2.getRefersToFormula());
+ assertTrue(name2.isDeleted());
+ // TODO - use a stronger typed exception for this condition
+ assertThrows(IllegalArgumentException.class, () ->
+ wb.getCreationHelper().createAreaReference(name2.getRefersToFormula()),
+ "attempt to supply an invalid reference to AreaReference constructor results in exception");
}
- wb.close();
}
/**
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java
index 3a351afa06..c7c3ddbffb 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java
@@ -16,13 +16,17 @@
==================================================================== */
package org.apache.poi.hssf.usermodel;
-import java.io.IOException;
-
-import org.apache.poi.ss.usermodel.*;
-import org.junit.Test;
-
-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.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.junit.jupiter.api.Test;
public final class TestHSSFOptimiser {
@Test
@@ -324,8 +328,8 @@ public final class TestHSSFOptimiser {
@Test
public void testColumnAndRowStyles() {
HSSFWorkbook wb = new HSSFWorkbook();
- assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()",
- 21, wb.getNumCellStyles());
+ assertEquals(21, wb.getNumCellStyles(),
+ "Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()");
HSSFSheet sheet = wb.createSheet();
@@ -357,8 +361,8 @@ public final class TestHSSFOptimiser {
@Test
public void testUnusedStyle() {
HSSFWorkbook wb = new HSSFWorkbook();
- assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()",
- 21, wb.getNumCellStyles());
+ assertEquals(21, wb.getNumCellStyles(),
+ "Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()");
HSSFSheet sheet = wb.createSheet();
@@ -395,8 +399,8 @@ public final class TestHSSFOptimiser {
@Test
public void testUnusedStyleOneUsed() {
HSSFWorkbook wb = new HSSFWorkbook();
- assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()",
- 21, wb.getNumCellStyles());
+ assertEquals(21, wb.getNumCellStyles(),
+ "Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()");
HSSFSheet sheet = wb.createSheet();
@@ -431,10 +435,10 @@ public final class TestHSSFOptimiser {
}
@Test
- public void testDefaultColumnStyleWitoutCell() throws IOException {
+ public void testDefaultColumnStyleWitoutCell() {
HSSFWorkbook wb = new HSSFWorkbook();
- assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()",
- 21, wb.getNumCellStyles());
+ assertEquals(21, wb.getNumCellStyles(),
+ "Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()");
HSSFSheet sheet = wb.createSheet();
@@ -473,10 +477,10 @@ public final class TestHSSFOptimiser {
}
@Test
- public void testUserDefinedStylesAreNeverOptimizedAway() throws IOException {
+ public void testUserDefinedStylesAreNeverOptimizedAway() {
HSSFWorkbook wb = new HSSFWorkbook();
- assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()",
- 21, wb.getNumCellStyles());
+ assertEquals(21, wb.getNumCellStyles(),
+ "Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()");
HSSFSheet sheet = wb.createSheet();
@@ -532,10 +536,10 @@ public final class TestHSSFOptimiser {
}
@Test
- public void testBug57517() throws IOException {
+ public void testBug57517() {
HSSFWorkbook wb = new HSSFWorkbook();
- assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()",
- 21, wb.getNumCellStyles());
+ assertEquals(21, wb.getNumCellStyles(),
+ "Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()");
HSSFSheet sheet = wb.createSheet();
@@ -599,7 +603,7 @@ public final class TestHSSFOptimiser {
// Create a test font and style, and use them
for (int i = 3; i < 6; i++) {
// Set Cell Color : GREEN
- HSSFRow row = sheet.getRow(0 + 9);
+ HSSFRow row = sheet.getRow(9);
row.createCell(i - 3).setCellStyle(
createColorStyle(wb, IndexedColors.GREEN));
obj_cnt++;
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
index e26146a1eb..d009a6f58a 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
@@ -17,15 +17,14 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.awt.Color;
import java.io.IOException;
-import java.util.Iterator;
import java.util.Map;
import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -34,17 +33,16 @@ import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public final class TestHSSFPalette {
- private PaletteRecord _palette;
private HSSFPalette _hssfPalette;
- @Before
+ @BeforeEach
public void setUp() {
- _palette = new PaletteRecord();
+ PaletteRecord _palette = new PaletteRecord();
_hssfPalette = new HSSFPalette(_palette);
}
@@ -66,27 +64,27 @@ public final class TestHSSFPalette {
palette = book.getCustomPalette();
HSSFColor color = palette.getColor(HSSFColorPredefined.CORAL.getIndex()); //unmodified
- assertNotNull("Unexpected null in custom palette (unmodified index)", color);
+ assertNotNull(color, "Unexpected null in custom palette (unmodified index)");
short[] expectedRGB = HSSFColorPredefined.CORAL.getTriplet();
short[] actualRGB = color.getTriplet();
String msg = "Expected palette position to remain unmodified";
- assertEquals(msg, expectedRGB[0], actualRGB[0]);
- assertEquals(msg, expectedRGB[1], actualRGB[1]);
- assertEquals(msg, expectedRGB[2], actualRGB[2]);
+ assertEquals(expectedRGB[0], actualRGB[0], msg);
+ assertEquals(expectedRGB[1], actualRGB[1], msg);
+ assertEquals(expectedRGB[2], actualRGB[2], msg);
color = palette.getColor((short) 0x12);
- assertNotNull("Unexpected null in custom palette (modified)", color);
+ assertNotNull(color, "Unexpected null in custom palette (modified)");
actualRGB = color.getTriplet();
msg = "Expected palette modification to be preserved across save";
- assertEquals(msg, (short) 101, actualRGB[0]);
- assertEquals(msg, (short) 230, actualRGB[1]);
- assertEquals(msg, (short) 100, actualRGB[2]);
+ assertEquals((short) 101, actualRGB[0], msg);
+ assertEquals((short) 230, actualRGB[1], msg);
+ assertEquals((short) 100, actualRGB[2], msg);
}
/**
* Uses the palette from cell stylings
*/
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("ConstantConditions")
@Test
public void testPaletteFromCellColours() {
HSSFWorkbook book = HSSFTestDataSamples.openSampleWorkbook("SimpleWithColours.xls");
@@ -105,6 +103,7 @@ public final class TestHSSFPalette {
assertEquals(64, cellA.getCellStyle().getFillBackgroundColor());
assertEquals(Font.COLOR_NORMAL, cellA.getCellStyle().getFont(book).getColor());
assertEquals(FillPatternType.NO_FILL, cellA.getCellStyle().getFillPattern());
+ assertNotNull(p.getColor((short)64));
assertEquals("0:0:0", p.getColor((short)64).getHexString());
assertNull(p.getColor((short) 32767));
@@ -145,11 +144,12 @@ public final class TestHSSFPalette {
assertEquals("FFFF:0:FFFF", p.getColor((short)14).getHexString());
}
+ @SuppressWarnings("ConstantConditions")
@Test
public void testFindSimilar() throws IOException {
HSSFWorkbook book = new HSSFWorkbook();
HSSFPalette p = book.getCustomPalette();
-
+
/* first test the defaults */
assertArrayEquals(
new short[] {(short) 255, (short) 255, (short) 0}, // not [204, 255, 255]
@@ -218,7 +218,7 @@ public final class TestHSSFPalette {
p.getColor((short)12).getHexString(),
p.findSimilarColor((byte)-1, (byte)2, (byte)10).getHexString()
);
-
+
// And with ints not bytes
assertEquals(
p.getColor((short)11).getHexString(),
@@ -228,23 +228,17 @@ public final class TestHSSFPalette {
p.getColor((short)12).getHexString(),
p.findSimilarColor(255, 2, 10).getHexString()
);
-
+
book.close();
}
-
+
/**
* Verifies that the generated gnumeric-format string values match the
* hardcoded values in the HSSFColor default color palette
*/
@Test
public void testGnumericStrings() {
- compareToDefaults(new ColorComparator() {
- @Override
- public void compare(HSSFColor expected, HSSFColor palette)
- {
- assertEquals(expected.getHexString(), palette.getHexString());
- }
- });
+ compareToDefaults((expected, palette) -> assertEquals(expected.getHexString(), palette.getHexString()));
}
/**
@@ -258,25 +252,18 @@ public final class TestHSSFPalette {
_hssfPalette.setColorAtIndex((short) 0x45, (byte) 255, (byte) 255, (byte) 255);
//should still match defaults;
- compareToDefaults(new ColorComparator() {
- @Override
- public void compare(HSSFColor expected, HSSFColor palette)
- {
- short[] s1 = expected.getTriplet();
- short[] s2 = palette.getTriplet();
- assertEquals(s1[0], s2[0]);
- assertEquals(s1[1], s2[1]);
- assertEquals(s1[2], s2[2]);
- }
+ compareToDefaults((expected, palette) -> {
+ short[] s1 = expected.getTriplet();
+ short[] s2 = palette.getTriplet();
+ assertEquals(s1[0], s2[0]);
+ assertEquals(s1[1], s2[1]);
+ assertEquals(s1[2], s2[2]);
});
}
private void compareToDefaults(ColorComparator c) {
Map<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
- Iterator<Integer> it = colors.keySet().iterator();
- while (it.hasNext())
- {
- Number index = it.next();
+ for (Integer index : colors.keySet()) {
HSSFColor expectedColor = colors.get(index);
HSSFColor paletteColor = _hssfPalette.getColor(index.shortValue());
c.compare(expectedColor, paletteColor);
@@ -285,16 +272,11 @@ public final class TestHSSFPalette {
@Test
public void testAddColor() {
- try
- {
- _hssfPalette.addColor((byte)10,(byte)10,(byte)10);
- fail();
- } catch (RuntimeException e) {
- // Failing because by default there are no colours left in the palette.
- }
+ assertThrows(RuntimeException.class, () -> _hssfPalette.addColor((byte)10,(byte)10,(byte)10),
+ "Failing because by default there are no colours left in the palette.");
}
- private static interface ColorComparator {
+ private interface ColorComparator {
void compare(HSSFColor expected, HSSFColor palette);
}
@@ -304,7 +286,7 @@ public final class TestHSSFPalette {
Color color = Color.decode("#006B6B");
HSSFPalette palette = wb.getCustomPalette();
-
+
HSSFColor hssfColor = palette.findColor((byte) color.getRed(),
(byte) color.getGreen(), (byte) color.getBlue());
assertNull(hssfColor);
@@ -317,7 +299,7 @@ public final class TestHSSFPalette {
assertNotNull(hssfColor);
assertEquals(55, hssfColor.getIndex());
assertArrayEquals(new short[] {0, 107, 107}, hssfColor.getTriplet());
-
+
wb.close();
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java
index ff65cbe113..4e81dbc402 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestHSSFPatriarch {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
index 95bd508770..5de42c63ef 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.Arrays;
@@ -34,7 +34,7 @@ import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Workbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestHSSFPicture extends BaseTestPicture {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
index 986bad978d..0a9a0b8894 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+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 java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
@@ -31,15 +31,15 @@ import javax.imageio.IIOException;
import javax.imageio.ImageIO;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
* Test <code>HSSFPictureData</code>.
* The code to retrieve images from a workbook provided by Trejkaz (trejkaz at trypticon dot org) in Bug 41223.
*/
public final class TestHSSFPictureData {
- @BeforeClass
+ @BeforeAll
public static void setUpClass() {
final String tmpDirProperty = System.getProperty("java.io.tmpdir");
if(tmpDirProperty == null || "".equals(tmpDirProperty)) {
@@ -86,7 +86,7 @@ public final class TestHSSFPictureData {
}
}
} catch (IIOException e) {
- assertFalse(e.getMessage(), e.getMessage().contains("Can't create cache file"));
+ assertFalse(e.getMessage().contains("Can't create cache file"), e.getMessage());
}
}
@@ -100,7 +100,7 @@ public final class TestHSSFPictureData {
HSSFPictureData pict = lst.get(0);
String ext = pict.suggestFileExtension();
- assertEquals("Expected a PNG.", "png", ext);
+ assertEquals("png", ext, "Expected a PNG.");
//try to read image data using javax.imageio.* (JDK 1.4+)
byte[] data = pict.getData();
@@ -111,7 +111,7 @@ public final class TestHSSFPictureData {
assertEquals(HSSFWorkbook.PICTURE_TYPE_PNG, pict.getFormat());
assertEquals("image/png", pict.getMimeType());
} catch (IIOException e) {
- assertFalse(e.getMessage(), e.getMessage().contains("Can't create cache file"));
+ assertFalse(e.getMessage().contains("Can't create cache file"), e.getMessage());
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRangeCopier.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRangeCopier.java
index 07f37d8e4a..9ba33f7d8c 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRangeCopier.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRangeCopier.java
@@ -22,7 +22,7 @@ package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BaseTestRangeCopier;
-import org.junit.Before;
+import org.junit.jupiter.api.BeforeEach;
public class TestHSSFRangeCopier extends BaseTestRangeCopier {
@@ -32,7 +32,7 @@ public class TestHSSFRangeCopier extends BaseTestRangeCopier {
testDataProvider = HSSFITestDataProvider.instance;
}
- @Before
+ @BeforeEach
public void init() {
workbook = HSSFTestDataSamples.openSampleWorkbook("tile-range-test.xls");
initSheets();
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java
index 442bf7e8c5..36d8f13c78 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestHSSFRichTextString {
@Test
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
index 53d799e953..0bfef5735b 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
@@ -17,6 +17,13 @@
package org.apache.poi.hssf.usermodel;
+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.HSSFITestDataProvider;
@@ -24,9 +31,7 @@ import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.BaseTestRow;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.Test;
/**
* Test HSSFRow is okay.
@@ -67,9 +72,8 @@ public final class TestHSSFRow extends BaseTestRow {
HSSFRow row = new HSSFRow(workbook, sheet, rowRec);
HSSFCell cell = row.createCellFromRecord(br);
- if (row.getFirstCellNum() == 2 && row.getLastCellNum() == 5) {
- fail("Identified bug 46654a");
- }
+ assertFalse(row.getFirstCellNum() == 2 && row.getLastCellNum() == 5, "Identified bug 46654a");
+
assertEquals(COL_IX, row.getFirstCellNum());
assertEquals(COL_IX + 1, row.getLastCellNum());
row.removeCell(cell);
@@ -100,20 +104,10 @@ public final class TestHSSFRow extends BaseTestRow {
assertEquals(4, row.getLastCellNum());
// Try to move to somewhere else that's used
- try {
- row.moveCell(cellB2, (short)3);
- fail("IllegalArgumentException should have been thrown");
- } catch(IllegalArgumentException e) {
- // expected during successful test
- }
+ assertThrows(IllegalArgumentException.class, () -> row.moveCell(cellB2, (short)3));
// Try to move one off a different row
- try {
- row.moveCell(cellA2, (short)3);
- fail("IllegalArgumentException should have been thrown");
- } catch(IllegalArgumentException e) {
- // expected during successful test
- }
+ assertThrows(IllegalArgumentException.class, () -> row.moveCell(cellA2, (short)3));
// Move somewhere spare
assertNotNull(row.getCell(1));
@@ -124,7 +118,7 @@ public final class TestHSSFRow extends BaseTestRow {
assertEquals(5, cellB2.getColumnIndex());
assertEquals(2, row.getFirstCellNum());
assertEquals(6, row.getLastCellNum());
-
+
workbook.close();
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
index 09906b8e27..38f5b28422 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
@@ -18,7 +18,15 @@
package org.apache.poi.hssf.usermodel;
import static org.apache.poi.hssf.HSSFTestDataSamples.writeOutAndReadBack;
-import static org.junit.Assert.*;
+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.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.ArrayList;
@@ -43,7 +51,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.CellRangeAddressList;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests HSSFSheet. This test case is very incomplete at the moment.
@@ -390,10 +398,10 @@ public final class TestHSSFSheet extends BaseTestSheet {
HSSFSheet s = wb.createSheet();
s.protectSheet("abcdefghij");
WorksheetProtectionBlock pb = s.getSheet().getProtectionBlock();
- assertTrue("protection should be on", pb.isSheetProtected());
- assertTrue("object protection should be on", pb.isObjectProtected());
- assertTrue("scenario protection should be on", pb.isScenarioProtected());
- assertEquals("well known value for top secret hash should be " + Integer.toHexString(expectedHash).substring(4), expectedHash, pb.getPasswordHash());
+ assertTrue(pb.isSheetProtected(), "protection should be on");
+ assertTrue(pb.isObjectProtected(), "object protection should be on");
+ assertTrue(pb.isScenarioProtected(), "scenario protection should be on");
+ assertEquals(expectedHash, pb.getPasswordHash(), "well known value for top secret hash should be " + Integer.toHexString(expectedHash).substring(4));
}
}
@@ -465,30 +473,18 @@ public final class TestHSSFSheet extends BaseTestSheet {
assertEquals(sclLoc, window2Loc + 1);
// verify limits
- try {
- sheet.setZoom(0);
- fail("Should catch Exception here");
- } catch (IllegalArgumentException e) {
- assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage());
- }
- try {
- sheet.setZoom(65536);
- fail("Should catch Exception here");
- } catch (IllegalArgumentException e) {
- assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage());
- }
- try {
- sheet.setZoom(2, 0);
- fail("Should catch Exception here");
- } catch (IllegalArgumentException e) {
- assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage());
- }
- try {
- sheet.setZoom(2, 65536);
- fail("Should catch Exception here");
- } catch (IllegalArgumentException e) {
- assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage());
- }
+ IllegalArgumentException e;
+ e = assertThrows(IllegalArgumentException.class, () -> sheet.setZoom(0));
+ assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage());
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheet.setZoom(65536));
+ assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage());
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheet.setZoom(2, 0));
+ assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage());
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheet.setZoom(2, 65536));
+ assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage());
}
}
@@ -504,26 +500,26 @@ public final class TestHSSFSheet extends BaseTestSheet {
HSSFSheet sheet = wb1.getSheetAt(0);
assertNotNull(sheet);
- assertEquals("1 row page break", 1, sheet.getRowBreaks().length);
- assertEquals("1 column page break", 1, sheet.getColumnBreaks().length);
+ assertEquals(1, sheet.getRowBreaks().length, "1 row page break");
+ assertEquals(1, sheet.getColumnBreaks().length, "1 column page break");
- assertTrue("No row page break", sheet.isRowBroken(22));
- assertTrue("No column page break", sheet.isColumnBroken((short) 4));
+ assertTrue(sheet.isRowBroken(22), "No row page break");
+ assertTrue(sheet.isColumnBroken((short) 4), "No column page break");
sheet.setRowBreak(10);
sheet.setColumnBreak((short) 13);
- assertEquals("row breaks number", 2, sheet.getRowBreaks().length);
- assertEquals("column breaks number", 2, sheet.getColumnBreaks().length);
+ assertEquals(2, sheet.getRowBreaks().length, "row breaks number");
+ assertEquals(2, sheet.getColumnBreaks().length, "column breaks number");
try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) {
sheet = wb2.getSheetAt(0);
- assertTrue("No row page break", sheet.isRowBroken(22));
- assertTrue("No column page break", sheet.isColumnBroken((short) 4));
+ assertTrue(sheet.isRowBroken(22), "No row page break");
+ assertTrue(sheet.isColumnBroken((short) 4), "No column page break");
- assertEquals("row breaks number", 2, sheet.getRowBreaks().length);
- assertEquals("column breaks number", 2, sheet.getColumnBreaks().length);
+ assertEquals(2, sheet.getRowBreaks().length, "row breaks number");
+ assertEquals(2, sheet.getColumnBreaks().length, "column breaks number");
}
}
}
@@ -532,8 +528,8 @@ public final class TestHSSFSheet extends BaseTestSheet {
public void dbcsName () throws IOException {
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DBCSSheetName.xls")) {
wb.getSheetAt(1);
- assertEquals("DBCS Sheet Name 2", wb.getSheetName(1), "\u090f\u0915");
- assertEquals("DBCS Sheet Name 1", wb.getSheetName(0), "\u091c\u093e");
+ assertEquals(wb.getSheetName(1), "\u090f\u0915", "DBCS Sheet Name 2");
+ assertEquals(wb.getSheetName(0), "\u091c\u093e", "DBCS Sheet Name 1");
}
}
@@ -551,8 +547,8 @@ public final class TestHSSFSheet extends BaseTestSheet {
short toprow = (short) 100;
short leftcol = (short) 50;
sheet.showInPane(toprow, leftcol);
- assertEquals("HSSFSheet.getTopRow()", toprow, sheet.getTopRow());
- assertEquals("HSSFSheet.getLeftCol()", leftcol, sheet.getLeftCol());
+ assertEquals(toprow, sheet.getTopRow(), "HSSFSheet.getTopRow()");
+ assertEquals(leftcol, sheet.getLeftCol(), "HSSFSheet.getLeftCol()");
}
}
@@ -597,8 +593,8 @@ public final class TestHSSFSheet extends BaseTestSheet {
// autoSize the first column and check its size before the merged region (1,0,1,1) is set:
// it has to be based on the 2nd row width
sheet.autoSizeColumn((short) 0);
- assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth(0) >= minWithRow1And2);
- assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth(0) <= maxWithRow1And2);
+ assertTrue(sheet.getColumnWidth(0) >= minWithRow1And2, "Column autosized with only one row: wrong width");
+ assertTrue(sheet.getColumnWidth(0) <= maxWithRow1And2, "Column autosized with only one row: wrong width");
//create a region over the 2nd row and auto size the first column
assertEquals(1, sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 1)));
@@ -779,11 +775,11 @@ public final class TestHSSFSheet extends BaseTestSheet {
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex41187-19267.xls")) {
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(0);
- assertNotNull("Identified bug 41187 a", row);
+ assertNotNull(row, "Identified bug 41187 a");
- assertNotEquals("Identified bug 41187 b", (short) 0, row.getHeight());
+ assertNotEquals((short) 0, row.getHeight(), "Identified bug 41187 b");
- assertEquals("Hi Excel!", row.getCell(0).getRichStringCellValue().getString());
+ assertEquals(row.getCell(0).getRichStringCellValue().getString(), "Hi Excel!");
// check row height for 'default' flag
assertEquals((short) 0xFF, row.getHeight());
@@ -838,12 +834,10 @@ public final class TestHSSFSheet extends BaseTestSheet {
final String SAME_PREFIX = "A123456789B123456789C123456789"; // 30 chars
wb.createSheet(SAME_PREFIX + "Dxxxx");
- try {
- wb.createSheet(SAME_PREFIX + "Dyyyy"); // identical up to the 32nd char
- fail("Expected exception not thrown");
- } catch (IllegalArgumentException e) {
- assertEquals("The workbook already contains a sheet named 'A123456789B123456789C123456789Dyyyy'", e.getMessage());
- }
+ // identical up to the 32nd char
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> wb.createSheet(SAME_PREFIX + "Dyyyy"));
+ assertEquals("The workbook already contains a sheet named 'A123456789B123456789C123456789Dyyyy'", e.getMessage());
+
wb.createSheet(SAME_PREFIX + "Exxxx"); // OK - differs in the 31st char
}
}
@@ -923,8 +917,8 @@ public final class TestHSSFSheet extends BaseTestSheet {
// The built-in name for auto-filter must consist of a single Area3d Ptg.
Ptg[] ptg = name.getNameDefinition();
- assertEquals("The built-in name for auto-filter must consist of a single Area3d Ptg", 1, ptg.length);
- assertTrue("The built-in name for auto-filter must consist of a single Area3d Ptg", ptg[0] instanceof Area3DPtg);
+ assertEquals(1, ptg.length, "The built-in name for auto-filter must consist of a single Area3d Ptg");
+ assertTrue(ptg[0] instanceof Area3DPtg, "The built-in name for auto-filter must consist of a single Area3d Ptg");
Area3DPtg aref = (Area3DPtg) ptg[0];
assertEquals(range.getFirstColumn(), aref.getFirstColumn());
@@ -1003,12 +997,10 @@ public final class TestHSSFSheet extends BaseTestSheet {
assertEquals(40000, sheet.getColumnWidth((short) 10));
//The maximum column width for an individual cell is 255 characters
- try {
- sheet.setColumnWidth((short) 9, 256 * 256);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertEquals("The maximum column width for an individual cell is 255 characters.", e.getMessage());
- }
+ Sheet sheet2 = sheet;
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () ->
+ sheet2.setColumnWidth((short) 9, 256 * 256));
+ assertEquals("The maximum column width for an individual cell is 255 characters.", e.getMessage());
//serialize and read again
try (HSSFWorkbook wb2 = writeOutAndReadBack(wb1)) {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetShiftColumns.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetShiftColumns.java
index f5be8470d2..5da9a1c606 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetShiftColumns.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetShiftColumns.java
@@ -24,14 +24,14 @@ import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BaseTestSheetShiftColumns;
import org.apache.poi.ss.usermodel.Workbook;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
public class TestHSSFSheetShiftColumns extends BaseTestSheetShiftColumns {
public TestHSSFSheetShiftColumns() {
- super();
+ super();
workbook = new HSSFWorkbook();
- _testDataProvider = HSSFITestDataProvider.instance;
+ _testDataProvider = HSSFITestDataProvider.instance;
}
protected Workbook openWorkbook(String spreadsheetFileName)
@@ -42,45 +42,45 @@ public class TestHSSFSheetShiftColumns extends BaseTestSheetShiftColumns {
protected Workbook getReadBackWorkbook(Workbook wb) throws IOException {
return HSSFTestDataSamples.writeOutAndReadBack((HSSFWorkbook)wb);
}
-
- @Override
- @Ignore("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
+
+ @Override
+ @Disabled("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
@Test
public void shiftMergedColumnsToMergedColumnsLeft() throws IOException {
- // This override is used only in order to test failing for HSSF. Please remove method after code is fixed on hssf,
- // so that original method from BaseTestSheetShiftColumns can be executed.
+ // This override is used only in order to test failing for HSSF. Please remove method after code is fixed on hssf,
+ // so that original method from BaseTestSheetShiftColumns can be executed.
}
- @Override
- @Ignore("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
+ @Override
+ @Disabled("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
@Test
public void shiftMergedColumnsToMergedColumnsRight() throws IOException {
- // This override is used only in order to test failing for HSSF. Please remove method after code is fixed on hssf,
- // so that original method from BaseTestSheetShiftColumns can be executed.
+ // This override is used only in order to test failing for HSSF. Please remove method after code is fixed on hssf,
+ // so that original method from BaseTestSheetShiftColumns can be executed.
}
- @Override
- @Ignore("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
+ @Override
+ @Disabled("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
@Test
public void testBug54524() throws IOException {
- // This override is used only in order to test failing for HSSF. Please remove method after code is fixed on hssf,
- // so that original method from BaseTestSheetShiftColumns can be executed.
+ // This override is used only in order to test failing for HSSF. Please remove method after code is fixed on hssf,
+ // so that original method from BaseTestSheetShiftColumns can be executed.
}
- @Override
- @Ignore("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
+ @Override
+ @Disabled("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
@Test
public void testCommentsShifting() throws IOException {
- // This override is used only in order to test failing for HSSF. Please remove method after code is fixed on hssf,
- // so that original method from BaseTestSheetShiftColumns can be executed.
+ // This override is used only in order to test failing for HSSF. Please remove method after code is fixed on hssf,
+ // so that original method from BaseTestSheetShiftColumns can be executed.
}
- @Override
- @Ignore("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
+ @Override
+ @Disabled("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
@Test
public void testShiftWithMergedRegions() throws IOException {
- // This override is used only in order to test failing for HSSF. Please remove method after code is fixed on hssf,
- // so that original method from BaseTestSheetShiftColumns can be executed.
- // After removing, you can re-add 'final' keyword to specification of original method.
+ // This override is used only in order to test failing for HSSF. Please remove method after code is fixed on hssf,
+ // so that original method from BaseTestSheetShiftColumns can be executed.
+ // After removing, you can re-add 'final' keyword to specification of original method.
}
@Override
- @Ignore("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
+ @Disabled("see <https://bz.apache.org/bugzilla/show_bug.cgi?id=62030>")
@Test
public void testShiftHyperlinks() throws IOException {}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java
index cc06e8fca6..7007c1edbc 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetUpdateArrayFormulas.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertArrayEquals;
-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.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.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 java.io.IOException;
import java.util.ArrayList;
@@ -33,14 +33,13 @@ import org.apache.poi.POITestCase;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.record.ArrayRecord;
import org.apache.poi.hssf.record.FormulaRecord;
-import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.SharedValueManager;
import org.apache.poi.ss.usermodel.BaseTestSheetUpdateArrayFormulas;
import org.apache.poi.ss.usermodel.CellRange;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test array formulas in HSSF
@@ -113,7 +112,7 @@ public final class TestHSSFSheetUpdateArrayFormulas extends BaseTestSheetUpdateA
RowRecordsAggregate rra = s.getSheet().getRowsAggregate();
SharedValueManager svm = POITestCase.getFieldValue(RowRecordsAggregate.class, rra, SharedValueManager.class, "_sharedValueManager");
- assertNull("Array record was not cleaned up properly.", svm.getArrayRecord(4, 1));
+ assertNull(svm.getArrayRecord(4, 1), "Array record was not cleaned up properly.");
}
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java
index e727e321bd..8d01fb2bc1 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java
@@ -17,11 +17,11 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test <code>HSSFTextbox</code>.
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
index fde0d769d2..4a7c855958 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
@@ -19,12 +19,13 @@ package org.apache.poi.hssf.usermodel;
import static org.apache.poi.POITestCase.assertContains;
import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
-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 java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -70,14 +71,17 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.TempFile;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
/**
* Tests for {@link HSSFWorkbook}
*/
public final class TestHSSFWorkbook extends BaseTestWorkbook {
private static final HSSFITestDataProvider _testDataProvider = HSSFITestDataProvider.instance;
+ private static final POIDataSamples samples = POIDataSamples.getSpreadSheetInstance();
public TestHSSFWorkbook() {
super(_testDataProvider);
@@ -208,9 +212,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
// Demonstrate bug 44525:
// Well... not quite, since isActive + isSelected were also added in the same bug fix
- assertFalse("Identified bug 44523 a", sheet1.isSelected());
+ assertFalse(sheet1.isSelected(), "Identified bug 44523 a");
wb.setActiveSheet(1);
- assertFalse("Identified bug 44523 b", sheet1.isActive());
+ assertFalse(sheet1.isActive(), "Identified bug 44523 b");
confirmActiveSelected(sheet1, false);
confirmActiveSelected(sheet2, true);
@@ -229,7 +233,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
}
private static void assertCollectionsEquals(Collection<Integer> expected, Collection<Integer> actual) {
- assertEquals("size", expected.size(), actual.size());
+ assertEquals(expected.size(), actual.size());
for (int e : expected) {
assertTrue(actual.contains(e));
}
@@ -278,22 +282,6 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertFalse(sheet0.isActive());
assertTrue(sheet2.isActive());
- /*{ // helpful if viewing this workbook in excel:
- sheet0.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet0"));
- sheet1.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet1"));
- sheet2.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet2"));
- sheet3.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet3"));
-
- try {
- File fOut = TempFile.createTempFile("sheetMultiSelect", ".xls");
- FileOutputStream os = new FileOutputStream(fOut);
- wb.write(os);
- os.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }*/
-
wb.close();
}
@@ -325,8 +313,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
wb.removeSheetAt(3);
// after removing the only active/selected sheet, another should be active/selected in its place
- assertTrue("identified bug 40414 a", sheet4.isSelected());
- assertTrue("identified bug 40414 b", sheet4.isActive());
+ assertTrue(sheet4.isSelected(), "identified bug 40414 a");
+ assertTrue(sheet4.isActive(), "identified bug 40414 b");
confirmActiveSelected(sheet0, false);
confirmActiveSelected(sheet1, false);
@@ -370,8 +358,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
private static void confirmActiveSelected(HSSFSheet sheet,
boolean expectedActive, boolean expectedSelected) {
- assertEquals("active", expectedActive, sheet.isActive());
- assertEquals("selected", expectedSelected, sheet.isSelected());
+ assertEquals(expectedActive, sheet.isActive(), "active");
+ assertEquals(expectedSelected, sheet.isSelected(), "selected");
}
/**
@@ -382,21 +370,15 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
*/
@Test
public void sheetSerializeSizeMismatch_bug45066() throws IOException {
- HSSFWorkbook wb = new HSSFWorkbook();
- InternalSheet sheet = wb.createSheet("Sheet1").getSheet();
- List<RecordBase> sheetRecords = sheet.getRecords();
- // one way (of many) to cause the discrepancy is with a badly behaved record:
- sheetRecords.add(new BadlyBehavedRecord());
- // There is also much logic inside Sheet that (if buggy) might also cause the discrepancy
- try {
- wb.getBytes();
- fail("Identified bug 45066 a");
- } catch (IllegalStateException e) {
- // Expected badly behaved sheet record to cause exception
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ InternalSheet sheet = wb.createSheet("Sheet1").getSheet();
+ List<RecordBase> sheetRecords = sheet.getRecords();
+ // one way (of many) to cause the discrepancy is with a badly behaved record:
+ sheetRecords.add(new BadlyBehavedRecord());
+ // There is also much logic inside Sheet that (if buggy) might also cause the discrepancy
+ IllegalStateException e = assertThrows(IllegalStateException.class, wb::getBytes, "Identified bug 45066 a");
assertTrue(e.getMessage().startsWith("Actual serialized sheet size"));
}
-
- wb.close();
}
/**
@@ -572,7 +554,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
*/
@Test
public void bug47920() throws IOException {
- POIFSFileSystem fs1 = new POIFSFileSystem(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("47920.xls"));
+ POIFSFileSystem fs1 = new POIFSFileSystem(samples.openResourceAsStream("47920.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs1);
ClassID clsid1 = fs1.getRoot().getStorageClsid();
@@ -593,34 +575,19 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
* If we try to open an old (pre-97) workbook, we get a helpful
* Exception give to explain what we've done wrong
*/
- @Test
- public void helpfulExceptionOnOldFiles() throws Exception {
- InputStream excel4 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_4.xls");
- try {
- new HSSFWorkbook(excel4).close();
- fail("Shouldn't be able to load an Excel 4 file");
- } catch (OldExcelFormatException e) {
- assertContains(e.getMessage(), "BIFF4");
- }
- excel4.close();
-
- InputStream excel5 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_5.xls");
- try {
- new HSSFWorkbook(excel5).close();
- fail("Shouldn't be able to load an Excel 5 file");
- } catch (OldExcelFormatException e) {
- assertContains(e.getMessage(), "BIFF5");
- }
- excel5.close();
-
- InputStream excel95 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_95.xls");
- try {
- new HSSFWorkbook(excel95).close();
- fail("Shouldn't be able to load an Excel 95 file");
- } catch (OldExcelFormatException e) {
- assertContains(e.getMessage(), "BIFF5");
+ @ParameterizedTest
+ @CsvSource({
+ "testEXCEL_4.xls,BIFF4",
+ "testEXCEL_5.xls,BIFF5",
+ "testEXCEL_95.xls,BIFF5"
+ })
+ public void helpfulExceptionOnOldFiles(String file, String format) throws Exception {
+ POIDataSamples xlsData = samples;
+ try (InputStream is = xlsData.openResourceAsStream(file)) {
+ OldExcelFormatException e = assertThrows(OldExcelFormatException.class, () -> new HSSFWorkbook(is),
+ "Shouldn't be able to load an Excel " + format + " file");
+ assertContains(e.getMessage(), format);
}
- excel95.close();
}
/**
@@ -717,25 +684,20 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
@Test
public void cellStylesLimit() throws IOException {
- Workbook wb = new HSSFWorkbook();
- int numBuiltInStyles = wb.getNumCellStyles();
- int MAX_STYLES = 4030;
- int limit = MAX_STYLES - numBuiltInStyles;
- for(int i=0; i < limit; i++){
- /* HSSFCellStyle style =*/ wb.createCellStyle();
- }
+ try (Workbook wb = new HSSFWorkbook()) {
+ int numBuiltInStyles = wb.getNumCellStyles();
+ int MAX_STYLES = 4030;
+ int limit = MAX_STYLES - numBuiltInStyles;
+ for (int i = 0; i < limit; i++) {
+ wb.createCellStyle();
+ }
- assertEquals(MAX_STYLES, wb.getNumCellStyles());
- try {
- /*HSSFCellStyle style =*/ wb.createCellStyle();
- fail("expected exception");
- } catch (IllegalStateException e){
+ assertEquals(MAX_STYLES, wb.getNumCellStyles());
+ IllegalStateException e = assertThrows(IllegalStateException.class, wb::createCellStyle);
assertEquals("The maximum number of cell styles was exceeded. " +
- "You can define up to 4000 styles in a .xls workbook", e.getMessage());
+ "You can define up to 4000 styles in a .xls workbook", e.getMessage());
+ assertEquals(MAX_STYLES, wb.getNumCellStyles());
}
- assertEquals(MAX_STYLES, wb.getNumCellStyles());
-
- wb.close();
}
@Test
@@ -831,10 +793,10 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
}
// Should throw exception about invalid POIFSFileSystem
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void emptyDirectoryNode() throws IOException {
try (POIFSFileSystem fs = new POIFSFileSystem()) {
- new HSSFWorkbook(fs).close();
+ assertThrows(IllegalArgumentException.class, () -> new HSSFWorkbook(fs).close());
}
}
@@ -856,9 +818,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
// Demonstrate bug 44525:
// Well... not quite, since isActive + isSelected were also added in the same bug fix
- assertFalse("Identified bug 44523 a", sheet1.isSelected());
+ assertFalse(sheet1.isSelected(), "Identified bug 44523 a");
wb.setActiveSheet(1);
- assertFalse("Identified bug 44523 b", sheet1.isActive());
+ assertFalse(sheet1.isActive(), "Identified bug 44523 b");
confirmActiveSelected(sheet1, false);
confirmActiveSelected(sheet2, true);
@@ -876,12 +838,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
public void names() throws IOException {
HSSFWorkbook wb=new HSSFWorkbook();
- try {
- wb.getNameAt(0);
- fail("Fails without any defined names");
- } catch (IllegalStateException e) {
- assertTrue(e.getMessage(), e.getMessage().contains("no defined names"));
- }
+ IllegalStateException ex1 = assertThrows(IllegalStateException.class, () -> wb.getNameAt(0));
+ assertTrue(ex1.getMessage().contains("no defined names"));
HSSFName name = wb.createName();
assertNotNull(name);
@@ -894,19 +852,11 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertEquals(0, wb.getNameIndex(name));
assertEquals(0, wb.getNameIndex("myname"));
- try {
- wb.getNameAt(5);
- fail("Fails without any defined names");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage(), e.getMessage().contains("outside the allowable range"));
- }
+ IllegalArgumentException ex2 = assertThrows(IllegalArgumentException.class, () -> wb.getNameAt(5));
+ assertTrue(ex2.getMessage().contains("outside the allowable range"));
- try {
- wb.getNameAt(-3);
- fail("Fails without any defined names");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage(), e.getMessage().contains("outside the allowable range"));
- }
+ IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> wb.getNameAt(-3));
+ assertTrue(ex.getMessage().contains("outside the allowable range"));
wb.close();
}
@@ -930,13 +880,6 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
wb.writeProtectWorkbook("mypassword", "myuser");
assertTrue(wb.isWriteProtected());
-// OutputStream os = new FileOutputStream("/tmp/protected.xls");
-// try {
-// wb.write(os);
-// } finally {
-// os.close();
-// }
-
wb.unwriteProtectWorkbook();
assertFalse(wb.isWriteProtected());
@@ -969,8 +912,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
int expected = wb.getWorkbook().getSize();
int written = wb.getWorkbook().serialize(0, new byte[expected*2]);
- assertEquals("Did not have the expected size when writing the workbook: written: " + written + ", but expected: " + expected,
- expected, written);
+ assertEquals(expected, written, "Did not have the expected size when writing the workbook");
HSSFWorkbook read = HSSFTestDataSamples.writeOutAndReadBack(wb);
assertSheetOrder(read, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
@@ -1012,8 +954,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
int expected = wb.getWorkbook().getSize();
int written = wb.getWorkbook().serialize(0, new byte[expected*2]);
- assertEquals("Did not have the expected size when writing the workbook: written: " + written + ", but expected: " + expected,
- expected, written);
+ assertEquals(expected, written, "Did not have the expected size when writing the workbook");
HSSFWorkbook read = HSSFTestDataSamples.writeOutAndReadBack(wb);
assertSheetOrder(read, "Invoice", "Deferred", "Received", "Digest");
@@ -1105,7 +1046,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
}
}
- assertTrue("Should find some images via Client or Child anchors, but did not find any at all", found);
+ assertTrue(found, "Should find some images via Client or Child anchors, but did not find any at all");
workbook.close();
}
@@ -1159,7 +1100,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
@Test
public void closeDoesNotModifyWorkbook() throws IOException {
final String filename = "SampleSS.xls";
- final File file = POIDataSamples.getSpreadSheetInstance().getFile(filename);
+ final File file = samples.getFile(filename);
Workbook wb;
// File via POIFileStream (java.nio)
@@ -1186,47 +1127,29 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
@Test
public void invalidInPlaceWrite() throws Exception {
- HSSFWorkbook wb;
-
// Can't work for new files
- wb = new HSSFWorkbook();
- try {
- wb.write();
- fail("Shouldn't work for new files");
- } catch (IllegalStateException e) {
- // expected here
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ assertThrows(IllegalStateException.class, wb::write, "Shouldn't work for new files");
}
- wb.close();
// Can't work for InputStream opened files
- wb = new HSSFWorkbook(
- POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls"));
- try {
- wb.write();
- fail("Shouldn't work for InputStream");
- } catch (IllegalStateException e) {
- // expected here
+ try (InputStream is = samples.openResourceAsStream("SampleSS.xls");
+ HSSFWorkbook wb = new HSSFWorkbook(is)) {
+ assertThrows(IllegalStateException.class, wb::write, "Shouldn't work for InputStream");
}
- wb.close();
// Can't work for Read-Only files
- POIFSFileSystem fs = new POIFSFileSystem(
- POIDataSamples.getSpreadSheetInstance().getFile("SampleSS.xls"), true);
- wb = new HSSFWorkbook(fs);
- try {
- wb.write();
- fail("Shouldn't work for Read Only");
- } catch (IllegalStateException e) {
- // expected here
+ try (POIFSFileSystem fs = new POIFSFileSystem(samples.getFile("SampleSS.xls"), true);
+ HSSFWorkbook wb = new HSSFWorkbook(fs)) {
+ assertThrows(IllegalStateException.class, wb::write, "Shouldn't work for Read Only");
}
- wb.close();
}
@Test
public void inPlaceWrite() throws Exception {
// Setup as a copy of a known-good file
final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
- try (InputStream inputStream = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls");
+ try (InputStream inputStream = samples.openResourceAsStream("SampleSS.xls");
FileOutputStream outputStream = new FileOutputStream(file)) {
IOUtils.copy(inputStream, outputStream);
}
@@ -1255,7 +1178,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
public void testWriteToNewFile() throws Exception {
// Open from a Stream
HSSFWorkbook wb = new HSSFWorkbook(
- POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls"));
+ samples.openResourceAsStream("SampleSS.xls"));
// Save to a new temp file
final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
@@ -1268,7 +1191,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
wb.close();
}
- @Ignore
+ @Disabled
@Test
@Override
public void createDrawing() throws Exception {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java
index 8d337e0888..67370a33da 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java
@@ -17,14 +17,15 @@
package org.apache.poi.hssf.usermodel;
-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.ss.formula.eval.ErrorEval;
@@ -38,14 +39,11 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-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;
-
-@RunWith(Parameterized.class)
+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;
+
public final class TestMatrixFormulasFromBinarySpreadsheet {
private static final POILogger LOG = POILogFactory.getLogger(TestMatrixFormulasFromBinarySpreadsheet.class);
@@ -65,7 +63,7 @@ public final class TestMatrixFormulasFromBinarySpreadsheet {
* then adding matrix size parameter would be useful and parsing would be based off that.
*/
- private static interface Navigator {
+ private interface Navigator {
/**
* Name of the test spreadsheet (found in the standard test data folder)
*/
@@ -98,20 +96,15 @@ public final class TestMatrixFormulasFromBinarySpreadsheet {
}
/* Parameters for test case */
- @Parameter(0)
- public String targetFunctionName;
- @Parameter(1)
- public int formulasRowIdx;
- @AfterClass
+ @AfterAll
public static void closeResource() throws Exception {
LocaleUtil.setUserLocale(userLocale);
workbook.close();
}
/* generating parameter instances */
- @Parameters(name="{0}")
- public static Collection<Object[]> data() throws Exception {
+ public static Stream<Arguments> data() throws Exception {
// 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
@@ -122,37 +115,32 @@ public final class TestMatrixFormulasFromBinarySpreadsheet {
sheet = workbook.getSheetAt(0);
evaluator = new HSSFFormulaEvaluator(workbook);
- List<Object[]> data = new ArrayList<Object[]>();
+ List<Arguments> data = new ArrayList<>();
- processFunctionGroup(data, Navigator.START_OPERATORS_ROW_INDEX, null);
+ processFunctionGroup(data);
- return data;
+ return data.stream();
}
- /**
- * @param startRowIndex row index in the spreadsheet where the first function/operator is found
- * @param testFocusFunctionName name of a single function/operator to test alone.
- * Typically pass <code>null</code> to test all functions
- */
- private static void processFunctionGroup(List<Object[]> data, int startRowIndex, String testFocusFunctionName) {
+ private static void processFunctionGroup(List<Arguments> data) {
+ int startRowIndex = Navigator.START_OPERATORS_ROW_INDEX;
for (int rowIndex = startRowIndex; true; rowIndex += Navigator.ROW_OFF_NEXT_OP) {
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) + "). Expected function name or '"
- + Navigator.END_OF_TESTS + "'", targetFunctionName);
+ + Navigator.END_OF_TESTS + "'");
if(targetFunctionName.equals(Navigator.END_OF_TESTS)) {
// found end of functions list
break;
}
- if(testFocusFunctionName == null || targetFunctionName.equalsIgnoreCase(testFocusFunctionName)) {
- data.add(new Object[]{targetFunctionName, rowIndex});
- }
+ data.add(Arguments.of(targetFunctionName, rowIndex));
}
}
- @Test
- public void processFunctionRow() {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void processFunctionRow(String targetFunctionName, int formulasRowIdx) {
int endColNum = Navigator.START_RESULT_COL_INDEX + Navigator.COL_OFF_EXPECTED_RESULT;
@@ -177,31 +165,32 @@ public final class TestMatrixFormulasFromBinarySpreadsheet {
String msg = String.format(Locale.ROOT, "Function '%s': Formula: %s @ %d:%d"
, targetFunctionName, c.getCellFormula(), rowNum, 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);
+ break;
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);
@@ -215,7 +204,6 @@ public final class TestMatrixFormulasFromBinarySpreadsheet {
*/
private static String getTargetFunctionName(Row r) {
if(r == null) {
-
LOG.log(POILogger.WARN,"Warning - given null row, can't figure out function name");
return null;
}
@@ -226,20 +214,10 @@ public final class TestMatrixFormulasFromBinarySpreadsheet {
"Warning - Row " + r.getRowNum() + " has no cell " + Navigator.START_OPERATORS_COL_INDEX + ", 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 "";
+ 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/hssf/usermodel/TestNonStandardWorkbookStreamNames.java b/src/testcases/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java
index 8d54e9b021..6a4a6dc885 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.usermodel;
-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;
import java.io.InputStream;
@@ -26,11 +26,11 @@ import java.io.InputStream;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.DirectoryNode;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for how HSSFWorkbook behaves with XLS files
- * with a WORKBOOK or BOOK directory entry (instead of
+ * with a WORKBOOK or BOOK directory entry (instead of
* the more usual, Workbook)
*/
public final class TestNonStandardWorkbookStreamNames {
@@ -54,7 +54,7 @@ public final class TestNonStandardWorkbookStreamNames {
// But not a Workbook one
assertFalse(root.hasEntry("Workbook"));
-
+
wb.close();
}
@@ -75,7 +75,7 @@ public final class TestNonStandardWorkbookStreamNames {
// But not a Workbook one and not a Summary one
assertFalse(root.hasEntry("Workbook"));
assertFalse(root.hasEntry(SummaryInformation.DEFAULT_STREAM_NAME));
-
+
wb.close();
}
@@ -93,9 +93,9 @@ public final class TestNonStandardWorkbookStreamNames {
// Check now it can be opened
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close();
-
+
DirectoryNode root = wb2.getDirectory();
-
+
// Check that we have the new entries
assertTrue(root.hasEntry("Workbook"));
assertFalse(root.hasEntry("BOOK"));
@@ -115,7 +115,7 @@ public final class TestNonStandardWorkbookStreamNames {
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
HSSFWorkbook wb = new HSSFWorkbook(is,true);
is.close();
-
+
// Check now it can be opened
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close();
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java b/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java
index cf1d1ba34e..340839bdde 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -34,38 +34,32 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
- *
+ *
*/
public final class TestOLE2Embeding {
@Test
public void testEmbeding() throws Exception {
// This used to break, until bug #43116 was fixed
- HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
-
- // Check we can get at the Escher layer still
- workbook.getAllPictures();
-
- workbook.close();
+ try (HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls")) {
+ // Check we can get at the Escher layer still
+ workbook.getAllPictures();
+ }
}
@Test
public void testEmbeddedObjects() throws Exception {
- HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
-
- List<HSSFObjectData> objects = workbook.getAllEmbeddedObjects();
- assertEquals("Wrong number of objects", 2, objects.size());
- assertEquals("Wrong name for first object", "MBD06CAB431",
- objects.get(0).getDirectory().getName());
- assertEquals("Wrong name for second object", "MBD06CAC85A",
- objects.get(1).getDirectory().getName());
-
- workbook.close();
+ try (HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls")) {
+ List<HSSFObjectData> objects = workbook.getAllEmbeddedObjects();
+ assertEquals(2, objects.size(), "Wrong number of objects");
+ assertEquals("MBD06CAB431", objects.get(0).getDirectory().getName(), "Wrong name for first object");
+ assertEquals("MBD06CAC85A", objects.get(1).getDirectory().getName(), "Wrong name for second object");
+ }
}
-
+
@Test
public void testReallyEmbedSomething() throws Exception {
HSSFWorkbook wb1 = new HSSFWorkbook();
@@ -81,7 +75,7 @@ public final class TestOLE2Embeding {
int imgPPT = wb1.addPicture(picturePPT, HSSFWorkbook.PICTURE_TYPE_JPEG);
int xlsIdx = wb1.addOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
int txtIdx = wb1.addOlePackage(getSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");
-
+
int rowoffset = 5;
int coloffset = 5;
@@ -89,21 +83,21 @@ public final class TestOLE2Embeding {
HSSFClientAnchor anchor = (HSSFClientAnchor)ch.createClientAnchor();
anchor.setAnchor((short)(2+coloffset), 1+rowoffset, 0, 0, (short)(3+coloffset), 5+rowoffset, 0, 0);
anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
-
+
patriarch.createObjectData(anchor, pptIdx, imgPPT);
anchor = (HSSFClientAnchor)ch.createClientAnchor();
anchor.setAnchor((short)(5+coloffset), 1+rowoffset, 0, 0, (short)(6+coloffset), 5+rowoffset, 0, 0);
anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
-
+
patriarch.createObjectData(anchor, xlsIdx, imgIdx);
-
+
anchor = (HSSFClientAnchor)ch.createClientAnchor();
anchor.setAnchor((short)(3+coloffset), 10+rowoffset, 0, 0, (short)(5+coloffset), 11+rowoffset, 0, 0);
anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
-
+
patriarch.createObjectData(anchor, txtIdx, imgIdx);
-
+
anchor = (HSSFClientAnchor)ch.createClientAnchor();
anchor.setAnchor((short)(1+coloffset), -2+rowoffset, 0, 0, (short)(7+coloffset), 14+rowoffset, 0, 0);
anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
@@ -117,10 +111,10 @@ public final class TestOLE2Embeding {
// wb.write(fos);
// fos.close();
// }
-
+
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
-
+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
HSSFObjectData od = wb2.getAllEmbeddedObjects().get(0);
Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
@@ -137,21 +131,21 @@ public final class TestOLE2Embeding {
od = wb2.getAllEmbeddedObjects().get(2);
ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
assertArrayEquals(ole10.getDataBuffer(), getSampleTXT());
-
+
xlsPoifs.close();
pptPoifs.close();
wb2.close();
}
-
+
static POIFSFileSystem getSamplePPT() throws IOException {
// scratchpad classes are not available, so we use something pre-cooked
InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("with_textbox.ppt");
POIFSFileSystem poifs = new POIFSFileSystem(is);
is.close();
-
+
return poifs;
}
-
+
static POIFSFileSystem getSampleXLS() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
@@ -163,8 +157,8 @@ public final class TestOLE2Embeding {
return new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
}
-
+
static byte[] getSampleTXT() {
return "All your base are belong to us".getBytes(LocaleUtil.CHARSET_1252);
- }
+ }
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java b/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
index 1060aaadc1..62b27c1800 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.usermodel;
-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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -29,7 +29,7 @@ import org.apache.poi.hpsf.*;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.HexDump;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Old-style setting of POIFS properties doesn't work with POI 3.0.2
@@ -103,7 +103,7 @@ public class TestPOIFSProperties {
private void checkFromByteArray(byte[] bytes) throws IOException, NoPropertySetStreamException, MarkUnsupportedException {
// on some environments in CI we see strange failures, let's verify that the size is exactly right
// this can be removed again after the problem is identified
- assertEquals("Had: " + HexDump.toHex(bytes), 5120, bytes.length);
+ assertEquals(5120, bytes.length, "Had: " + HexDump.toHex(bytes));
POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(bytes));
SummaryInformation summary2 = (SummaryInformation) PropertySetFactory.create(fs2.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestPatriarch.java b/src/testcases/org/apache/poi/hssf/usermodel/TestPatriarch.java
index 6ca0acda0f..30dfe80b5a 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestPatriarch.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestPatriarch.java
@@ -17,15 +17,15 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import org.apache.poi.ddf.EscherDgRecord;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.EscherAggregate;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestPatriarch {
@Test
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java b/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java
index b47443b1b8..f76cd0983b 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java
@@ -18,9 +18,9 @@
package org.apache.poi.hssf.usermodel;
import static org.apache.poi.poifs.storage.RawDataUtil.decompress;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+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 java.io.IOException;
@@ -29,7 +29,7 @@ import org.apache.poi.ddf.EscherPropertyTypes;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.ObjRecord;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestPolygon {
@Test
@@ -71,7 +71,7 @@ public class TestPolygon {
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
-
+
wb.close();
}
@@ -100,10 +100,10 @@ public class TestPolygon {
"</elements>" +
"</record>";
String actual = verticesProp1.toXml("").replaceAll("[\r\n\t]","");
-
+
assertEquals(verticesProp1.getNumberOfElementsInArray(), 5);
assertEquals(expected, actual);
-
+
polygon.setPoints(new int[]{1,2,3}, new int[] {4,5,6});
assertArrayEquals(polygon.getXPoints(), new int[]{1, 2, 3});
assertArrayEquals(polygon.getYPoints(), new int[]{4, 5, 6});
@@ -121,10 +121,10 @@ public class TestPolygon {
"<item>AQAEAA==</item>" +
"</elements></record>";
actual = verticesProp1.toXml("").replaceAll("[\r\n\t]","");
-
+
assertEquals(verticesProp1.getNumberOfElementsInArray(), 4);
assertEquals(expected, actual);
-
+
wb.close();
}
@@ -173,7 +173,7 @@ public class TestPolygon {
assertArrayEquals(polygon.getYPoints(), new int[]{41, 51, 61});
assertEquals(polygon.getDrawAreaHeight(), 1011);
assertEquals(polygon.getDrawAreaWidth(), 1021);
-
+
wb3.close();
}
@@ -227,7 +227,7 @@ public class TestPolygon {
assertArrayEquals(polygon2.getYPoints(), new int[]{24,25,26});
assertEquals(polygon2.getDrawAreaHeight(), 204);
assertEquals(polygon2.getDrawAreaWidth(), 203);
-
+
wb3.close();
}
@@ -243,7 +243,7 @@ public class TestPolygon {
assertEquals(polygon.getDrawAreaWidth(), 3686175);
assertArrayEquals(polygon.getXPoints(), new int[]{0, 0, 31479, 16159, 19676, 20502});
assertArrayEquals(polygon.getYPoints(), new int[]{0, 0, 36, 56, 34, 18});
-
+
wb.close();
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java b/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java
index e7fe40c02f..7f0cc0c24f 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.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;
@@ -31,7 +31,7 @@ import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* @author Glen Stampoultzis (glens at apache.org)
@@ -61,7 +61,7 @@ public final class TestReadWriteChart {
assertTrue(records.get(0) instanceof BOFRecord);
assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
-
+
workbook.close();
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java
index 1977ef0caa..f94b63ce2e 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java
@@ -18,14 +18,14 @@
package org.apache.poi.hssf.usermodel;
import static org.apache.poi.hssf.HSSFTestDataSamples.writeOutAndReadBack;
-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;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test row styling functionality
@@ -58,8 +58,8 @@ public final class TestRowStyle {
try (HSSFWorkbook wb2 = writeOutAndReadBack(wb)) {
SanityChecker sanityChecker = new SanityChecker();
sanityChecker.checkHSSFWorkbook(wb2);
- assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
- assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
+ assertEquals(99, s.getLastRowNum(), "LAST ROW == 99");
+ assertEquals(0, s.getFirstRowNum(), "FIRST ROW == 0");
}
}
}
@@ -90,8 +90,8 @@ public final class TestRowStyle {
SanityChecker sanityChecker = new SanityChecker();
sanityChecker.checkHSSFWorkbook(wb2);
- assertEquals("LAST ROW ", 1, s.getLastRowNum());
- assertEquals("FIRST ROW ", 0, s.getFirstRowNum());
+ assertEquals(1, s.getLastRowNum(), "LAST ROW");
+ assertEquals(0, s.getFirstRowNum(), "FIRST ROW");
}
}
}
@@ -109,7 +109,6 @@ public final class TestRowStyle {
public void testWriteSheetStyle() throws IOException {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet s = wb.createSheet();
- HSSFRow r = null;
HSSFFont fnt = wb.createFont();
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
@@ -126,7 +125,7 @@ public final class TestRowStyle {
cs2.setFillPattern(FillPatternType.BRICKS);
cs2.setFont(fnt);
for (int rownum = 0; rownum < 100; rownum++) {
- r = s.createRow(rownum);
+ HSSFRow r = s.createRow(rownum);
r.setRowStyle(cs);
r.createCell(0);
@@ -140,34 +139,34 @@ public final class TestRowStyle {
try (HSSFWorkbook wb2 = writeOutAndReadBack(wb)) {
SanityChecker sanityChecker = new SanityChecker();
sanityChecker.checkHSSFWorkbook(wb2);
- assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
- assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
+ assertEquals(99, s.getLastRowNum(), "LAST ROW == 99");
+ assertEquals(0, s.getFirstRowNum(), "FIRST ROW == 0");
s = wb2.getSheetAt(0);
- assertNotNull("Sheet is not null", s);
+ assertNotNull(s, "Sheet is not null");
for (int rownum = 0; rownum < 100; rownum++) {
- r = s.getRow(rownum);
- assertNotNull("Row is not null", r);
+ HSSFRow r = s.getRow(rownum);
+ assertNotNull(r, "Row is not null");
cs = r.getRowStyle();
assertNotNull(cs);
- assertEquals("Bottom Border Style for row:", BorderStyle.THIN, cs.getBorderBottom());
- assertEquals("Left Border Style for row:", BorderStyle.THIN, cs.getBorderLeft());
- assertEquals("Right Border Style for row:", BorderStyle.THIN, cs.getBorderRight());
- assertEquals("Top Border Style for row:", BorderStyle.THIN, cs.getBorderTop());
- assertEquals("FillForegroundColor for row:", 0xA, cs.getFillForegroundColor());
- assertEquals("FillPattern for row:", FillPatternType.BRICKS, cs.getFillPattern());
+ assertEquals(BorderStyle.THIN, cs.getBorderBottom(), "Bottom Border Style for row:");
+ assertEquals(BorderStyle.THIN, cs.getBorderLeft(), "Left Border Style for row:");
+ assertEquals(BorderStyle.THIN, cs.getBorderRight(), "Right Border Style for row:");
+ assertEquals(BorderStyle.THIN, cs.getBorderTop(), "Top Border Style for row:");
+ assertEquals(0xA, cs.getFillForegroundColor(), "FillForegroundColor for row:");
+ assertEquals(FillPatternType.BRICKS, cs.getFillPattern(), "FillPattern for row:");
rownum++;
if (rownum >= 100) break; // I feel too lazy to check if this isreqd :-/
r = s.getRow(rownum);
- assertNotNull("Row is not null", r);
+ assertNotNull(r, "Row is not null");
cs2 = r.getRowStyle();
assertNotNull(cs2);
- assertEquals("FillForegroundColor for row: ", cs2.getFillForegroundColor(), (short) 0x0);
- assertEquals("FillPattern for row: ", cs2.getFillPattern(), FillPatternType.BRICKS);
+ assertEquals(cs2.getFillForegroundColor(), (short) 0x0, "FillForegroundColor for row:");
+ assertEquals(cs2.getFillPattern(), FillPatternType.BRICKS, "FillPattern for row:");
}
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestSanityChecker.java b/src/testcases/org/apache/poi/hssf/usermodel/TestSanityChecker.java
index 0293348636..cd020fe6d1 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestSanityChecker.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestSanityChecker.java
@@ -17,7 +17,8 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList;
import java.util.Arrays;
@@ -30,7 +31,7 @@ import org.apache.poi.hssf.record.InterfaceHdrRecord;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.usermodel.SanityChecker.CheckRecord;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* A Test case for a test utility class.<br>
@@ -43,7 +44,7 @@ public final class TestSanityChecker {
private static BoundSheetRecord createBoundSheetRec() {
return new BoundSheetRecord("Sheet1");
}
-
+
@Test
public void testCheckRecordOrder() {
final SanityChecker c = new SanityChecker();
@@ -119,20 +120,10 @@ public final class TestSanityChecker {
EOFRecord.instance,
});
}
+
private static void confirmBadRecordOrder(final SanityChecker.CheckRecord[] check, Record[] recs) {
final SanityChecker c = new SanityChecker();
final List<org.apache.poi.hssf.record.Record> records = Arrays.asList(recs);
- try {
- new Runnable() {
- @Override
- public void run() {
- c.checkRecordOrder(records, check);
- }
- }.run();
- } catch (AssertionError pass) {
- // expected during normal test
- return;
- }
- fail("Did not get failure exception as expected");
+ assertThrows(AssertionError.class, () -> c.checkRecordOrder(records, check));
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java b/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java
index 46ca6b9560..c927b9273f 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
-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.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
@@ -28,7 +28,7 @@ import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherSpgrRecord;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.EscherAggregate;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestShapeGroup {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java
index f9d172310b..0164a69189 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java
@@ -21,12 +21,13 @@ import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.ss.usermodel.BaseTestSheetHiding;
import org.apache.poi.ss.usermodel.SheetVisibility;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-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 static org.junit.jupiter.api.Assertions.fail;
public final class TestSheetHiding extends BaseTestSheetHiding {
public TestSheetHiding() {
@@ -60,11 +61,6 @@ public final class TestSheetHiding extends BaseTestSheetHiding {
assertEquals(SheetVisibility.HIDDEN, intWb.getSheetVisibility(1));
// check sheet-index with index out of bounds => throws exception
- try {
- wb.setSheetVisibility(10, SheetVisibility.HIDDEN);
- fail("Should catch exception here");
- } catch (RuntimeException e) {
- // expected here
- }
+ assertThrows(RuntimeException.class, () -> wb.setSheetVisibility(10, SheetVisibility.HIDDEN));
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestText.java b/src/testcases/org/apache/poi/hssf/usermodel/TestText.java
index bb16cf9879..751f7f5fb3 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestText.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestText.java
@@ -18,15 +18,15 @@
package org.apache.poi.hssf.usermodel;
import static org.apache.poi.poifs.storage.RawDataUtil.decompress;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.hssf.record.TextObjectRecord;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* @author Evgeniy Berlog
@@ -75,7 +75,7 @@ public class TestText {
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
-
+
TextObjectRecord tor = textbox.getTextObjectRecord();
expected = decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA==");
@@ -83,7 +83,7 @@ public class TestText {
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
-
+
wb.close();
}
@@ -118,7 +118,7 @@ public class TestText {
assertEquals(((HSSFTextbox) patriarch.getChildren().get(0)).getString().getString(), "just for test");
assertEquals(((HSSFTextbox) patriarch.getChildren().get(1)).getString().getString(), "just for test2");
assertEquals(((HSSFTextbox) patriarch.getChildren().get(2)).getString().getString(), "text3");
-
+
wb3.close();
}
@@ -191,7 +191,7 @@ public class TestText {
assertEquals(textbox.getMarginLeft(), 81);
assertEquals(textbox.getMarginRight(), 91);
assertEquals(textbox.getMarginTop(), 101);
-
+
wb3.close();
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java
index 40afff2131..828e8b6087 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.usermodel;
-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;
@@ -29,7 +29,7 @@ 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;
/**
* @author aviks
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java
index 6535246725..d4e19943b5 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.usermodel;
-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;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestUnicodeWorkbook {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
index 79d9553eca..678dd9e976 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
@@ -23,13 +23,12 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.BackupRecord;
import org.apache.poi.hssf.record.LabelSSTRecord;
-import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Class to test Workbook functionality
@@ -62,23 +61,22 @@ public final class TestWorkbook {
*/
@Test
public void testWriteSheetSimple() throws IOException {
- HSSFWorkbook wb1 = new HSSFWorkbook();
- HSSFSheet s = wb1.createSheet();
+ try (HSSFWorkbook wb1 = new HSSFWorkbook()) {
+ HSSFSheet s = wb1.createSheet();
- populateSheet(s);
+ populateSheet(s);
- HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
-
- sanityChecker.checkHSSFWorkbook(wb1);
- assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
- assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
+ try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
+ sanityChecker.checkHSSFWorkbook(wb1);
+ assertEquals(99, s.getLastRowNum(), "LAST ROW == 99");
+ assertEquals(0, s.getFirstRowNum(), "FIRST ROW == 0");
- sanityChecker.checkHSSFWorkbook(wb2);
- s = wb2.getSheetAt(0);
- assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
- assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
- wb2.close();
- wb1.close();
+ sanityChecker.checkHSSFWorkbook(wb2);
+ s = wb2.getSheetAt(0);
+ assertEquals(99, s.getLastRowNum(), "LAST ROW == 99");
+ assertEquals(0, s.getFirstRowNum(), "FIRST ROW == 0");
+ }
+ }
}
/**
@@ -107,16 +105,16 @@ public final class TestWorkbook {
}
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
-
+
sanityChecker.checkHSSFWorkbook(wb1);
- assertEquals("LAST ROW == 74", 74, s.getLastRowNum());
- assertEquals("FIRST ROW == 25", 25, s.getFirstRowNum());
+ assertEquals(74, s.getLastRowNum(), "LAST ROW == 74");
+ assertEquals(25, s.getFirstRowNum(), "FIRST ROW == 25");
sanityChecker.checkHSSFWorkbook(wb2);
s = wb2.getSheetAt(0);
- assertEquals("LAST ROW == 74", 74, s.getLastRowNum());
- assertEquals("FIRST ROW == 25", 25, s.getFirstRowNum());
-
+ assertEquals(74, s.getLastRowNum(), "LAST ROW == 74");
+ assertEquals(25, s.getFirstRowNum(), "FIRST ROW == 25");
+
wb2.close();
wb1.close();
}
@@ -155,7 +153,7 @@ public final class TestWorkbook {
assertEquals(1.25,cell.getNumericCellValue(), 1e-10);
assertEquals(format.getFormat(cell.getCellStyle().getDataFormat()), "0.0");
-
+
wb.close();
}
@@ -214,7 +212,7 @@ public final class TestWorkbook {
assertEquals(LAST_NAME_KEY, sheet.getRow(3).getCell(2).getRichStringCellValue().getString());
assertEquals(FIRST_NAME_KEY, sheet.getRow(4).getCell(2).getRichStringCellValue().getString());
assertEquals(SSN_KEY, sheet.getRow(5).getCell(2).getRichStringCellValue().getString());
-
+
wb.close();
}
@@ -241,7 +239,7 @@ public final class TestWorkbook {
sheet = wb2.getSheetAt(0);
cell = sheet.getRow(0).getCell(0);
assertEquals(REPLACED, cell.getRichStringCellValue().getString());
-
+
wb2.close();
wb1.close();
}
@@ -279,7 +277,7 @@ public final class TestWorkbook {
assertEquals(REPLACED, cell.getRichStringCellValue().getString());
cell = sheet.getRow(1).getCell(1);
assertEquals(DO_NOT_REPLACE, cell.getRichStringCellValue().getString());
-
+
wb2.close();
wb1.close();
}
@@ -312,7 +310,7 @@ public final class TestWorkbook {
HSSFCell cell = sheet.getRow(k).getCell(0);
assertEquals(REPLACED, cell.getRichStringCellValue().getString());
}
-
+
wb2.close();
wb1.close();
}
@@ -347,7 +345,7 @@ public final class TestWorkbook {
assertEquals(LAST_NAME_VALUE, sheet.getRow(3).getCell(2).getRichStringCellValue().getString());
assertEquals(FIRST_NAME_VALUE, sheet.getRow(4).getCell(2).getRichStringCellValue().getString());
assertEquals(SSN_VALUE, sheet.getRow(5).getCell(2).getRichStringCellValue().getString());
-
+
wb2.close();
wb1.close();
}
@@ -366,7 +364,7 @@ public final class TestWorkbook {
HSSFCell c = s.getRow(0).getCell(0);
assertEquals(CellType.NUMERIC, c.getCellType());
-
+
wb.close();
}
@@ -442,7 +440,7 @@ public final class TestWorkbook {
wb.setBackupFlag(false);
assertEquals(0, record.getBackup());
assertFalse(wb.getBackupFlag());
-
+
wb.close();
}
@@ -482,7 +480,7 @@ public final class TestWorkbook {
RecordCounter rc = new RecordCounter();
sheet.getSheet().visitContainedRecords(rc, 0);
assertEquals(1, rc.getCount());
-
+
workbook.close();
}
@@ -503,7 +501,7 @@ public final class TestWorkbook {
cell.setCellValue(i);
}
sanityChecker.checkHSSFWorkbook(wb1);
- assertEquals("LAST ROW == 32770", 32770, sheet.getLastRowNum());
+ assertEquals(32770, sheet.getLastRowNum(), "LAST ROW == 32770");
cell = sheet.getRow(32770).getCell(0);
double lastVal = cell.getNumericCellValue();
@@ -511,9 +509,9 @@ public final class TestWorkbook {
HSSFSheet s = wb2.getSheetAt(0);
row = s.getRow(32770);
cell = row.getCell(0);
- assertEquals("Value from last row == 32770", lastVal, cell.getNumericCellValue(), 0);
- assertEquals("LAST ROW == 32770", 32770, s.getLastRowNum());
-
+ assertEquals(lastVal, cell.getNumericCellValue(), 0, "Value from last row == 32770");
+ assertEquals(32770, s.getLastRowNum(), "LAST ROW == 32770");
+
wb2.close();
wb1.close();
}
@@ -539,7 +537,7 @@ public final class TestWorkbook {
sheet = wb2.getSheetAt(0);
assertEquals("A:B", sheet.getRepeatingColumns().formatAsString());
assertEquals("1:1", sheet.getRepeatingRows().formatAsString());
-
+
wb2.close();
wb1.close();
}
@@ -558,25 +556,14 @@ public final class TestWorkbook {
HSSFCell cell = row.createCell(1);
cell.setCellValue(new HSSFRichTextString("hi"));
CellRangeAddress cra = new CellRangeAddress(-1, 1, -1, 1);
- try {
- sheet.setRepeatingColumns(cra);
- fail("invalid start index is ignored");
- } catch (IllegalArgumentException e) {
- // expected here
- }
-
- try {
- sheet.setRepeatingRows(cra);
- fail("invalid start index is ignored");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> sheet.setRepeatingColumns(cra), "invalid start index is ignored");
+ assertThrows(IllegalArgumentException.class, () -> sheet.setRepeatingRows(cra), "invalid start index is ignored");
sheet.setRepeatingColumns(null);
sheet.setRepeatingRows(null);
-
+
HSSFTestDataSamples.writeOutAndReadBack(workbook).close();
-
+
workbook.close();
}
@@ -590,12 +577,12 @@ public final class TestWorkbook {
sheet1.createRow(0).createCell((short) 0).setCellValue("val1");
sheet2.createRow(0).createCell((short) 0).setCellValue("val2");
sheet3.createRow(0).createCell((short) 0).setCellValue("val3");
-
+
Name namedCell1 = wb1.createName();
namedCell1.setNameName("name1");
String reference1 = "sheet1!$A$1";
namedCell1.setRefersToFormula(reference1);
-
+
Name namedCell2= wb1.createName();
namedCell2.setNameName("name2");
String reference2 = "sheet2!$A$1";
@@ -608,23 +595,29 @@ public final class TestWorkbook {
Workbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
-
+
Name nameCell = wb2.getName("name1");
+ assertNotNull(nameCell);
assertEquals("sheet1!$A$1", nameCell.getRefersToFormula());
nameCell = wb2.getName("name2");
+ assertNotNull(nameCell);
assertEquals("sheet2!$A$1", nameCell.getRefersToFormula());
nameCell = wb2.getName("name3");
+ assertNotNull(nameCell);
assertEquals("sheet3!$A$1", nameCell.getRefersToFormula());
-
+
wb2.removeSheetAt(wb2.getSheetIndex("sheet1"));
-
+
nameCell = wb2.getName("name1");
+ assertNotNull(nameCell);
assertEquals("#REF!$A$1", nameCell.getRefersToFormula());
nameCell = wb2.getName("name2");
+ assertNotNull(nameCell);
assertEquals("sheet2!$A$1", nameCell.getRefersToFormula());
nameCell = wb2.getName("name3");
+ assertNotNull(nameCell);
assertEquals("sheet3!$A$1", nameCell.getRefersToFormula());
-
+
wb2.close();
}
}
diff --git a/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java b/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java
deleted file mode 100644
index 7e71fb2de1..0000000000
--- a/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java
+++ /dev/null
@@ -1,34 +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.hssf.util;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for org.apache.poi.hssf.util.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestAreaReference.class,
- TestCellReference.class,
- TestHSSFColor.class,
- TestRKUtil.class
-})
-public class AllHSSFUtilTests {
-}
diff --git a/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java b/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java
index fddd1e7603..c3c68a3dca 100644
--- a/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java
+++ b/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java
@@ -17,12 +17,12 @@
package org.apache.poi.hssf.util;
-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.InputStream;
@@ -44,27 +44,27 @@ import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.UnionPtg;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestAreaReference {
@Test
public void testAreaRef1() {
AreaReference ar = new AreaReference("$A$1:$B$2", SpreadsheetVersion.EXCEL97);
- assertFalse("Two cells expected", ar.isSingleCell());
+ assertFalse(ar.isSingleCell(), "Two cells expected");
CellReference cf = ar.getFirstCell();
- assertEquals("row is 4", 0, cf.getRow());
- assertEquals("col is 1", 0, cf.getCol());
- assertTrue("row is abs", cf.isRowAbsolute());
- assertTrue("col is abs", cf.isColAbsolute());
- assertEquals("string is $A$1", "$A$1", cf.formatAsString());
+ assertEquals(0, cf.getRow(), "row is 4");
+ assertEquals(0, cf.getCol(), "col is 1");
+ assertTrue(cf.isRowAbsolute(), "row is abs");
+ assertTrue(cf.isColAbsolute(), "col is abs");
+ assertEquals("$A$1", cf.formatAsString(), "string is $A$1");
cf = ar.getLastCell();
- assertEquals("row is 4", 1, cf.getRow());
- assertEquals("col is 1", 1, cf.getCol());
- assertTrue("row is abs", cf.isRowAbsolute());
- assertTrue("col is abs", cf.isColAbsolute());
- assertEquals("string is $B$2", "$B$2", cf.formatAsString());
+ assertEquals(1, cf.getRow(), "row is 4");
+ assertEquals(1, cf.getCol(), "col is 1");
+ assertTrue(cf.isRowAbsolute(), "row is abs");
+ assertTrue(cf.isColAbsolute(), "col is abs");
+ assertEquals("$B$2", cf.formatAsString(), "string is $B$2");
CellReference[] refs = ar.getAllReferencedCells();
assertEquals(4, refs.length);
@@ -136,24 +136,9 @@ public final class TestAreaReference {
// Check we can only create contiguous entries
new AreaReference(refSimple, SpreadsheetVersion.EXCEL97);
new AreaReference(ref2D, SpreadsheetVersion.EXCEL97);
- try {
- new AreaReference(refDCSimple, SpreadsheetVersion.EXCEL97);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
- try {
- new AreaReference(refDC2D, SpreadsheetVersion.EXCEL97);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
- try {
- new AreaReference(refDC3D, SpreadsheetVersion.EXCEL97);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
+ assertThrows(IllegalArgumentException.class, () -> new AreaReference(refDCSimple, SpreadsheetVersion.EXCEL97));
+ assertThrows(IllegalArgumentException.class, () -> new AreaReference(refDC2D, SpreadsheetVersion.EXCEL97));
+ assertThrows(IllegalArgumentException.class, () -> new AreaReference(refDC3D, SpreadsheetVersion.EXCEL97));
// Test that we split as expected
AreaReference[] refs;
@@ -251,6 +236,7 @@ public final class TestAreaReference {
HSSFName aNamedCell = wb.getName("test");
// Should have 2 references
+ assertNotNull(aNamedCell);
String formulaRefs = aNamedCell.getRefersToFormula();
assertNotNull(formulaRefs);
assertEquals(ref, formulaRefs);
diff --git a/src/testcases/org/apache/poi/hssf/util/TestCellReference.java b/src/testcases/org/apache/poi/hssf/util/TestCellReference.java
index c7a7e10aa5..ab23476c1d 100644
--- a/src/testcases/org/apache/poi/hssf/util/TestCellReference.java
+++ b/src/testcases/org/apache/poi/hssf/util/TestCellReference.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.util;
-import org.junit.Test;
-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.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.CellReference.NameType;
-import org.apache.poi.ss.SpreadsheetVersion;
+import org.junit.jupiter.api.Test;
/**
* Tests for the HSSF and SS versions of CellReference.
@@ -41,7 +41,7 @@ public final class TestCellReference {
assertEquals(701, CellReference.convertColStringToIndex("ZZ"));
assertEquals(702, CellReference.convertColStringToIndex("AAA"));
assertEquals(18277, CellReference.convertColStringToIndex("ZZZ"));
-
+
assertEquals("A", CellReference.convertNumToColString(0));
assertEquals("B", CellReference.convertNumToColString(1));
assertEquals("Z", CellReference.convertNumToColString(25));
@@ -49,19 +49,15 @@ public final class TestCellReference {
assertEquals("ZZ", CellReference.convertNumToColString(701));
assertEquals("AAA", CellReference.convertNumToColString(702));
assertEquals("ZZZ", CellReference.convertNumToColString(18277));
-
+
// Absolute references are allowed for the string ones
assertEquals(0, CellReference.convertColStringToIndex("$A"));
assertEquals(25, CellReference.convertColStringToIndex("$Z"));
assertEquals(26, CellReference.convertColStringToIndex("$AA"));
-
+
// $ sign isn't allowed elsewhere though
- try {
- CellReference.convertColStringToIndex("A$B$");
- fail("Column reference is invalid and shouldn't be accepted");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> CellReference.convertColStringToIndex("A$B$"),
+ "Column reference is invalid and shouldn't be accepted");
}
@Test
@@ -129,11 +125,11 @@ public final class TestCellReference {
int expCol, boolean expIsRowAbs, boolean expIsColAbs, String expText) {
assertEquals(expSheetName, cf.getSheetName());
- assertEquals("row index is wrong", expRow, cf.getRow());
- assertEquals("col index is wrong", expCol, cf.getCol());
- assertEquals("isRowAbsolute is wrong", expIsRowAbs, cf.isRowAbsolute());
- assertEquals("isColAbsolute is wrong", expIsColAbs, cf.isColAbsolute());
- assertEquals("text is wrong", expText, cf.formatAsString());
+ assertEquals(expRow, cf.getRow(), "row index is wrong");
+ assertEquals(expCol, cf.getCol(), "col index is wrong");
+ assertEquals(expIsRowAbs, cf.isRowAbsolute(), "isRowAbsolute is wrong");
+ assertEquals(expIsColAbs, cf.isColAbsolute(), "isColAbsolute is wrong");
+ assertEquals(expText, cf.formatAsString(), "text is wrong");
}
@Test
diff --git a/src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java b/src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java
index eb484a775e..ac636c8f5c 100644
--- a/src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java
+++ b/src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.util;
-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.Map;
import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestHSSFColor {
@Test
@@ -31,7 +31,7 @@ public final class TestHSSFColor {
assertTrue(HSSFColorPredefined.YELLOW.getIndex() > 0);
assertTrue(HSSFColorPredefined.YELLOW.getIndex2() > 0);
}
-
+
@Test
public void testContents() {
short[] triplet = HSSFColorPredefined.YELLOW.getTriplet();
@@ -39,14 +39,14 @@ public final class TestHSSFColor {
assertEquals(255, triplet[0]);
assertEquals(255, triplet[1]);
assertEquals(0, triplet[2]);
-
+
assertEquals("FFFF:FFFF:0", HSSFColorPredefined.YELLOW.getHexString());
}
-
+
@Test
public void testTripletHash() {
Map<String, HSSFColor> triplets = HSSFColor.getTripletHash();
-
+
assertEquals(
HSSFColorPredefined.MAROON.getColor(),
triplets.get(HSSFColorPredefined.MAROON.getHexString())
diff --git a/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java b/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java
index 09fcaa40cf..28e1964ff7 100644
--- a/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java
+++ b/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.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 the {@link RKUtil} class.
diff --git a/src/testcases/org/apache/poi/poifs/AllPOIFSTests.java b/src/testcases/org/apache/poi/poifs/AllPOIFSTests.java
deleted file mode 100644
index a50bfe6f43..0000000000
--- a/src/testcases/org/apache/poi/poifs/AllPOIFSTests.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.poifs;
-
-import org.apache.poi.poifs.eventfilesystem.TestPOIFSReaderRegistry;
-import org.apache.poi.poifs.filesystem.AllPOIFSFileSystemTests;
-import org.apache.poi.poifs.macros.TestVBAMacroReader;
-import org.apache.poi.poifs.nio.TestDataSource;
-import org.apache.poi.poifs.property.AllPOIFSPropertyTests;
-import org.apache.poi.poifs.storage.AllPOIFSStorageTests;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test suite for all sub-packages of org.apache.poi.poifs
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestPOIFSReaderRegistry.class
- , TestDataSource.class
- , TestVBAMacroReader.class
- , AllPOIFSFileSystemTests.class
- , AllPOIFSPropertyTests.class
- , AllPOIFSStorageTests.class
-})
-public final class AllPOIFSTests {
-}
diff --git a/src/testcases/org/apache/poi/poifs/crypt/AllEncryptionTests.java b/src/testcases/org/apache/poi/poifs/crypt/AllEncryptionTests.java
deleted file mode 100644
index 8bd67db91b..0000000000
--- a/src/testcases/org/apache/poi/poifs/crypt/AllEncryptionTests.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.poifs.crypt;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for package <tt>org.apache.poi.poifs.crypt</tt>.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestBiff8DecryptingStream.class,
- TestCipherAlgorithm.class,
- TestXorEncryption.class
-})
-public final class AllEncryptionTests {
-}
diff --git a/src/testcases/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java b/src/testcases/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java
index d57cbdda41..1ccdb3083a 100644
--- a/src/testcases/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java
+++ b/src/testcases/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java
@@ -17,9 +17,9 @@
package org.apache.poi.poifs.crypt;
-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.InputStream;
@@ -27,7 +27,7 @@ import javax.crypto.spec.SecretKeySpec;
import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream;
import org.apache.poi.util.HexRead;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link Biff8DecryptingStream}
@@ -118,7 +118,7 @@ public final class TestBiff8DecryptingStream {
byte[] expData = HexRead.readFromString(expHexData);
byte[] actData = new byte[expData.length];
_bds.readFully(actData);
- assertArrayEquals("Data mismatch", expData, actData);
+ assertArrayEquals(expData, actData, "Data mismatch");
}
}
@@ -180,9 +180,9 @@ public final class TestBiff8DecryptingStream {
Biff8DecryptingStream bds = st.getBDS();
int hval = bds.readDataSize(); // unencrypted
int nextInt = bds.readInt();
- assertNotEquals("Indentified bug in key alignment after call to readHeaderUShort()",0x8F534029, nextInt);
+ assertNotEquals(0x8F534029, nextInt, "Indentified bug in key alignment after call to readHeaderUShort()");
assertEquals(0x16885243, nextInt);
- assertNotEquals("readHeaderUShort() incorrectly decrypted result", 0x283E, hval);
+ assertNotEquals(0x283E, hval, "readHeaderUShort() incorrectly decrypted result");
assertEquals(0x504F, hval);
// confirm next key change
diff --git a/src/testcases/org/apache/poi/poifs/crypt/TestCipherAlgorithm.java b/src/testcases/org/apache/poi/poifs/crypt/TestCipherAlgorithm.java
index 68d6ab2901..998eacbd0f 100644
--- a/src/testcases/org/apache/poi/poifs/crypt/TestCipherAlgorithm.java
+++ b/src/testcases/org/apache/poi/poifs/crypt/TestCipherAlgorithm.java
@@ -17,16 +17,17 @@
package org.apache.poi.poifs.crypt;
-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.EncryptedDocumentException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestCipherAlgorithm {
@Test
public void validInputs() {
assertEquals(128, CipherAlgorithm.aes128.defaultKeySize);
-
+
for(CipherAlgorithm alg : CipherAlgorithm.values()) {
assertEquals(alg, CipherAlgorithm.valueOf(alg.toString()));
}
@@ -34,19 +35,11 @@ public class TestCipherAlgorithm {
assertEquals(CipherAlgorithm.aes128, CipherAlgorithm.fromEcmaId(0x660E));
assertEquals(CipherAlgorithm.aes192, CipherAlgorithm.fromXmlId("AES", 192));
}
-
- @Test(expected=EncryptedDocumentException.class)
- public void invalidEcmaId() {
- CipherAlgorithm.fromEcmaId(0);
- }
-
- @Test(expected=EncryptedDocumentException.class)
- public void invalidXmlId1() {
- CipherAlgorithm.fromXmlId("AES", 1);
- }
-
- @Test(expected=EncryptedDocumentException.class)
- public void invalidXmlId2() {
- CipherAlgorithm.fromXmlId("RC1", 0x40);
+
+ @Test
+ public void invalidInputs() {
+ assertThrows(EncryptedDocumentException.class, () -> CipherAlgorithm.fromEcmaId(0));
+ assertThrows(EncryptedDocumentException.class, () -> CipherAlgorithm.fromXmlId("AES", 1));
+ assertThrows(EncryptedDocumentException.class, () -> CipherAlgorithm.fromXmlId("RC1", 0x40));
}
}
diff --git a/src/testcases/org/apache/poi/poifs/crypt/TestXorEncryption.java b/src/testcases/org/apache/poi/poifs/crypt/TestXorEncryption.java
index 91894113bd..6a2d8d8709 100644
--- a/src/testcases/org/apache/poi/poifs/crypt/TestXorEncryption.java
+++ b/src/testcases/org/apache/poi/poifs/crypt/TestXorEncryption.java
@@ -19,7 +19,7 @@ package org.apache.poi.poifs.crypt;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -33,8 +33,8 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.HexRead;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
public class TestXorEncryption {
@@ -73,7 +73,7 @@ public class TestXorEncryption {
}
@Test
- @Ignore("currently not supported")
+ @Disabled("currently not supported")
public void encrypt() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
diff --git a/src/testcases/org/apache/poi/poifs/crypt/binaryrc4/TestBinaryRC4.java b/src/testcases/org/apache/poi/poifs/crypt/binaryrc4/TestBinaryRC4.java
index b1155c3f57..373b9af4fc 100644
--- a/src/testcases/org/apache/poi/poifs/crypt/binaryrc4/TestBinaryRC4.java
+++ b/src/testcases/org/apache/poi/poifs/crypt/binaryrc4/TestBinaryRC4.java
@@ -18,9 +18,8 @@
package org.apache.poi.poifs.crypt.binaryrc4;
import static org.apache.poi.util.HexRead.readFromString;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.security.GeneralSecurityException;
@@ -29,20 +28,20 @@ import javax.crypto.SecretKey;
import org.apache.poi.poifs.crypt.Decryptor;
import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.poifs.crypt.EncryptionMode;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestBinaryRC4 {
@Test
- public void createKeyDigest() throws GeneralSecurityException {
+ public void createKeyDigest() {
byte[] docIdData = readFromString("17 F6 D1 6B 09 B1 5F 7B 4C 9D 03 B4 81 B5 B4 4A");
byte[] expResult = readFromString("C2 D9 56 B2 6B");
-
+
EncryptionInfo ei = new EncryptionInfo(EncryptionMode.binaryRC4);
BinaryRC4EncryptionVerifier ver = (BinaryRC4EncryptionVerifier)ei.getVerifier();
ver.setSalt(docIdData);
SecretKey sk = BinaryRC4Decryptor.generateSecretKey("MoneyForNothing", ver);
-
- assertArrayEquals("keyDigest mismatch", expResult, sk.getEncoded());
+
+ assertArrayEquals(expResult, sk.getEncoded(), "keyDigest mismatch");
}
@Test
@@ -81,7 +80,7 @@ public class TestBinaryRC4 {
String docIdHex, String saltDataHex, String saltHashHex) throws GeneralSecurityException {
confirmValid(expectedResult, docIdHex, saltDataHex, saltHashHex, null);
}
-
+
private static void confirmValid(boolean expectedResult, String docIdHex,
String saltDataHex, String saltHashHex, String password) throws GeneralSecurityException {
byte[] docId = readFromString(docIdHex);
@@ -96,11 +95,6 @@ public class TestBinaryRC4 {
String pass = password == null ? Decryptor.DEFAULT_PASSWORD : password;
boolean actResult = ei.getDecryptor().verifyPassword(pass);
- if (expectedResult) {
- assertTrue("validate failed", actResult);
- } else {
- assertFalse("validate succeeded unexpectedly", actResult);
- }
+ assertEquals(expectedResult, actResult, expectedResult ? "validate failed" : "validate succeeded unexpectedly");
}
-
}
diff --git a/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java b/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
index f03bbf9127..ef4eec6417 100644
--- a/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
+++ b/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
@@ -16,26 +16,35 @@
==================================================================== */
package org.apache.poi.poifs.dev;
+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.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.property.PropertyTable;
import org.apache.poi.util.TempFile;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.io.*;
-
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
public class TestPOIFSDump {
private static PrintStream SYSTEM;
- @BeforeClass
+ @BeforeAll
public static void setUp() throws UnsupportedEncodingException {
SYSTEM = System.out;
System.setOut(new PrintStream(new OutputStream() {
@@ -46,7 +55,7 @@ public class TestPOIFSDump {
}, false, "UTF-8"));
}
- @AfterClass
+ @AfterAll
public static void resetSystemOut() {
System.setOut(SYSTEM);
}
@@ -65,7 +74,7 @@ public class TestPOIFSDump {
"-dump-mini-stream",
};
- @After
+ @AfterEach
public void tearDown() throws IOException {
// clean up the directory that POIFSDump writes to
deleteDirectory(new File(new File(TEST_FILE+"_dump").getName()));
@@ -140,60 +149,28 @@ public class TestPOIFSDump {
}
}
@Test
- public void testInvalidFile() throws Exception {
- try {
- POIFSDump.main(new String[]{
- INVALID_FILE
- });
- fail("Should fail with an exception");
- } catch (NotOLE2FileException e) {
- // expected here
- }
-
- try {
- POIFSDump.main(new String[]{
- INVALID_XLSX_FILE
- });
- fail("Should fail with an exception");
- } catch (OfficeXmlFileException e) {
- // expected here
- }
+ public void testInvalidFile() {
+ assertThrows(NotOLE2FileException.class, () -> POIFSDump.main(new String[]{INVALID_FILE}));
+ assertThrows(OfficeXmlFileException.class, () -> POIFSDump.main(new String[]{INVALID_XLSX_FILE}));
for(String option : DUMP_OPTIONS) {
- try {
- POIFSDump.main(new String[]{
- option,
- INVALID_FILE
- });
- fail("Should fail with an exception");
- } catch (NotOLE2FileException e) {
- // expected here
- }
-
- try {
- POIFSDump.main(new String[]{
- option,
- INVALID_XLSX_FILE
- });
- fail("Should fail with an exception");
- } catch (OfficeXmlFileException e) {
- // expected here
- }
+ assertThrows(NotOLE2FileException.class, () -> POIFSDump.main(new String[]{option, INVALID_FILE}));
+ assertThrows(OfficeXmlFileException.class, () -> POIFSDump.main(new String[]{option, INVALID_XLSX_FILE}));
}
}
- @Ignore("Calls System.exit()")
+ @Disabled("Calls System.exit()")
@Test
public void testMainNoArgs() throws Exception {
POIFSDump.main(new String[] {});
}
- @Test(expected=IndexOutOfBoundsException.class)
+ @Test
public void testFailToWrite() throws IOException {
File dir = TempFile.createTempFile("TestPOIFSDump", ".tst");
- assertTrue("Had: " + dir, dir.exists());
- assertTrue("Had: " + dir, dir.delete());
- assertTrue("Had: " + dir, dir.mkdirs());
+ assertTrue(dir.exists(), "Had: " + dir);
+ assertTrue(dir.delete(), "Had: " + dir);
+ assertTrue(dir.mkdirs(), "Had: " + dir);
FileInputStream is = new FileInputStream(TEST_FILE);
POIFSFileSystem fs = new POIFSFileSystem(is);
@@ -204,6 +181,6 @@ public class TestPOIFSDump {
// try with an invalid startBlock to trigger an exception
// to validate that file-handles are closed properly
- POIFSDump.dump(fs, 999999999, "mini-stream", dir);
+ assertThrows(IndexOutOfBoundsException.class, () -> POIFSDump.dump(fs, 999999999, "mini-stream", dir));
}
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/poifs/eventfilesystem/TestPOIFSReaderRegistry.java b/src/testcases/org/apache/poi/poifs/eventfilesystem/TestPOIFSReaderRegistry.java
index 9a87b3fe7f..89457e22b1 100644
--- a/src/testcases/org/apache/poi/poifs/eventfilesystem/TestPOIFSReaderRegistry.java
+++ b/src/testcases/org/apache/poi/poifs/eventfilesystem/TestPOIFSReaderRegistry.java
@@ -17,16 +17,16 @@
package org.apache.poi.poifs.eventfilesystem;
-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.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.poi.poifs.filesystem.POIFSDocumentPath;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test POIFSReaderRegistry functionality
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/AllPOIFSFileSystemTests.java b/src/testcases/org/apache/poi/poifs/filesystem/AllPOIFSFileSystemTests.java
deleted file mode 100644
index fff4a4fcda..0000000000
--- a/src/testcases/org/apache/poi/poifs/filesystem/AllPOIFSFileSystemTests.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.poifs.filesystem;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Tests for org.apache.poi.poifs.filesystem
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestDirectoryNode.class
- , TestDocument.class
- , TestDocumentDescriptor.class
- , TestDocumentInputStream.class
- , TestDocumentOutputStream.class
- , TestEmptyDocument.class
- , TestNotOLE2Exception.class
- , TestOfficeXMLException.class
- , TestPOIFSDocumentPath.class
- , TestPOIFSFileSystem.class
- , TestPropertySorter.class
- , TestOle10Native.class
-})
-public final class AllPOIFSFileSystemTests {
-}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java
index b3363b9cae..92536e96f4 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java
@@ -18,11 +18,11 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
@@ -31,7 +31,7 @@ import java.util.Iterator;
import org.apache.poi.poifs.property.DirectoryProperty;
import org.apache.poi.poifs.property.DocumentProperty;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test DirectoryNode functionality
@@ -70,13 +70,7 @@ public final class TestDirectoryNode {
assertEquals(0, node.getEntryCount());
// verify behavior of getEntry
- try {
- node.getEntry("foo");
- fail("should have caught FileNotFoundException");
- } catch (FileNotFoundException ignored) {
-
- // as expected
- }
+ assertThrows(FileNotFoundException.class, () -> node.getEntry("foo"));
// verify behavior of isDirectoryEntry
assertTrue(node.isDirectoryEntry());
@@ -128,13 +122,7 @@ public final class TestDirectoryNode {
child1.getEntry("child3");
node.getEntry("child2");
- try {
- node.getEntry("child3");
- fail("should have caught FileNotFoundException");
- } catch (FileNotFoundException ignored) {
-
- // as expected
- }
+ assertThrows(FileNotFoundException.class, () -> node.getEntry("child3"));
// verify behavior of isDirectoryEntry
assertTrue(node.isDirectoryEntry());
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocument.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocument.java
index 59839672e3..91b58df0d9 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocument.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocument.java
@@ -18,10 +18,10 @@
package org.apache.poi.poifs.filesystem;
import static org.apache.poi.poifs.common.POIFSConstants.LARGER_BIG_BLOCK_SIZE;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -32,7 +32,7 @@ import java.util.stream.IntStream;
import org.apache.poi.poifs.property.DocumentProperty;
import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.util.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test POIFSDocument functionality
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java
index 0081a43181..c548042a2e 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java
@@ -17,10 +17,10 @@
package org.apache.poi.poifs.filesystem;
-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.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test DocumentDescriptor functionality
@@ -50,7 +50,7 @@ public final class TestDocumentDescriptor {
DocumentDescriptor d2 = new DocumentDescriptor(paths[ k ], names[ n ]);
if (m == n) {
- assertEquals("" + j + "," + k + "," + m + "," + n, d1, d2);
+ assertEquals(d1, d2, "" + j + "," + k + "," + m + "," + n);
} else {
assertNotEquals(d1, d2);
}
@@ -80,7 +80,7 @@ public final class TestDocumentDescriptor {
DocumentDescriptor d2 = new DocumentDescriptor(builtUpPaths[ k ], names[ n ]);
if ((k == j) && (m == n)) {
- assertEquals("" + j + "," + k + "," + m + "," + n, d1, d2);
+ assertEquals(d1, d2, "" + j + "," + k + "," + m + "," + n);
} else {
assertNotEquals(d1, d2);
}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
index b6261817a9..af5466b052 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
@@ -17,10 +17,10 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -30,8 +30,8 @@ import java.util.Arrays;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.SuppressForbidden;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Class to test DocumentInputStream functionality
@@ -45,7 +45,7 @@ public final class TestDocumentInputStream {
// any block size
private static final int _buffer_size = 6;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
int blocks = (_workbook_size + 511) / 512;
@@ -87,13 +87,13 @@ public final class TestDocumentInputStream {
/**
* test available() behavior
*/
- @Test(expected = IllegalStateException.class)
+ @Test
public void testAvailable() throws IOException {
DocumentInputStream nstream = new DocumentInputStream(_workbook_n);
assertEquals(_workbook_size, available(nstream));
nstream.close();
- available(nstream);
+ assertThrows(IllegalStateException.class, () -> available(nstream));
}
/**
@@ -109,10 +109,7 @@ public final class TestDocumentInputStream {
// Read a fifth of it, and check all's correct
stream.read(buffer);
for (int j = 0; j < buffer.length; j++) {
- assertEquals(
- "checking byte " + j,
- _workbook_data[j], buffer[j]
- );
+ assertEquals(_workbook_data[j], buffer[j], "checking byte " + j);
}
assertEquals(_workbook_size - buffer.length, available(stream));
@@ -125,10 +122,7 @@ public final class TestDocumentInputStream {
// Read part of a block
stream.read(small_buffer);
for (int j = 0; j < small_buffer.length; j++) {
- assertEquals(
- "checking byte " + j,
- _workbook_data[j], small_buffer[j]
- );
+ assertEquals(_workbook_data[j], small_buffer[j], "checking byte " + j);
}
assertEquals(_workbook_size - small_buffer.length, available(stream));
stream.mark(0);
@@ -136,10 +130,7 @@ public final class TestDocumentInputStream {
// Read the next part
stream.read(small_buffer);
for (int j = 0; j < small_buffer.length; j++) {
- assertEquals(
- "checking byte " + j,
- _workbook_data[j + small_buffer.length], small_buffer[j]
- );
+ assertEquals(_workbook_data[j + small_buffer.length], small_buffer[j], "checking byte " + j);
}
assertEquals(_workbook_size - 2 * small_buffer.length, available(stream));
@@ -150,10 +141,7 @@ public final class TestDocumentInputStream {
// Read
stream.read(small_buffer);
for (int j = 0; j < small_buffer.length; j++) {
- assertEquals(
- "checking byte " + j,
- _workbook_data[j + small_buffer.length], small_buffer[j]
- );
+ assertEquals(_workbook_data[j + small_buffer.length], small_buffer[j], "checking byte " + j);
}
assertEquals(_workbook_size - 2 * small_buffer.length, available(stream));
@@ -179,7 +167,7 @@ public final class TestDocumentInputStream {
pos++;
}
- assertEquals("checking byte " + j, exp, small_buffer[j]);
+ assertEquals(exp, small_buffer[j], "checking byte " + j);
}
// Now repeat it with spanning multiple blocks
@@ -188,10 +176,7 @@ public final class TestDocumentInputStream {
buffer = new byte[_workbook_size / 5];
stream.read(buffer);
for (int j = 0; j < buffer.length; j++) {
- assertEquals(
- "checking byte " + j,
- _workbook_data[j], buffer[j]
- );
+ assertEquals(_workbook_data[j], buffer[j], "checking byte " + j);
}
assertEquals(_workbook_size - buffer.length, available(stream));
@@ -201,20 +186,15 @@ public final class TestDocumentInputStream {
stream.read(buffer);
for (int j = 0; j < buffer.length; j++) {
- assertEquals(
- "checking byte " + j,
- _workbook_data[j], buffer[j]
- );
+ assertEquals(_workbook_data[j], buffer[j], "checking byte " + j);
}
// Mark our position, and read another whole buffer
stream.mark(12);
stream.read(buffer);
- assertEquals(_workbook_size - (2 * buffer.length),
- available(stream));
+ assertEquals(_workbook_size - (2 * buffer.length), available(stream));
for (int j = buffer.length; j < (2 * buffer.length); j++) {
- assertEquals("checking byte " + j, _workbook_data[j],
- buffer[j - buffer.length]);
+ assertEquals(_workbook_data[j], buffer[j - buffer.length], "checking byte " + j);
}
// Reset, should go back to only one buffer full read
@@ -223,11 +203,9 @@ public final class TestDocumentInputStream {
// Read the buffer again
stream.read(buffer);
- assertEquals(_workbook_size - (2 * buffer.length),
- available(stream));
+ assertEquals(_workbook_size - (2 * buffer.length), available(stream));
for (int j = buffer.length; j < (2 * buffer.length); j++) {
- assertEquals("checking byte " + j, _workbook_data[j],
- buffer[j - buffer.length]);
+ assertEquals(_workbook_data[j], buffer[j - buffer.length], "checking byte " + j);
}
assertTrue(stream.markSupported());
}
@@ -236,7 +214,7 @@ public final class TestDocumentInputStream {
* test simple read method
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
- @Test(expected = IOException.class)
+ @Test
public void testReadSingleByte() throws IOException {
DocumentInputStream stream = new DocumentInputStream(_workbook_n);
int remaining = _workbook_size;
@@ -244,12 +222,10 @@ public final class TestDocumentInputStream {
// Try and read each byte in turn
for (int j = 0; j < _workbook_size; j++) {
int b = stream.read();
- assertTrue("checking sign of " + j, b >= 0);
- assertEquals("validating byte " + j, _workbook_data[j],
- (byte) b);
+ assertTrue(b >= 0, "checking sign of " + j);
+ assertEquals(_workbook_data[j], (byte) b, "validating byte " + j);
remaining--;
- assertEquals("checking remaining after reading byte " + j,
- remaining, available(stream));
+ assertEquals(remaining, available(stream), "checking remaining after reading byte " + j);
}
// Ensure we fell off the end
@@ -257,7 +233,7 @@ public final class TestDocumentInputStream {
// Check that after close we can no longer read
stream.close();
- stream.read();
+ assertThrows(IOException.class, stream::read);
}
/**
@@ -268,12 +244,7 @@ public final class TestDocumentInputStream {
public void testBufferRead() throws IOException {
DocumentInputStream stream = new DocumentInputStream(_workbook_n);
// Need to give a byte array to read
- try {
- stream.read(null);
- fail("Should have caught NullPointerException");
- } catch (NullPointerException ignored) {
- // as expected
- }
+ assertThrows(NullPointerException.class, () -> stream.read(null));
// test reading zero length buffer
assertEquals(0, stream.read(new byte[0]));
@@ -284,12 +255,10 @@ public final class TestDocumentInputStream {
while (available(stream) >= buffer.length) {
assertEquals(_buffer_size, stream.read(buffer));
for (byte element : buffer) {
- assertEquals("in main loop, byte " + offset,
- _workbook_data[offset], element);
+ assertEquals(_workbook_data[offset], element, "in main loop, byte " + offset);
offset++;
}
- assertEquals("offset " + offset, _workbook_size - offset,
- available(stream));
+ assertEquals(_workbook_size - offset, available(stream), "offset " + offset);
}
assertEquals(_workbook_size % _buffer_size, available(stream));
Arrays.fill(buffer, (byte) 0);
@@ -297,22 +266,17 @@ public final class TestDocumentInputStream {
assertEquals(_workbook_size % _buffer_size, count);
for (int j = 0; j < count; j++) {
- assertEquals("past main loop, byte " + offset,
- _workbook_data[offset], buffer[j]);
+ assertEquals(_workbook_data[offset], buffer[j], "past main loop, byte " + offset);
offset++;
}
assertEquals(_workbook_size, offset);
for (int j = count; j < buffer.length; j++) {
- assertEquals("checking remainder, byte " + j, 0, buffer[j]);
+ assertEquals(0, buffer[j], "checking remainder, byte " + j);
}
assertEquals(-1, stream.read(buffer));
stream.close();
- try {
- stream.read(buffer);
- fail("Should have caught IOException");
- } catch (IOException ignored) {
- // as expected
- }
+
+ assertThrows(IOException.class, () -> stream.read(buffer));
}
/**
@@ -322,32 +286,12 @@ public final class TestDocumentInputStream {
@Test
public void testComplexBufferRead() throws IOException {
DocumentInputStream stream = new DocumentInputStream(_workbook_n);
- try {
- stream.read(null, 0, 1);
- fail("Should have caught NullPointerException");
- } catch (IllegalArgumentException ignored) {
- // as expected
- }
+ assertThrows(IllegalArgumentException.class, () -> stream.read(null, 0, 1));
// test illegal offsets and lengths
- try {
- stream.read(new byte[5], -4, 0);
- fail("Should have caught IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException ignored) {
- // as expected
- }
- try {
- stream.read(new byte[5], 0, -4);
- fail("Should have caught IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException ignored) {
- // as expected
- }
- try {
- stream.read(new byte[5], 0, 6);
- fail("Should have caught IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException ignored) {
- // as expected
- }
+ assertThrows(IndexOutOfBoundsException.class, () -> stream.read(new byte[5], -4, 0));
+ assertThrows(IndexOutOfBoundsException.class, () -> stream.read(new byte[5], 0, -4));
+ assertThrows(IndexOutOfBoundsException.class, () -> stream.read(new byte[5], 0, 6));
// test reading zero
assertEquals(0, stream.read(new byte[5], 0, 0));
@@ -357,48 +301,39 @@ public final class TestDocumentInputStream {
while (available(stream) >= _buffer_size) {
Arrays.fill(buffer, (byte) 0);
- assertEquals(_buffer_size,
- stream.read(buffer, offset, _buffer_size));
+ assertEquals(_buffer_size, stream.read(buffer, offset, _buffer_size));
for (int j = 0; j < offset; j++) {
- assertEquals("checking byte " + j, 0, buffer[j]);
+ assertEquals(0, buffer[j], "checking byte " + j);
}
for (int j = offset; j < (offset + _buffer_size); j++) {
- assertEquals("checking byte " + j, _workbook_data[j],
- buffer[j]);
+ assertEquals(_workbook_data[j], buffer[j], "checking byte " + j);
}
for (int j = offset + _buffer_size; j < buffer.length; j++) {
- assertEquals("checking byte " + j, 0, buffer[j]);
+ assertEquals(0, buffer[j], "checking byte " + j);
}
offset += _buffer_size;
- assertEquals("offset " + offset, _workbook_size - offset,
- available(stream));
+ assertEquals(_workbook_size - offset, available(stream), "offset " + offset);
}
assertEquals(_workbook_size % _buffer_size, available(stream));
Arrays.fill(buffer, (byte) 0);
- int count = stream.read(buffer, offset,
- _workbook_size % _buffer_size);
+ int count = stream.read(buffer, offset, _workbook_size % _buffer_size);
assertEquals(_workbook_size % _buffer_size, count);
for (int j = 0; j < offset; j++) {
- assertEquals("checking byte " + j, 0, buffer[j]);
+ assertEquals(0, buffer[j], "checking byte " + j);
}
for (int j = offset; j < buffer.length; j++) {
- assertEquals("checking byte " + j, _workbook_data[j],
- buffer[j]);
+ assertEquals(_workbook_data[j], buffer[j], "checking byte " + j);
}
assertEquals(_workbook_size, offset + count);
for (int j = count; j < offset; j++) {
- assertEquals("byte " + j, 0, buffer[j]);
+ assertEquals(0, buffer[j], "byte " + j);
}
assertEquals(-1, stream.read(buffer, 0, 1));
stream.close();
- try {
- stream.read(buffer, 0, 1);
- fail("Should have caught IOException");
- } catch (IOException ignored) {
- // as expected
- }
+
+ assertThrows(IOException.class, () -> stream.read(buffer, 0, 1));
}
/**
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java
index a31a78feab..36d31da9f7 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java
@@ -18,15 +18,16 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import org.apache.poi.util.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test DocumentOutputStream functionality
@@ -51,12 +52,7 @@ public final class TestDocumentOutputStream {
fail("stream exhausted too early");
}
- try {
- dstream.write(0);
- fail("Should have caught IOException");
- }
- catch (IOException ignored) {
- }
+ assertThrows(IOException.class, () -> dstream.write(0));
};
compare(l, expected);
@@ -78,11 +74,7 @@ public final class TestDocumentOutputStream {
fail("stream exhausted too early");
}
- try {
- dstream.write(new byte[]{'7','7','7','7'});
- fail("Should have caught IOException");
- } catch (IOException ignored) {
- }
+ assertThrows(IOException.class, () -> dstream.write(new byte[]{'7','7','7','7'}));
};
compare(l, expected);
@@ -103,11 +95,7 @@ public final class TestDocumentOutputStream {
} catch (IOException ignored) {
fail("stream exhausted too early");
}
- try {
- dstream.write(input, 0, 1);
- fail("Should have caught IOException");
- }
- catch (IOException ignored) {}
+ assertThrows(IOException.class, () -> dstream.write(input, 0, 1));
};
compare(l, expected);
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
index 9c7b688b58..bfd5a9c004 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
@@ -17,8 +17,8 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -27,7 +27,7 @@ import java.io.IOException;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestEmptyDocument {
private static final POILogger LOG = POILogFactory.getLogger(TestEmptyDocument.class);
@@ -48,12 +48,7 @@ public final class TestEmptyDocument {
public void testSingleEmptyDocumentEvent() throws IOException {
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry dir = fs.getRoot();
- dir.createDocument("Foo", 0, new POIFSWriterListener() {
- @Override
- public void processPOIFSWriterEvent(POIFSWriterEvent event) {
- LOG.log(POILogger.WARN, "written");
- }
- });
+ dir.createDocument("Foo", 0, event -> LOG.log(POILogger.WARN, "written"));
ByteArrayOutputStream out = new ByteArrayOutputStream();
fs.writeFilesystem(out);
@@ -78,21 +73,14 @@ public final class TestEmptyDocument {
public void testEmptyDocumentEventWithFriend() throws IOException {
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry dir = fs.getRoot();
- dir.createDocument("Bar", 1, new POIFSWriterListener() {
- @Override
- public void processPOIFSWriterEvent(POIFSWriterEvent event) {
- try {
- event.getStream().write(0);
- } catch (IOException exception) {
- throw new RuntimeException("exception on write: " + exception);
- }
- }
- });
- dir.createDocument("Foo", 0, new POIFSWriterListener() {
- @Override
- public void processPOIFSWriterEvent(POIFSWriterEvent event) {
+ dir.createDocument("Bar", 1, event -> {
+ try {
+ event.getStream().write(0);
+ } catch (IOException exception) {
+ throw new RuntimeException("exception on write: " + exception);
}
});
+ dir.createDocument("Foo", 0, event -> {});
ByteArrayOutputStream out = new ByteArrayOutputStream();
fs.writeFilesystem(out);
@@ -116,15 +104,15 @@ public final class TestEmptyDocument {
fs = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
DocumentEntry entry = (DocumentEntry) fs.getRoot().getEntry("Empty");
- assertEquals("Expected zero size", 0, entry.getSize());
+ assertEquals(0, entry.getSize(), "Expected zero size");
byte[] actualReadbackData;
actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
- assertEquals("Expected zero read from stream", 0, actualReadbackData.length);
+ assertEquals(0, actualReadbackData.length, "Expected zero read from stream");
entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty");
actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
- assertEquals("Expected size was wrong", testData.length, entry.getSize());
- assertArrayEquals("Expected same data read from stream", testData, actualReadbackData);
+ assertEquals(testData.length, entry.getSize(), "Expected size was wrong");
+ assertArrayEquals(testData, actualReadbackData, "Expected same data read from stream");
fs.close();
}
}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java b/src/testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java
index 7dca078a3e..984844a4d2 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java
@@ -17,11 +17,11 @@
package org.apache.poi.poifs.filesystem;
-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.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.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -30,7 +30,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestEntryUtils {
private static final byte[] dataSmallA = new byte[] { 12, 42, 11, -12, -121 };
@@ -42,23 +42,23 @@ public class TestEntryUtils {
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry dirA = fs.createDirectory("DirA");
DirectoryEntry dirB = fs.createDirectory("DirB");
-
+
DocumentEntry entryR = fs.createDocument(new ByteArrayInputStream(dataSmallA), "EntryRoot");
DocumentEntry entryA1 = dirA.createDocument("EntryA1", new ByteArrayInputStream(dataSmallA));
DocumentEntry entryA2 = dirA.createDocument("EntryA2", new ByteArrayInputStream(dataSmallB));
-
+
// Copy docs
assertEquals(0, fsD.getRoot().getEntryCount());
EntryUtils.copyNodeRecursively(entryR, fsD.getRoot());
-
+
assertEquals(1, fsD.getRoot().getEntryCount());
assertNotNull(fsD.getRoot().getEntry("EntryRoot"));
-
+
EntryUtils.copyNodeRecursively(entryA1, fsD.getRoot());
assertEquals(2, fsD.getRoot().getEntryCount());
assertNotNull(fsD.getRoot().getEntry("EntryRoot"));
assertNotNull(fsD.getRoot().getEntry("EntryA1"));
-
+
EntryUtils.copyNodeRecursively(entryA2, fsD.getRoot());
assertEquals(3, fsD.getRoot().getEntryCount());
assertNotNull(fsD.getRoot().getEntry("EntryRoot"));
@@ -66,16 +66,16 @@ public class TestEntryUtils {
assertNotNull(fsD.getRoot().getEntry("EntryA2"));
fsD.close();
-
+
// Copy directories
fsD = new POIFSFileSystem();
assertEquals(0, fsD.getRoot().getEntryCount());
-
+
EntryUtils.copyNodeRecursively(dirB, fsD.getRoot());
assertEquals(1, fsD.getRoot().getEntryCount());
assertNotNull(fsD.getRoot().getEntry("DirB"));
assertEquals(0, ((DirectoryEntry)fsD.getRoot().getEntry("DirB")).getEntryCount());
-
+
EntryUtils.copyNodeRecursively(dirA, fsD.getRoot());
assertEquals(2, fsD.getRoot().getEntryCount());
assertNotNull(fsD.getRoot().getEntry("DirB"));
@@ -83,11 +83,11 @@ public class TestEntryUtils {
assertNotNull(fsD.getRoot().getEntry("DirA"));
assertEquals(2, ((DirectoryEntry)fsD.getRoot().getEntry("DirA")).getEntryCount());
fsD.close();
-
+
// Copy the whole lot
fsD = new POIFSFileSystem();
assertEquals(0, fsD.getRoot().getEntryCount());
-
+
EntryUtils.copyNodes(fs, fsD, new ArrayList<>());
assertEquals(3, fsD.getRoot().getEntryCount());
assertNotNull(fsD.getRoot().getEntry(dirA.getName()));
@@ -104,32 +104,32 @@ public class TestEntryUtils {
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry dirA = fs.createDirectory("DirA");
DirectoryEntry dirB = fs.createDirectory("DirB");
-
+
DocumentEntry entryA1 = dirA.createDocument("Entry1", new ByteArrayInputStream(dataSmallA));
DocumentEntry entryA1b = dirA.createDocument("Entry1b", new ByteArrayInputStream(dataSmallA));
DocumentEntry entryA2 = dirA.createDocument("Entry2", new ByteArrayInputStream(dataSmallB));
DocumentEntry entryB1 = dirB.createDocument("Entry1", new ByteArrayInputStream(dataSmallA));
-
-
+
+
// Names must match
assertNotEquals(entryA1.getName(), entryA1b.getName());
assertFalse(EntryUtils.areDocumentsIdentical(entryA1, entryA1b));
-
+
// Contents must match
assertFalse(EntryUtils.areDocumentsIdentical(entryA1, entryA2));
-
+
// Parents don't matter if contents + names are the same
assertNotEquals(entryA1.getParent(), entryB1.getParent());
assertTrue(EntryUtils.areDocumentsIdentical(entryA1, entryB1));
-
-
+
+
// Can work with POIFS
ByteArrayOutputStream tmpO = new ByteArrayOutputStream();
fs.writeFilesystem(tmpO);
-
+
ByteArrayInputStream tmpI = new ByteArrayInputStream(tmpO.toByteArray());
POIFSFileSystem nfs = new POIFSFileSystem(tmpI);
-
+
DirectoryEntry dN1 = (DirectoryEntry)nfs.getRoot().getEntry("DirA");
DirectoryEntry dN2 = (DirectoryEntry)nfs.getRoot().getEntry("DirB");
DocumentEntry eNA1 = (DocumentEntry)dN1.getEntry(entryA1.getName());
@@ -153,59 +153,59 @@ public class TestEntryUtils {
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry dirA = fs.createDirectory("DirA");
DirectoryEntry dirB = fs.createDirectory("DirB");
-
+
// Names must match
assertFalse(EntryUtils.areDirectoriesIdentical(dirA, dirB));
-
+
// Empty dirs are fine
- DirectoryEntry dirA1 = dirA.createDirectory("TheDir");
+ DirectoryEntry dirA1 = dirA.createDirectory("TheDir");
DirectoryEntry dirB1 = dirB.createDirectory("TheDir");
assertEquals(0, dirA1.getEntryCount());
assertEquals(0, dirB1.getEntryCount());
assertTrue(EntryUtils.areDirectoriesIdentical(dirA1, dirB1));
-
+
// Otherwise children must match
dirA1.createDocument("Entry1", new ByteArrayInputStream(dataSmallA));
assertFalse(EntryUtils.areDirectoriesIdentical(dirA1, dirB1));
-
+
dirB1.createDocument("Entry1", new ByteArrayInputStream(dataSmallA));
assertTrue(EntryUtils.areDirectoriesIdentical(dirA1, dirB1));
-
+
dirA1.createDirectory("DD");
assertFalse(EntryUtils.areDirectoriesIdentical(dirA1, dirB1));
dirB1.createDirectory("DD");
assertTrue(EntryUtils.areDirectoriesIdentical(dirA1, dirB1));
-
-
+
+
// Excludes support
List<String> excl = Arrays.asList("Ignore1", "IgnDir/Ign2");
FilteringDirectoryNode fdA = new FilteringDirectoryNode(dirA1, excl);
FilteringDirectoryNode fdB = new FilteringDirectoryNode(dirB1, excl);
assertTrue(EntryUtils.areDirectoriesIdentical(fdA, fdB));
-
+
// Add an ignored doc, no notice is taken
fdA.createDocument("Ignore1", new ByteArrayInputStream(dataSmallA));
assertTrue(EntryUtils.areDirectoriesIdentical(fdA, fdB));
-
+
// Add a directory with filtered contents, not the same
DirectoryEntry dirAI = dirA1.createDirectory("IgnDir");
assertFalse(EntryUtils.areDirectoriesIdentical(fdA, fdB));
-
+
DirectoryEntry dirBI = dirB1.createDirectory("IgnDir");
assertTrue(EntryUtils.areDirectoriesIdentical(fdA, fdB));
-
+
// Add something to the filtered subdir that gets ignored
dirAI.createDocument("Ign2", new ByteArrayInputStream(dataSmallA));
assertTrue(EntryUtils.areDirectoriesIdentical(fdA, fdB));
-
+
// And something that doesn't
dirAI.createDocument("IgnZZ", new ByteArrayInputStream(dataSmallA));
assertFalse(EntryUtils.areDirectoriesIdentical(fdA, fdB));
-
+
dirBI.createDocument("IgnZZ", new ByteArrayInputStream(dataSmallA));
assertTrue(EntryUtils.areDirectoriesIdentical(fdA, fdB));
-
+
fs.close();
}
}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestFileMagic.java b/src/testcases/org/apache/poi/poifs/filesystem/TestFileMagic.java
index 0b1261a7fc..1cd92b952f 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestFileMagic.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestFileMagic.java
@@ -17,13 +17,13 @@
package org.apache.poi.poifs.filesystem;
-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.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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+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.BufferedInputStream;
import java.io.File;
@@ -37,7 +37,7 @@ import java.util.Random;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.TempFile;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestFileMagic {
@Test
@@ -62,12 +62,7 @@ public class TestFileMagic {
assertEquals(FileMagic.UNKNOWN, FileMagic.valueOf("something".getBytes(StandardCharsets.UTF_8)));
assertEquals(FileMagic.UNKNOWN, FileMagic.valueOf(new byte[0]));
- try {
- FileMagic.valueOf("some string");
- fail("Should catch exception here");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> FileMagic.valueOf("some string"));
}
@Test
@@ -134,7 +129,7 @@ public class TestFileMagic {
}
}
- @Test(expected = IOException.class)
+ @Test
public void testMarkRequired() throws IOException {
byte[] data = new byte[] { -1, -40, -1, -32, 0 };
@@ -148,7 +143,7 @@ public class TestFileMagic {
try (FileInputStream str = new FileInputStream(file)) {
assertFalse(str.markSupported());
- FileMagic.valueOf(str);
+ assertThrows(IOException.class, () -> FileMagic.valueOf(str));
}
} finally {
assertTrue(file.delete());
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java
index 140794bca8..dee7a17c4b 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java
@@ -17,8 +17,8 @@
package org.apache.poi.poifs.filesystem;
-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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -30,8 +30,8 @@ import java.util.List;
import java.util.Map;
import org.apache.poi.POIDataSamples;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
/**
* Tests bugs for POIFSFileSystem
@@ -42,7 +42,7 @@ public final class TestFileSystemBugs {
private List<POIFSFileSystem> openedFSs;
- @After
+ @AfterEach
public void tearDown() {
if (openedFSs != null && !openedFSs.isEmpty()) {
for (POIFSFileSystem fs : openedFSs) {
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestFilteringDirectoryNode.java b/src/testcases/org/apache/poi/poifs/filesystem/TestFilteringDirectoryNode.java
index 65d9265ab0..e511bc2609 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestFilteringDirectoryNode.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestFilteringDirectoryNode.java
@@ -18,11 +18,10 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
@@ -32,177 +31,134 @@ import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Class to test FilteringDirectoryNode functionality
*/
public final class TestFilteringDirectoryNode {
- private POIFSFileSystem fs;
- private DirectoryEntry dirA;
- private DirectoryEntry dirAA;
- private DirectoryEntry dirB;
- private DocumentEntry eRoot;
- private DocumentEntry eA;
- private DocumentEntry eAA;
-
- @Before
- public void setUp() throws Exception {
- fs = new POIFSFileSystem();
- dirA = fs.createDirectory("DirA");
- dirB = fs.createDirectory("DirB");
- dirAA = dirA.createDirectory("DirAA");
- eRoot = fs.getRoot().createDocument("Root", new ByteArrayInputStream(new byte[]{}));
- eA = dirA.createDocument("NA", new ByteArrayInputStream(new byte[]{}));
- eAA = dirAA.createDocument("NAA", new ByteArrayInputStream(new byte[]{}));
- }
-
- @Test
- public void testNoFiltering() throws Exception {
- FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), new HashSet<>());
- assertEquals(3, d.getEntryCount());
- assertEquals(dirA.getName(), d.getEntry(dirA.getName()).getName());
-
- assertTrue(d.getEntry(dirA.getName()).isDirectoryEntry());
- assertFalse(d.getEntry(dirA.getName()).isDocumentEntry());
-
- assertTrue(d.getEntry(dirB.getName()).isDirectoryEntry());
- assertFalse(d.getEntry(dirB.getName()).isDocumentEntry());
-
- assertFalse(d.getEntry(eRoot.getName()).isDirectoryEntry());
- assertTrue(d.getEntry(eRoot.getName()).isDocumentEntry());
-
- Iterator<Entry> i = d.getEntries();
- assertEquals(dirA, i.next());
- assertEquals(dirB, i.next());
- assertEquals(eRoot, i.next());
- try {
- assertNull(i.next());
- fail("Should throw NoSuchElementException when depleted");
- } catch (NoSuchElementException ignored) {
- }
- }
-
- @Test
- public void testChildFiltering() throws Exception {
- List<String> excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName());
- FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), excl);
-
- assertEquals(2, d.getEntryCount());
- assertTrue(d.hasEntry(dirA.getName()));
- assertTrue(d.hasEntry(dirB.getName()));
- assertFalse(d.hasEntry(eRoot.getName()));
-
- assertEquals(dirA, d.getEntry(dirA.getName()));
- assertEquals(dirB, d.getEntry(dirB.getName()));
- try {
- d.getEntry(eRoot.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
-
- Iterator<Entry> i = d.getEntries();
- assertEquals(dirA, i.next());
- assertEquals(dirB, i.next());
- try {
- assertNull(i.next());
- fail("Should throw NoSuchElementException when depleted");
- } catch (NoSuchElementException ignored) {
- }
-
-
- // Filter more
- excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName(), dirA.getName());
- d = new FilteringDirectoryNode(fs.getRoot(), excl);
-
- assertEquals(1, d.getEntryCount());
- assertFalse(d.hasEntry(dirA.getName()));
- assertTrue(d.hasEntry(dirB.getName()));
- assertFalse(d.hasEntry(eRoot.getName()));
-
- try {
- d.getEntry(dirA.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
- assertEquals(dirB, d.getEntry(dirB.getName()));
- try {
- d.getEntry(eRoot.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
-
- i = d.getEntries();
- assertEquals(dirB, i.next());
- try {
- assertNull(i.next());
- fail("Should throw NoSuchElementException when depleted");
- } catch (NoSuchElementException ignored) {
- }
-
-
- // Filter everything
- excl = Arrays.asList("NotThere", eRoot.getName(), dirA.getName(), dirB.getName());
- d = new FilteringDirectoryNode(fs.getRoot(), excl);
-
- assertEquals(0, d.getEntryCount());
- assertFalse(d.hasEntry(dirA.getName()));
- assertFalse(d.hasEntry(dirB.getName()));
- assertFalse(d.hasEntry(eRoot.getName()));
-
- try {
- d.getEntry(dirA.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
- try {
- d.getEntry(dirB.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
- try {
- d.getEntry(eRoot.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
-
- i = d.getEntries();
- try {
- assertNull(i.next());
- fail("Should throw NoSuchElementException when depleted");
- } catch (NoSuchElementException ignored) {
- }
- }
-
- @Test
- public void testNestedFiltering() throws Exception {
- List<String> excl = Arrays.asList(dirA.getName() + "/" + "MadeUp",
- dirA.getName() + "/" + eA.getName(),
- dirA.getName() + "/" + dirAA.getName() + "/Test",
- eRoot.getName());
- FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), excl);
-
- // Check main
- assertEquals(2, d.getEntryCount());
- assertTrue(d.hasEntry(dirA.getName()));
- assertTrue(d.hasEntry(dirB.getName()));
- assertFalse(d.hasEntry(eRoot.getName()));
-
- // Check filtering down
- assertTrue(d.getEntry(dirA.getName()) instanceof FilteringDirectoryNode);
- assertFalse(d.getEntry(dirB.getName()) instanceof FilteringDirectoryNode);
-
- DirectoryEntry fdA = (DirectoryEntry) d.getEntry(dirA.getName());
- assertFalse(fdA.hasEntry(eA.getName()));
- assertTrue(fdA.hasEntry(dirAA.getName()));
-
- DirectoryEntry fdAA = (DirectoryEntry) fdA.getEntry(dirAA.getName());
- assertTrue(fdAA.hasEntry(eAA.getName()));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNullDirectory() {
- new FilteringDirectoryNode(null, null);
- }
+ private POIFSFileSystem fs;
+ private DirectoryEntry dirA;
+ private DirectoryEntry dirAA;
+ private DirectoryEntry dirB;
+ private DocumentEntry eRoot;
+ private DocumentEntry eA;
+ private DocumentEntry eAA;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ fs = new POIFSFileSystem();
+ dirA = fs.createDirectory("DirA");
+ dirB = fs.createDirectory("DirB");
+ dirAA = dirA.createDirectory("DirAA");
+ eRoot = fs.getRoot().createDocument("Root", new ByteArrayInputStream(new byte[]{}));
+ eA = dirA.createDocument("NA", new ByteArrayInputStream(new byte[]{}));
+ eAA = dirAA.createDocument("NAA", new ByteArrayInputStream(new byte[]{}));
+ }
+
+ @Test
+ public void testNoFiltering() throws Exception {
+ FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), new HashSet<>());
+ assertEquals(3, d.getEntryCount());
+ assertEquals(dirA.getName(), d.getEntry(dirA.getName()).getName());
+
+ assertTrue(d.getEntry(dirA.getName()).isDirectoryEntry());
+ assertFalse(d.getEntry(dirA.getName()).isDocumentEntry());
+
+ assertTrue(d.getEntry(dirB.getName()).isDirectoryEntry());
+ assertFalse(d.getEntry(dirB.getName()).isDocumentEntry());
+
+ assertFalse(d.getEntry(eRoot.getName()).isDirectoryEntry());
+ assertTrue(d.getEntry(eRoot.getName()).isDocumentEntry());
+
+ Iterator<Entry> i = d.getEntries();
+ assertEquals(dirA, i.next());
+ assertEquals(dirB, i.next());
+ assertEquals(eRoot, i.next());
+ assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted");
+ }
+
+ @Test
+ public void testChildFiltering() throws Exception {
+ List<String> excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName());
+ FilteringDirectoryNode d1 = new FilteringDirectoryNode(fs.getRoot(), excl);
+
+ assertEquals(2, d1.getEntryCount());
+ assertTrue(d1.hasEntry(dirA.getName()));
+ assertTrue(d1.hasEntry(dirB.getName()));
+ assertFalse(d1.hasEntry(eRoot.getName()));
+
+ assertEquals(dirA, d1.getEntry(dirA.getName()));
+ assertEquals(dirB, d1.getEntry(dirB.getName()));
+ assertThrows(FileNotFoundException.class, () -> d1.getEntry(eRoot.getName()));
+
+ Iterator<Entry> i = d1.getEntries();
+ assertEquals(dirA, i.next());
+ assertEquals(dirB, i.next());
+ assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted");
+
+
+ // Filter more
+ excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName(), dirA.getName());
+ FilteringDirectoryNode d2 = new FilteringDirectoryNode(fs.getRoot(), excl);
+
+ assertEquals(1, d2.getEntryCount());
+ assertFalse(d2.hasEntry(dirA.getName()));
+ assertTrue(d2.hasEntry(dirB.getName()));
+ assertFalse(d2.hasEntry(eRoot.getName()));
+ assertThrows(FileNotFoundException.class, () -> d2.getEntry(dirA.getName()), "Should be filtered");
+ assertEquals(dirB, d2.getEntry(dirB.getName()));
+ assertThrows(FileNotFoundException.class, () -> d2.getEntry(eRoot.getName()), "Should be filtered");
+
+ i = d2.getEntries();
+ assertEquals(dirB, i.next());
+ assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted");
+
+ // Filter everything
+ excl = Arrays.asList("NotThere", eRoot.getName(), dirA.getName(), dirB.getName());
+ FilteringDirectoryNode d3 = new FilteringDirectoryNode(fs.getRoot(), excl);
+
+ assertEquals(0, d3.getEntryCount());
+ assertFalse(d3.hasEntry(dirA.getName()));
+ assertFalse(d3.hasEntry(dirB.getName()));
+ assertFalse(d3.hasEntry(eRoot.getName()));
+ assertThrows(FileNotFoundException.class, () -> d3.getEntry(dirA.getName()), "Should be filtered");
+ assertThrows(FileNotFoundException.class, () -> d3.getEntry(dirB.getName()), "Should be filtered");
+ assertThrows(FileNotFoundException.class, () -> d3.getEntry(eRoot.getName()), "Should be filtered");
+
+ i = d3.getEntries();
+ assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted");
+ }
+
+ @Test
+ public void testNestedFiltering() throws Exception {
+ List<String> excl = Arrays.asList(dirA.getName() + "/" + "MadeUp",
+ dirA.getName() + "/" + eA.getName(),
+ dirA.getName() + "/" + dirAA.getName() + "/Test",
+ eRoot.getName());
+ FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), excl);
+
+ // Check main
+ assertEquals(2, d.getEntryCount());
+ assertTrue(d.hasEntry(dirA.getName()));
+ assertTrue(d.hasEntry(dirB.getName()));
+ assertFalse(d.hasEntry(eRoot.getName()));
+
+ // Check filtering down
+ assertTrue(d.getEntry(dirA.getName()) instanceof FilteringDirectoryNode);
+ assertFalse(d.getEntry(dirB.getName()) instanceof FilteringDirectoryNode);
+
+ DirectoryEntry fdA = (DirectoryEntry) d.getEntry(dirA.getName());
+ assertFalse(fdA.hasEntry(eA.getName()));
+ assertTrue(fdA.hasEntry(dirAA.getName()));
+
+ DirectoryEntry fdAA = (DirectoryEntry) fdA.getEntry(dirAA.getName());
+ assertTrue(fdAA.hasEntry(eAA.getName()));
+ }
+
+ @Test
+ public void testNullDirectory() {
+ assertThrows(IllegalArgumentException.class, () -> new FilteringDirectoryNode(null, null));
+ }
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java
index ef0798a4c7..d43833bb1f 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java
@@ -18,7 +18,7 @@
package org.apache.poi.poifs.filesystem;
import static org.apache.poi.POITestCase.assertContains;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import java.io.InputStream;
@@ -26,7 +26,7 @@ import java.io.InputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.OldExcelFormatException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test that POIFS complains when given older non-OLE2
@@ -44,10 +44,7 @@ public class TestNotOLE2Exception {
@Test
public void testRawXMLException() throws IOException {
try (InputStream in = openXLSSampleStream("SampleSS.xml")) {
- new POIFSFileSystem(in).close();
- fail("expected exception was not thrown");
- } catch(NotOLE2FileException e) {
- // expected during successful test
+ NotOLE2FileException e = assertThrows(NotOLE2FileException.class, () -> new POIFSFileSystem(in));
assertContains(e.getMessage(), "The supplied data appears to be a raw XML file");
assertContains(e.getMessage(), "Formats such as Office 2003 XML");
}
@@ -56,10 +53,7 @@ public class TestNotOLE2Exception {
@Test
public void testMSWriteException() throws IOException {
try (InputStream in = openDOCSampleStream("MSWriteOld.wri")) {
- new POIFSFileSystem(in).close();
- fail("expected exception was not thrown");
- } catch(NotOLE2FileException e) {
- // expected during successful test
+ NotOLE2FileException e = assertThrows(NotOLE2FileException.class, () -> new POIFSFileSystem(in));
assertContains(e.getMessage(), "The supplied data appears to be in the old MS Write");
assertContains(e.getMessage(), "doesn't currently support");
}
@@ -68,10 +62,7 @@ public class TestNotOLE2Exception {
@Test
public void testBiff3Exception() throws IOException {
try (InputStream in = openXLSSampleStream("testEXCEL_3.xls")) {
- new POIFSFileSystem(in).close();
- fail("expected exception was not thrown");
- } catch(OldExcelFormatException e) {
- // expected during successful test
+ OldExcelFormatException e = assertThrows(OldExcelFormatException.class, () -> new POIFSFileSystem(in));
assertContains(e.getMessage(), "The supplied data appears to be in BIFF3 format");
assertContains(e.getMessage(), "try OldExcelExtractor");
}
@@ -80,10 +71,7 @@ public class TestNotOLE2Exception {
@Test
public void testBiff4Exception() throws IOException {
try (InputStream in = openXLSSampleStream("testEXCEL_4.xls")) {
- new POIFSFileSystem(in).close();
- fail("expected exception was not thrown");
- } catch(OldExcelFormatException e) {
- // expected during successful test
+ OldExcelFormatException e = assertThrows(OldExcelFormatException.class, () -> new POIFSFileSystem(in));
assertContains(e.getMessage(), "The supplied data appears to be in BIFF4 format");
assertContains(e.getMessage(), "try OldExcelExtractor");
}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java b/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java
index 1b154bd89d..bd727fafcb 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java
@@ -17,11 +17,11 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+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.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -29,7 +29,7 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test that POIFS complains when given an Office 2003 XML
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java b/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java
index 2a235d3940..7aa4efaf7a 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java
@@ -19,9 +19,9 @@ package org.apache.poi.poifs.filesystem;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
-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.ByteArrayOutputStream;
import java.io.File;
@@ -34,7 +34,7 @@ import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.RecordFormatException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestOle10Native {
private static final POIDataSamples dataSamples = POIDataSamples.getPOIFSInstance();
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java
index 9c01ca0a52..58119d8a13 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java
@@ -17,15 +17,16 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test POIFSDocumentPath functionality
@@ -73,14 +74,8 @@ public final class TestPOIFSDocumentPath {
// test weird variants
assertEquals(0, new POIFSDocumentPath(null).length());
- try {
- new POIFSDocumentPath(new String[]{"fu", ""});
- fail("should have caught IllegalArgumentException");
- } catch (IllegalArgumentException ignored) { }
- try {
- new POIFSDocumentPath(new String[]{"fu", null});
- fail("should have caught IllegalArgumentException");
- } catch (IllegalArgumentException ignored) { }
+ assertThrows(IllegalArgumentException.class, () -> new POIFSDocumentPath(new String[]{"fu", ""}));
+ assertThrows(IllegalArgumentException.class, () -> new POIFSDocumentPath(new String[]{"fu", null}));
}
/**
@@ -129,16 +124,10 @@ public final class TestPOIFSDocumentPath {
new POIFSDocumentPath(base, new String[]{"", "fu"});
// This one shouldn't be allowed
- try {
- new POIFSDocumentPath(base, new String[]{"fu", null});
- fail("should have caught IllegalArgumentException");
- } catch (IllegalArgumentException ignored) { }
+ assertThrows(IllegalArgumentException.class, () -> new POIFSDocumentPath(base, new String[]{"fu", null}));
// Ditto
- try {
- new POIFSDocumentPath(base, new String[]{null, "fu"});
- fail("should have caught IllegalArgumentException");
- } catch (IllegalArgumentException ignored) { }
+ assertThrows(IllegalArgumentException.class, () -> new POIFSDocumentPath(base, new String[]{null, "fu"}));
}
}
@@ -157,7 +146,7 @@ public final class TestPOIFSDocumentPath {
for (int j = 0; j < paths.length; j++) {
for (int k = 0; k < paths.length; k++) {
- assertEquals(j + "<>" + k, paths[ j ], paths[ k ]);
+ assertEquals(paths[ j ], paths[ k ], j + "<>" + k);
}
}
a2 = new POIFSDocumentPath(a1, new String[]{"foo"});
@@ -178,7 +167,7 @@ public final class TestPOIFSDocumentPath {
for (int k = 0; k < builtUpPaths.length; k++) {
for (int j = 0; j < fullPaths.length; j++) {
if (k == j) {
- assertEquals(j + "<>" + k, fullPaths[ j ], builtUpPaths[ k ]);
+ assertEquals(fullPaths[ j ], builtUpPaths[ k ], j + "<>" + k);
} else {
assertNotEquals(fullPaths[j], builtUpPaths[k]);
}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
index 9860935c12..cff04d3e78 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
@@ -18,10 +18,9 @@
package org.apache.poi.poifs.filesystem;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
-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.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -42,7 +41,7 @@ import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.storage.BATBlock;
import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.util.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for the older OPOIFS-based POIFSFileSystem
@@ -113,23 +112,17 @@ public final class TestPOIFSFileSystem {
*/
@Test
public void testAlwaysClose() throws IOException {
- TestIS testIS;
-
// Normal case - read until EOF and close
- testIS = new TestIS(openSampleStream("13224.xls"), -1);
- try (POIFSFileSystem ignored = new POIFSFileSystem(testIS)){
- assertTrue("input stream was not closed", testIS.isClosed());
+ try (TestIS testIS = new TestIS(openSampleStream("13224.xls"), -1);
+ POIFSFileSystem ignored = new POIFSFileSystem(testIS)){
+ assertTrue(testIS.isClosed(), "input stream was not closed");
}
// intended to crash after reading 10000 bytes
- testIS = new TestIS(openSampleStream("13224.xls"), 10000);
- try (POIFSFileSystem ignored = new POIFSFileSystem(testIS)){
- fail("ex should have been thrown");
- } catch (MyEx e) {
- // expected
- assertTrue("input stream was not closed", testIS.isClosed()); // but still should close
- } catch (Exception e) {
- fail("MyEx is expected to be thrown");
+ try (TestIS testIS = new TestIS(openSampleStream("13224.xls"), 10000)){
+ assertThrows(MyEx.class, () -> new POIFSFileSystem(testIS));
+ // but still should close
+ assertTrue(testIS.isClosed(), "input stream was not closed");
}
}
@@ -173,9 +166,9 @@ public final class TestPOIFSFileSystem {
public void testFATandDIFATsectors() throws Exception {
try (InputStream stream = _samples.openResourceAsStream("ReferencesInvalidSectors.mpp")) {
IndexOutOfBoundsException ex = assertThrows(
- "File is corrupt and shouldn't have been opened",
IndexOutOfBoundsException.class,
- () -> new POIFSFileSystem(stream)
+ () -> new POIFSFileSystem(stream),
+ "File is corrupt and shouldn't have been opened"
);
assertTrue(ex.getMessage().contains("Block 1148 not found"));
}
@@ -302,8 +295,7 @@ public final class TestPOIFSFileSystem {
try (POIFSFileSystem poiFS = new POIFSFileSystem(_samples.getFile("64322.ole2"))) {
int count = recurseDir(poiFS.getRoot());
- assertEquals("Expecting a fixed number of entries being found in the test-document",
- 1285, count);
+ assertEquals(1285, count, "Expecting a fixed number of entries being found in the test-document");
}
}
@@ -312,8 +304,7 @@ public final class TestPOIFSFileSystem {
try (POIFSFileSystem poiFS = new POIFSFileSystem(_samples.openResourceAsStream("64322.ole2"))) {
int count = recurseDir(poiFS.getRoot());
- assertEquals("Expecting a fixed number of entries being found in the test-document",
- 1285, count);
+ assertEquals(1285, count, "Expecting a fixed number of entries being found in the test-document");
}
}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSMiniStore.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSMiniStore.java
index 92ea46c698..26f8d6b8fa 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSMiniStore.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSMiniStore.java
@@ -17,11 +17,12 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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 static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
@@ -31,451 +32,443 @@ import java.util.NoSuchElementException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for the Mini Store in the NIO POIFS
*/
@SuppressWarnings("CatchMayIgnoreException")
public final class TestPOIFSMiniStore {
- private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance();
-
- /**
- * Check that for a given mini block, we can correctly figure
- * out what the next one is
- */
- @Test
- public void testNextBlock() throws Exception {
- // It's the same on 512 byte and 4096 byte block files!
- POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- POIFSFileSystem fsC = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
- POIFSFileSystem fsD = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB,fsC,fsD}) {
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // 0 -> 51 is one stream
- for(int i=0; i<50; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(50));
-
- // 51 -> 103 is the next
- for(int i=51; i<103; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(103));
-
- // Then there are 3 one block ones
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(104));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(105));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(106));
-
- // 107 -> 154 is the next
- for(int i=107; i<154; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(154));
-
- // 155 -> 160 is the next
- for(int i=155; i<160; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(160));
-
- // 161 -> 166 is the next
- for(int i=161; i<166; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(166));
-
- // 167 -> 172 is the next
- for(int i=167; i<172; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(172));
-
- // Now some short ones
- assertEquals(174 , ministore.getNextBlock(173));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(174));
-
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(175));
-
- assertEquals(177 , ministore.getNextBlock(176));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(177));
-
- assertEquals(179 , ministore.getNextBlock(178));
- assertEquals(180 , ministore.getNextBlock(179));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
-
- // 181 onwards is free
- for(int i=181; i<fs.getBigBlockSizeDetails().getBATEntriesPerBlock(); i++) {
+ private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance();
+
+ /**
+ * Check that for a given mini block, we can correctly figure
+ * out what the next one is
+ */
+ @Test
+ public void testNextBlock() throws Exception {
+ // It's the same on 512 byte and 4096 byte block files!
+ POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ POIFSFileSystem fsC = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+ POIFSFileSystem fsD = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB, fsC, fsD}) {
+ POIFSMiniStore ministore = fs.getMiniStore();
+
+ // 0 -> 51 is one stream
+ for (int i = 0; i < 50; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(50));
+
+ // 51 -> 103 is the next
+ for (int i = 51; i < 103; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(103));
+
+ // Then there are 3 one block ones
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(104));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(105));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(106));
+
+ // 107 -> 154 is the next
+ for (int i = 107; i < 154; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(154));
+
+ // 155 -> 160 is the next
+ for (int i = 155; i < 160; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(160));
+
+ // 161 -> 166 is the next
+ for (int i = 161; i < 166; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(166));
+
+ // 167 -> 172 is the next
+ for (int i = 167; i < 172; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(172));
+
+ // Now some short ones
+ assertEquals(174, ministore.getNextBlock(173));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(174));
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(175));
+
+ assertEquals(177, ministore.getNextBlock(176));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(177));
+
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
+
+ // 181 onwards is free
+ for (int i = 181; i < fs.getBigBlockSizeDetails().getBATEntriesPerBlock(); i++) {
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
+ }
+ }
+ fsD.close();
+ fsC.close();
+ fsB.close();
+ fsA.close();
+ }
+
+ /**
+ * Check we get the right data back for each block
+ */
+ @Test
+ public void testGetBlock() throws Exception {
+ // It's the same on 512 byte and 4096 byte block files!
+ POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ POIFSFileSystem fsC = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+ POIFSFileSystem fsD = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB, fsC, fsD}) {
+ // Mini stream should be at big block zero
+ assertEquals(0, fs._get_property_table().getRoot().getStartBlock());
+
+ // Grab the ministore
+ POIFSMiniStore ministore = fs.getMiniStore();
+ ByteBuffer b;
+
+ // Runs from the start of the data section in 64 byte chungs
+ b = ministore.getBlockAt(0);
+ assertEquals((byte) 0x9e, b.get());
+ assertEquals((byte) 0x75, b.get());
+ assertEquals((byte) 0x97, b.get());
+ assertEquals((byte) 0xf6, b.get());
+ assertEquals((byte) 0xff, b.get());
+ assertEquals((byte) 0x21, b.get());
+ assertEquals((byte) 0xd2, b.get());
+ assertEquals((byte) 0x11, b.get());
+
+ // And the next block
+ b = ministore.getBlockAt(1);
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x03, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x12, b.get());
+ assertEquals((byte) 0x02, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+
+ // Check the last data block
+ b = ministore.getBlockAt(180);
+ assertEquals((byte) 0x30, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x80, b.get());
+
+ // And the rest until the end of the big block is zeros
+ for (int i = 181; i < 184; i++) {
+ b = ministore.getBlockAt(i);
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ }
+ }
+ fsD.close();
+ fsC.close();
+ fsB.close();
+ fsA.close();
+ }
+
+ /**
+ * Ask for free blocks where there are some already
+ * to be had from the SFAT
+ */
+ @Test
+ public void testGetFreeBlockWithSpare() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ POIFSMiniStore ministore = fs.getMiniStore();
+
+ // Our 2nd SBAT block has spares
+ assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertTrue(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+
+ // First free one at 181
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(181));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(182));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(183));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(184));
+
+ // Ask, will get 181
+ assertEquals(181, ministore.getFreeBlock());
+
+ // Ask again, will still get 181 as not written to
+ assertEquals(181, ministore.getFreeBlock());
+
+ // Allocate it, then ask again
+ ministore.setNextBlock(181, POIFSConstants.END_OF_CHAIN);
+ assertEquals(182, ministore.getFreeBlock());
+
+ fs.close();
+ }
+
+ /**
+ * Ask for free blocks where no free ones exist, and so the
+ * stream needs to be extended and another SBAT added
+ */
+ @Test
+ public void testGetFreeBlockWithNoneSpare() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ POIFSMiniStore ministore = fs.getMiniStore();
+
+ // We've spare ones from 181 to 255
+ for (int i = 181; i < 256; i++) {
assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
- }
- }
- fsD.close();
- fsC.close();
- fsB.close();
- fsA.close();
- }
-
- /**
- * Check we get the right data back for each block
- */
- @Test
- public void testGetBlock() throws Exception {
- // It's the same on 512 byte and 4096 byte block files!
- POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- POIFSFileSystem fsC = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
- POIFSFileSystem fsD = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB,fsC,fsD}) {
- // Mini stream should be at big block zero
- assertEquals(0, fs._get_property_table().getRoot().getStartBlock());
-
- // Grab the ministore
- POIFSMiniStore ministore = fs.getMiniStore();
- ByteBuffer b;
-
- // Runs from the start of the data section in 64 byte chungs
- b = ministore.getBlockAt(0);
- assertEquals((byte)0x9e, b.get());
- assertEquals((byte)0x75, b.get());
- assertEquals((byte)0x97, b.get());
- assertEquals((byte)0xf6, b.get());
- assertEquals((byte)0xff, b.get());
- assertEquals((byte)0x21, b.get());
- assertEquals((byte)0xd2, b.get());
- assertEquals((byte)0x11, b.get());
-
- // And the next block
- b = ministore.getBlockAt(1);
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x03, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x12, b.get());
- assertEquals((byte)0x02, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
-
- // Check the last data block
- b = ministore.getBlockAt(180);
- assertEquals((byte)0x30, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x80, b.get());
-
- // And the rest until the end of the big block is zeros
- for(int i=181; i<184; i++) {
- b = ministore.getBlockAt(i);
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- }
- }
- fsD.close();
- fsC.close();
- fsB.close();
- fsA.close();
- }
-
- /**
- * Ask for free blocks where there are some already
- * to be had from the SFAT
- */
- @Test
- public void testGetFreeBlockWithSpare() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // Our 2nd SBAT block has spares
- assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- assertTrue(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
-
- // First free one at 181
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(181));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(182));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(183));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(184));
-
- // Ask, will get 181
- assertEquals(181, ministore.getFreeBlock());
-
- // Ask again, will still get 181 as not written to
- assertEquals(181, ministore.getFreeBlock());
-
- // Allocate it, then ask again
- ministore.setNextBlock(181, POIFSConstants.END_OF_CHAIN);
- assertEquals(182, ministore.getFreeBlock());
-
- fs.close();
- }
-
- /**
- * Ask for free blocks where no free ones exist, and so the
- * stream needs to be extended and another SBAT added
- */
- @Test
- public void testGetFreeBlockWithNoneSpare() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // We've spare ones from 181 to 255
- for(int i=181; i<256; i++) {
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
- }
-
- // Check our SBAT free stuff is correct
- assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- assertTrue(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
-
- // Allocate all the spare ones
- for(int i=181; i<256; i++) {
- ministore.setNextBlock(i, POIFSConstants.END_OF_CHAIN);
- }
-
- // SBAT are now full, but there's only the two
- assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- assertFalse(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
- try {
- assertFalse(ministore.getBATBlockAndIndex(256).getBlock().hasFreeSectors());
- fail("Should only be two SBATs");
- } catch(IndexOutOfBoundsException e) {}
-
- // Now ask for a free one, will need to extend the SBAT chain
- assertEquals(256, ministore.getFreeBlock());
-
- assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- assertFalse(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
- assertTrue(ministore.getBATBlockAndIndex(256).getBlock().hasFreeSectors());
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(254)); // 2nd SBAT
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(255)); // 2nd SBAT
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(256)); // 3rd SBAT
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(257)); // 3rd SBAT
-
- fs.close();
- }
-
- /**
- * Test that we will extend the underlying chain of
- * big blocks that make up the ministream as needed
- */
- @Test
- public void testCreateBlockIfNeeded() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // 178 -> 179 -> 180, 181+ is free
- assertEquals(179 , ministore.getNextBlock(178));
- assertEquals(180 , ministore.getNextBlock(179));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
- for(int i=181; i<256; i++) {
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
- }
-
- // However, the ministore data only covers blocks to 183
- for(int i=0; i<=183; i++) {
- ministore.getBlockAt(i);
- }
- try {
- ministore.getBlockAt(184);
- fail("No block at 184");
- } catch(NoSuchElementException e) {}
-
- // The ministore itself is made up of 23 big blocks
- Iterator<ByteBuffer> it = new POIFSStream(fs, fs.getRoot().getProperty().getStartBlock()).getBlockIterator();
- int count = 0;
- while(it.hasNext()) {
- count++;
- it.next();
- }
- assertEquals(23, count);
-
- // Ask it to get block 184 with creating, it will do
- ministore.createBlockIfNeeded(184);
-
- // The ministore should be one big block bigger now
- it = new POIFSStream(fs, fs.getRoot().getProperty().getStartBlock()).getBlockIterator();
- count = 0;
- while(it.hasNext()) {
- count++;
- it.next();
- }
- assertEquals(24, count);
-
- // The mini block block counts now run to 191
- for(int i=0; i<=191; i++) {
- ministore.getBlockAt(i);
- }
- try {
- ministore.getBlockAt(192);
- fail("No block at 192");
- } catch(NoSuchElementException e) {}
-
-
- // Now try writing through to 192, check that the SBAT and blocks are there
- byte[] data = new byte[15*64];
- POIFSStream stream = new POIFSStream(ministore, 178);
- stream.updateContents(data);
-
- // Check now
- assertEquals(179 , ministore.getNextBlock(178));
- assertEquals(180 , ministore.getNextBlock(179));
- assertEquals(181 , ministore.getNextBlock(180));
- assertEquals(182 , ministore.getNextBlock(181));
- assertEquals(183 , ministore.getNextBlock(182));
- assertEquals(184 , ministore.getNextBlock(183));
- assertEquals(185 , ministore.getNextBlock(184));
- assertEquals(186 , ministore.getNextBlock(185));
- assertEquals(187 , ministore.getNextBlock(186));
- assertEquals(188 , ministore.getNextBlock(187));
- assertEquals(189 , ministore.getNextBlock(188));
- assertEquals(190 , ministore.getNextBlock(189));
- assertEquals(191 , ministore.getNextBlock(190));
- assertEquals(192 , ministore.getNextBlock(191));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(192));
- for(int i=193; i<256; i++) {
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
- }
-
- fs.close();
- }
-
- @Test
- public void testCreateMiniStoreFirst() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem();
- POIFSMiniStore ministore = fs.getMiniStore();
- DocumentInputStream dis;
- DocumentEntry entry;
-
- // Initially has Properties + BAT but nothing else
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
- // Ministore has no blocks, so can't iterate until used
- try {
- ministore.getNextBlock(0);
- } catch (IndexOutOfBoundsException e) {}
-
- // Write a very small new document, will populate the ministore for us
- byte[] data = new byte[8];
- for (int i=0; i<data.length; i++) {
- data[i] = (byte)(i+42);
- }
- fs.getRoot().createDocument("mini", new ByteArrayInputStream(data));
-
- // Should now have a mini-fat and a mini-stream
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(1));
-
- // Re-fetch the mini store, and add it a second time
- ministore = fs.getMiniStore();
- fs.getRoot().createDocument("mini2", new ByteArrayInputStream(data));
-
- // Main unchanged, ministore has a second
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(2));
-
- // Check the data is unchanged and the right length
- entry = (DocumentEntry)fs.getRoot().getEntry("mini");
- assertEquals(data.length, entry.getSize());
- byte[] rdata = new byte[data.length];
- dis = new DocumentInputStream(entry);
- IOUtils.readFully(dis, rdata);
- assertArrayEquals(data, rdata);
- dis.close();
-
- entry = (DocumentEntry)fs.getRoot().getEntry("mini2");
- assertEquals(data.length, entry.getSize());
- rdata = new byte[data.length];
- dis = new DocumentInputStream(entry);
- IOUtils.readFully(dis, rdata);
- assertArrayEquals(data, rdata);
- dis.close();
-
- // Done
- fs.close();
- }
-
- @Test
- public void testMultiBlockStream() throws Exception {
- byte[] data1B = new byte[63];
- byte[] data2B = new byte[64+14];
- for (int i=0; i<data1B.length; i++) {
- data1B[i] = (byte)(i+2);
- }
- for (int i=0; i<data2B.length; i++) {
- data2B[i] = (byte)(i+4);
- }
-
- // New filesystem and store to use
- POIFSFileSystem fs = new POIFSFileSystem();
-
- // Initially has Properties + BAT but nothing else
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
-
- // Store the 2 block one, should use 2 mini blocks, and request
- // the use of 2 big blocks
- POIFSMiniStore ministore = fs.getMiniStore();
- fs.getRoot().createDocument("mini2", new ByteArrayInputStream(data2B));
-
- // Check
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); // SBAT
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); // Mini
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
-
- // First 2 Mini blocks will be used
- assertEquals(2, ministore.getFreeBlock());
-
- // Add one more mini-stream, and check
- fs.getRoot().createDocument("mini1", new ByteArrayInputStream(data1B));
-
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); // SBAT
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); // Mini
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
-
- // One more mini-block will be used
- assertEquals(3, ministore.getFreeBlock());
-
- // Check the contents too
- byte[] r1 = new byte[data1B.length];
- DocumentInputStream dis = fs.createDocumentInputStream("mini1");
- IOUtils.readFully(dis, r1);
- dis.close();
- assertArrayEquals(data1B, r1);
-
- byte[] r2 = new byte[data2B.length];
- dis = fs.createDocumentInputStream("mini2");
- IOUtils.readFully(dis, r2);
- dis.close();
- assertArrayEquals(data2B, r2);
- fs.close();
- }
+ }
+
+ // Check our SBAT free stuff is correct
+ assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertTrue(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+
+ // Allocate all the spare ones
+ for (int i = 181; i < 256; i++) {
+ ministore.setNextBlock(i, POIFSConstants.END_OF_CHAIN);
+ }
+
+ // SBAT are now full, but there's only the two
+ assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertFalse(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+ assertThrows(IndexOutOfBoundsException.class, () -> ministore.getBATBlockAndIndex(256), "Should only be two SBATs");
+
+ // Now ask for a free one, will need to extend the SBAT chain
+ assertEquals(256, ministore.getFreeBlock());
+
+ assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertFalse(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+ assertTrue(ministore.getBATBlockAndIndex(256).getBlock().hasFreeSectors());
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(254)); // 2nd SBAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(255)); // 2nd SBAT
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(256)); // 3rd SBAT
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(257)); // 3rd SBAT
+
+ fs.close();
+ }
+
+ /**
+ * Test that we will extend the underlying chain of
+ * big blocks that make up the ministream as needed
+ */
+ @Test
+ public void testCreateBlockIfNeeded() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ POIFSMiniStore ministore = fs.getMiniStore();
+
+ // 178 -> 179 -> 180, 181+ is free
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
+ for (int i = 181; i < 256; i++) {
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
+ }
+
+ // However, the ministore data only covers blocks to 183
+ for (int i = 0; i <= 183; i++) {
+ ministore.getBlockAt(i);
+ }
+ assertThrows(NoSuchElementException.class, () -> ministore.getBlockAt(184), "No block at 184");
+
+ // The ministore itself is made up of 23 big blocks
+ Iterator<ByteBuffer> it = new POIFSStream(fs, fs.getRoot().getProperty().getStartBlock()).getBlockIterator();
+ int count = 0;
+ while (it.hasNext()) {
+ count++;
+ it.next();
+ }
+ assertEquals(23, count);
+
+ // Ask it to get block 184 with creating, it will do
+ ministore.createBlockIfNeeded(184);
+
+ // The ministore should be one big block bigger now
+ it = new POIFSStream(fs, fs.getRoot().getProperty().getStartBlock()).getBlockIterator();
+ count = 0;
+ while (it.hasNext()) {
+ count++;
+ it.next();
+ }
+ assertEquals(24, count);
+
+ // The mini block block counts now run to 191
+ for (int i = 0; i <= 191; i++) {
+ ministore.getBlockAt(i);
+ }
+
+ assertThrows(NoSuchElementException.class, () -> ministore.getBlockAt(192), "No block at 192");
+
+ // Now try writing through to 192, check that the SBAT and blocks are there
+ byte[] data = new byte[15 * 64];
+ POIFSStream stream = new POIFSStream(ministore, 178);
+ stream.updateContents(data);
+
+ // Check now
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(181, ministore.getNextBlock(180));
+ assertEquals(182, ministore.getNextBlock(181));
+ assertEquals(183, ministore.getNextBlock(182));
+ assertEquals(184, ministore.getNextBlock(183));
+ assertEquals(185, ministore.getNextBlock(184));
+ assertEquals(186, ministore.getNextBlock(185));
+ assertEquals(187, ministore.getNextBlock(186));
+ assertEquals(188, ministore.getNextBlock(187));
+ assertEquals(189, ministore.getNextBlock(188));
+ assertEquals(190, ministore.getNextBlock(189));
+ assertEquals(191, ministore.getNextBlock(190));
+ assertEquals(192, ministore.getNextBlock(191));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(192));
+ for (int i = 193; i < 256; i++) {
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
+ }
+
+ fs.close();
+ }
+
+ @Test
+ public void testCreateMiniStoreFirst() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem();
+ POIFSMiniStore ministore = fs.getMiniStore();
+ DocumentInputStream dis;
+ DocumentEntry entry;
+
+ // Initially has Properties + BAT but nothing else
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
+ // Ministore has no blocks, so can't iterate until used
+ try {
+ ministore.getNextBlock(0);
+ } catch (IndexOutOfBoundsException e) {
+ }
+
+ // Write a very small new document, will populate the ministore for us
+ byte[] data = new byte[8];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i + 42);
+ }
+ fs.getRoot().createDocument("mini", new ByteArrayInputStream(data));
+
+ // Should now have a mini-fat and a mini-stream
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(1));
+
+ // Re-fetch the mini store, and add it a second time
+ ministore = fs.getMiniStore();
+ fs.getRoot().createDocument("mini2", new ByteArrayInputStream(data));
+
+ // Main unchanged, ministore has a second
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(2));
+
+ // Check the data is unchanged and the right length
+ entry = (DocumentEntry) fs.getRoot().getEntry("mini");
+ assertEquals(data.length, entry.getSize());
+ byte[] rdata = new byte[data.length];
+ dis = new DocumentInputStream(entry);
+ IOUtils.readFully(dis, rdata);
+ assertArrayEquals(data, rdata);
+ dis.close();
+
+ entry = (DocumentEntry) fs.getRoot().getEntry("mini2");
+ assertEquals(data.length, entry.getSize());
+ rdata = new byte[data.length];
+ dis = new DocumentInputStream(entry);
+ IOUtils.readFully(dis, rdata);
+ assertArrayEquals(data, rdata);
+ dis.close();
+
+ // Done
+ fs.close();
+ }
+
+ @Test
+ public void testMultiBlockStream() throws Exception {
+ byte[] data1B = new byte[63];
+ byte[] data2B = new byte[64 + 14];
+ for (int i = 0; i < data1B.length; i++) {
+ data1B[i] = (byte) (i + 2);
+ }
+ for (int i = 0; i < data2B.length; i++) {
+ data2B[i] = (byte) (i + 4);
+ }
+
+ // New filesystem and store to use
+ POIFSFileSystem fs = new POIFSFileSystem();
+
+ // Initially has Properties + BAT but nothing else
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
+
+ // Store the 2 block one, should use 2 mini blocks, and request
+ // the use of 2 big blocks
+ POIFSMiniStore ministore = fs.getMiniStore();
+ fs.getRoot().createDocument("mini2", new ByteArrayInputStream(data2B));
+
+ // Check
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); // SBAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); // Mini
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
+
+ // First 2 Mini blocks will be used
+ assertEquals(2, ministore.getFreeBlock());
+
+ // Add one more mini-stream, and check
+ fs.getRoot().createDocument("mini1", new ByteArrayInputStream(data1B));
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); // SBAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); // Mini
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
+
+ // One more mini-block will be used
+ assertEquals(3, ministore.getFreeBlock());
+
+ // Check the contents too
+ byte[] r1 = new byte[data1B.length];
+ DocumentInputStream dis = fs.createDocumentInputStream("mini1");
+ IOUtils.readFully(dis, r1);
+ dis.close();
+ assertArrayEquals(data1B, r1);
+
+ byte[] r2 = new byte[data2B.length];
+ dis = fs.createDocumentInputStream("mini2");
+ IOUtils.readFully(dis, r2);
+ dis.close();
+ assertArrayEquals(data2B, r2);
+ fs.close();
+ }
}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSStream.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSStream.java
index af313172a7..4803441911 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSStream.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSStream.java
@@ -20,12 +20,14 @@ package org.apache.poi.poifs.filesystem;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
-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.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -52,2803 +54,2740 @@ import org.apache.poi.poifs.storage.BATBlock;
import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.TempFile;
-import org.junit.Assume;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* Tests {@link POIFSStream}
*/
public final class TestPOIFSStream {
- private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance();
-
- /**
- * Read a single block stream
- */
- @Test
- public void testReadTinyStream() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
-
- // 98 is actually the last block in a two block stream...
- POIFSStream stream = new POIFSStream(fs, 98);
- Iterator<ByteBuffer> i = stream.getBlockIterator();
- assertTrue(i.hasNext());
- ByteBuffer b = i.next();
- assertFalse(i.hasNext());
-
- // Check the contents
- assertEquals((byte)0x81, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x82, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
-
- fs.close();
- }
-
- /**
- * Read a stream with only two blocks in it
- */
- @Test
- public void testReadShortStream() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
-
- // 97 -> 98 -> end
- POIFSStream stream = new POIFSStream(fs, 97);
- Iterator<ByteBuffer> i = stream.getBlockIterator();
- assertTrue(i.hasNext());
- ByteBuffer b97 = i.next();
- assertTrue(i.hasNext());
- ByteBuffer b98 = i.next();
- assertFalse(i.hasNext());
-
- // Check the contents of the 1st block
- assertEquals((byte)0x01, b97.get());
- assertEquals((byte)0x00, b97.get());
- assertEquals((byte)0x00, b97.get());
- assertEquals((byte)0x00, b97.get());
- assertEquals((byte)0x02, b97.get());
- assertEquals((byte)0x00, b97.get());
- assertEquals((byte)0x00, b97.get());
- assertEquals((byte)0x00, b97.get());
-
- // Check the contents of the 2nd block
- assertEquals((byte)0x81, b98.get());
- assertEquals((byte)0x00, b98.get());
- assertEquals((byte)0x00, b98.get());
- assertEquals((byte)0x00, b98.get());
- assertEquals((byte)0x82, b98.get());
- assertEquals((byte)0x00, b98.get());
- assertEquals((byte)0x00, b98.get());
- assertEquals((byte)0x00, b98.get());
-
- fs.close();
- }
-
- /**
- * Read a stream with many blocks
- */
- @Test
- public void testReadLongerStream() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
-
- ByteBuffer b0 = null;
- ByteBuffer b1 = null;
- ByteBuffer b22 = null;
-
- // The stream at 0 has 23 blocks in it
- POIFSStream stream = new POIFSStream(fs, 0);
- Iterator<ByteBuffer> i = stream.getBlockIterator();
- int count = 0;
- while(i.hasNext()) {
- ByteBuffer b = i.next();
- if(count == 0) {
- b0 = b;
- }
- if(count == 1) {
- b1 = b;
- }
- if(count == 22) {
- b22 = b;
- }
-
- count++;
- }
- assertEquals(23, count);
-
- // Check the contents
- // 1st block is at 0
- assertNotNull(b0);
- assertEquals((byte)0x9e, b0.get());
- assertEquals((byte)0x75, b0.get());
- assertEquals((byte)0x97, b0.get());
- assertEquals((byte)0xf6, b0.get());
-
- // 2nd block is at 1
- assertNotNull(b1);
- assertEquals((byte)0x86, b1.get());
- assertEquals((byte)0x09, b1.get());
- assertEquals((byte)0x22, b1.get());
- assertEquals((byte)0xfb, b1.get());
-
- // last block is at 89
- assertNotNull(b22);
- assertEquals((byte)0xfe, b22.get());
- assertEquals((byte)0xff, b22.get());
- assertEquals((byte)0x00, b22.get());
- assertEquals((byte)0x00, b22.get());
- assertEquals((byte)0x05, b22.get());
- assertEquals((byte)0x01, b22.get());
- assertEquals((byte)0x02, b22.get());
- assertEquals((byte)0x00, b22.get());
-
- fs.close();
- }
-
- /**
- * Read a stream with several blocks in a 4096 byte block file
- */
- @Test
- public void testReadStream4096() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
-
- // 0 -> 1 -> 2 -> end
- POIFSStream stream = new POIFSStream(fs, 0);
- Iterator<ByteBuffer> i = stream.getBlockIterator();
- assertTrue(i.hasNext());
- ByteBuffer b0 = i.next();
- assertTrue(i.hasNext());
- ByteBuffer b1 = i.next();
- assertTrue(i.hasNext());
- ByteBuffer b2 = i.next();
- assertFalse(i.hasNext());
-
- // Check the contents of the 1st block
- assertEquals((byte)0x9E, b0.get());
- assertEquals((byte)0x75, b0.get());
- assertEquals((byte)0x97, b0.get());
- assertEquals((byte)0xF6, b0.get());
- assertEquals((byte)0xFF, b0.get());
- assertEquals((byte)0x21, b0.get());
- assertEquals((byte)0xD2, b0.get());
- assertEquals((byte)0x11, b0.get());
-
- // Check the contents of the 2nd block
- assertEquals((byte)0x00, b1.get());
- assertEquals((byte)0x00, b1.get());
- assertEquals((byte)0x03, b1.get());
- assertEquals((byte)0x00, b1.get());
- assertEquals((byte)0x00, b1.get());
- assertEquals((byte)0x00, b1.get());
- assertEquals((byte)0x00, b1.get());
- assertEquals((byte)0x00, b1.get());
-
- // Check the contents of the 3rd block
- assertEquals((byte)0x6D, b2.get());
- assertEquals((byte)0x00, b2.get());
- assertEquals((byte)0x00, b2.get());
- assertEquals((byte)0x00, b2.get());
- assertEquals((byte)0x03, b2.get());
- assertEquals((byte)0x00, b2.get());
- assertEquals((byte)0x46, b2.get());
- assertEquals((byte)0x00, b2.get());
-
- fs.close();
- }
-
- /**
- * Craft a nasty file with a loop, and ensure we don't get stuck
- */
- @Test
- public void testReadFailsOnLoop() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
-
- // Hack the FAT so that it goes 0->1->2->0
- fs.setNextBlock(0, 1);
- fs.setNextBlock(1, 2);
- fs.setNextBlock(2, 0);
-
- // Now try to read
- POIFSStream stream = new POIFSStream(fs, 0);
- Iterator<ByteBuffer> i = stream.getBlockIterator();
- assertTrue(i.hasNext());
-
- // 1st read works
- i.next();
- assertTrue(i.hasNext());
-
- // 2nd read works
- i.next();
- assertTrue(i.hasNext());
-
- // 3rd read works
- i.next();
- assertTrue(i.hasNext());
-
- // 4th read blows up as it loops back to 0
- try {
- i.next();
- fail("Loop should have been detected but wasn't!");
- } catch(RuntimeException e) {
- // Good, it was detected
- }
- assertTrue(i.hasNext());
-
- fs.close();
- }
-
- /**
- * Tests that we can load some streams that are
- * stored in the mini stream.
- */
- @Test
- public void testReadMiniStreams() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // 178 -> 179 -> 180 -> end
- POIFSStream stream = new POIFSStream(ministore, 178);
- Iterator<ByteBuffer> i = stream.getBlockIterator();
- assertTrue(i.hasNext());
- ByteBuffer b178 = i.next();
- assertTrue(i.hasNext());
- ByteBuffer b179 = i.next();
- assertTrue(i.hasNext());
- ByteBuffer b180 = i.next();
- assertFalse(i.hasNext());
-
- // Check the contents of the 1st block
- assertEquals((byte)0xfe, b178.get());
- assertEquals((byte)0xff, b178.get());
- assertEquals((byte)0x00, b178.get());
- assertEquals((byte)0x00, b178.get());
- assertEquals((byte)0x05, b178.get());
- assertEquals((byte)0x01, b178.get());
- assertEquals((byte)0x02, b178.get());
- assertEquals((byte)0x00, b178.get());
-
- // And the 2nd
- assertEquals((byte)0x6c, b179.get());
- assertEquals((byte)0x00, b179.get());
- assertEquals((byte)0x00, b179.get());
- assertEquals((byte)0x00, b179.get());
- assertEquals((byte)0x28, b179.get());
- assertEquals((byte)0x00, b179.get());
- assertEquals((byte)0x00, b179.get());
- assertEquals((byte)0x00, b179.get());
-
- // And the 3rd
- assertEquals((byte)0x30, b180.get());
- assertEquals((byte)0x00, b180.get());
- assertEquals((byte)0x00, b180.get());
- assertEquals((byte)0x00, b180.get());
- assertEquals((byte)0x00, b180.get());
- assertEquals((byte)0x00, b180.get());
- assertEquals((byte)0x00, b180.get());
- assertEquals((byte)0x80, b180.get());
-
- fs.close();
- }
-
- /**
- * Writing the same amount of data as before
- */
- @Test
- public void testReplaceStream() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
-
- byte[] data = new byte[512];
- for(int i=0; i<data.length; i++) {
- data[i] = (byte)(i%256);
- }
-
- // 98 is actually the last block in a two block stream...
- POIFSStream stream = new POIFSStream(fs, 98);
- stream.updateContents(data);
-
- // Check the reading of blocks
- Iterator<ByteBuffer> it = stream.getBlockIterator();
- assertTrue(it.hasNext());
- ByteBuffer b = it.next();
- assertFalse(it.hasNext());
-
- // Now check the contents
- data = new byte[512];
- b.get(data);
- for(int i=0; i<data.length; i++) {
- byte exp = (byte)(i%256);
- assertEquals(exp, data[i]);
- }
-
- fs.close();
- }
-
- /**
- * Writes less data than before, some blocks will need
- * to be freed
- */
- @Test
- public void testReplaceStreamWithLess() throws Exception {
- try (InputStream is = _inst.openResourceAsStream("BlockSize512.zvi");
- POIFSFileSystem fs = new POIFSFileSystem(is)) {
-
- byte[] data = new byte[512];
- for (int i = 0; i < data.length; i++) {
- data[i] = (byte) (i % 256);
- }
-
- // 97 -> 98 -> end
- assertEquals(98, fs.getNextBlock(97));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(98));
-
- // Create a 2 block stream, will become a 1 block one
- POIFSStream stream = new POIFSStream(fs, 97);
- stream.updateContents(data);
-
- // 97 should now be the end, and 98 free
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(97));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(98));
-
- // Check the reading of blocks
- Iterator<ByteBuffer> it = stream.getBlockIterator();
- assertTrue(it.hasNext());
- ByteBuffer b = it.next();
- assertFalse(it.hasNext());
-
- // Now check the contents
- data = new byte[512];
- b.get(data);
- for (int i = 0; i < data.length; i++) {
- byte exp = (byte) (i % 256);
- assertEquals(exp, data[i]);
- }
- }
- }
-
- /**
- * Writes more data than before, new blocks will be needed
- */
- @Test
- public void testReplaceStreamWithMore() throws Exception {
- try (InputStream is = _inst.openResourceAsStream("BlockSize512.zvi");
- POIFSFileSystem fs = new POIFSFileSystem(is)) {
-
- byte[] data = new byte[512 * 3];
- for (int i = 0; i < data.length; i++) {
- data[i] = (byte) (i % 256);
- }
-
- // 97 -> 98 -> end
- assertEquals(98, fs.getNextBlock(97));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(98));
-
- // 100 is our first free one
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(100));
-
- // Create a 2 block stream, will become a 3 block one
- POIFSStream stream = new POIFSStream(fs, 97);
- stream.updateContents(data);
-
- // 97 -> 98 -> 100 -> end
- assertEquals(98, fs.getNextBlock(97));
- assertEquals(100, fs.getNextBlock(98));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(100));
-
- // Check the reading of blocks
- Iterator<ByteBuffer> it = stream.getBlockIterator();
- int count = 0;
- while (it.hasNext()) {
- ByteBuffer b = it.next();
- data = new byte[512];
- b.get(data);
- for (int i = 0; i < data.length; i++) {
- byte exp = (byte) (i % 256);
- assertEquals(exp, data[i]);
- }
- count++;
- }
- assertEquals(3, count);
- }
- }
-
- /**
- * Writes to a new stream in the file
- */
- @Test
- public void testWriteNewStream() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
-
- // 100 is our first free one
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(100));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(101));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(102));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(103));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(104));
-
-
- // Add a single block one
- byte[] data = new byte[512];
- for(int i=0; i<data.length; i++) {
- data[i] = (byte)(i%256);
- }
-
- POIFSStream stream = new POIFSStream(fs);
- stream.updateContents(data);
-
- // Check it was allocated properly
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(100));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(101));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(102));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(103));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(104));
-
- // And check the contents
- Iterator<ByteBuffer> it = stream.getBlockIterator();
- int count = 0;
- while(it.hasNext()) {
- ByteBuffer b = it.next();
- data = new byte[512];
- b.get(data);
- for(int i=0; i<data.length; i++) {
- byte exp = (byte)(i%256);
- assertEquals(exp, data[i]);
- }
- count++;
- }
- assertEquals(1, count);
-
-
- // And a multi block one
- data = new byte[512*3];
- for(int i=0; i<data.length; i++) {
- data[i] = (byte)(i%256);
- }
-
- stream = new POIFSStream(fs);
- stream.updateContents(data);
-
- // Check it was allocated properly
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(100));
- assertEquals(102, fs.getNextBlock(101));
- assertEquals(103, fs.getNextBlock(102));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(103));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(104));
-
- // And check the contents
- it = stream.getBlockIterator();
- count = 0;
- while(it.hasNext()) {
- ByteBuffer b = it.next();
- data = new byte[512];
- b.get(data);
- for(int i=0; i<data.length; i++) {
- byte exp = (byte)(i%256);
- assertEquals(exp, data[i]);
- }
- count++;
- }
- assertEquals(3, count);
-
- // Free it
- stream.free();
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(100));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(101));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(102));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(103));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(104));
-
- fs.close();
- }
-
- /**
- * Writes to a new stream in the file, where we've not enough
- * free blocks so new FAT segments will need to be allocated
- * to support this
- */
- @Test
- public void testWriteNewStreamExtraFATs() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
-
- // Allocate almost all the blocks
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(100));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(127));
- for(int i=100; i<127; i++) {
- fs.setNextBlock(i, POIFSConstants.END_OF_CHAIN);
- }
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(127));
- assertTrue(fs.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
-
-
- // Write a 3 block stream
- byte[] data = new byte[512*3];
- for(int i=0; i<data.length; i++) {
- data[i] = (byte)(i%256);
- }
- POIFSStream stream = new POIFSStream(fs);
- stream.updateContents(data);
-
- // Check we got another BAT
- assertFalse(fs.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- assertTrue(fs.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
-
- // the BAT will be in the first spot of the new block
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(126));
- assertEquals(129, fs.getNextBlock(127));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(128));
- assertEquals(130, fs.getNextBlock(129));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(130));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(131));
-
- fs.close();
- }
-
- /**
- * Replaces data in an existing stream, with a bit
- * more data than before, in a 4096 byte block file
- */
- @Test
- public void testWriteStream4096() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
-
- // 0 -> 1 -> 2 -> end
- assertEquals(1, fs.getNextBlock(0));
- assertEquals(2, fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
- assertEquals(4, fs.getNextBlock(3));
-
- // First free one is at 15
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(14));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(15));
-
-
- // Write a 5 block file
- byte[] data = new byte[4096*5];
- for(int i=0; i<data.length; i++) {
- data[i] = (byte)(i%256);
- }
- POIFSStream stream = new POIFSStream(fs, 0);
- stream.updateContents(data);
-
-
- // Check it
- assertEquals(1, fs.getNextBlock(0));
- assertEquals(2, fs.getNextBlock(1));
- assertEquals(15, fs.getNextBlock(2)); // Jumps
- assertEquals(4, fs.getNextBlock(3)); // Next stream
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(14));
- assertEquals(16, fs.getNextBlock(15)); // Continues
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(16)); // Ends
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(17)); // Free
-
- // Check the contents too
- Iterator<ByteBuffer> it = stream.getBlockIterator();
- int count = 0;
- while(it.hasNext()) {
- ByteBuffer b = it.next();
- data = new byte[512];
- b.get(data);
- for(int i=0; i<data.length; i++) {
- byte exp = (byte)(i%256);
+ private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance();
+
+ /**
+ * Read a single block stream
+ */
+ @Test
+ public void testReadTinyStream() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+
+ // 98 is actually the last block in a two block stream...
+ POIFSStream stream = new POIFSStream(fs, 98);
+ Iterator<ByteBuffer> i = stream.getBlockIterator();
+ assertTrue(i.hasNext());
+ ByteBuffer b = i.next();
+ assertFalse(i.hasNext());
+
+ // Check the contents
+ assertEquals((byte) 0x81, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x82, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+
+ fs.close();
+ }
+
+ /**
+ * Read a stream with only two blocks in it
+ */
+ @Test
+ public void testReadShortStream() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+
+ // 97 -> 98 -> end
+ POIFSStream stream = new POIFSStream(fs, 97);
+ Iterator<ByteBuffer> i = stream.getBlockIterator();
+ assertTrue(i.hasNext());
+ ByteBuffer b97 = i.next();
+ assertTrue(i.hasNext());
+ ByteBuffer b98 = i.next();
+ assertFalse(i.hasNext());
+
+ // Check the contents of the 1st block
+ assertEquals((byte) 0x01, b97.get());
+ assertEquals((byte) 0x00, b97.get());
+ assertEquals((byte) 0x00, b97.get());
+ assertEquals((byte) 0x00, b97.get());
+ assertEquals((byte) 0x02, b97.get());
+ assertEquals((byte) 0x00, b97.get());
+ assertEquals((byte) 0x00, b97.get());
+ assertEquals((byte) 0x00, b97.get());
+
+ // Check the contents of the 2nd block
+ assertEquals((byte) 0x81, b98.get());
+ assertEquals((byte) 0x00, b98.get());
+ assertEquals((byte) 0x00, b98.get());
+ assertEquals((byte) 0x00, b98.get());
+ assertEquals((byte) 0x82, b98.get());
+ assertEquals((byte) 0x00, b98.get());
+ assertEquals((byte) 0x00, b98.get());
+ assertEquals((byte) 0x00, b98.get());
+
+ fs.close();
+ }
+
+ /**
+ * Read a stream with many blocks
+ */
+ @Test
+ public void testReadLongerStream() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+
+ ByteBuffer b0 = null;
+ ByteBuffer b1 = null;
+ ByteBuffer b22 = null;
+
+ // The stream at 0 has 23 blocks in it
+ POIFSStream stream = new POIFSStream(fs, 0);
+ Iterator<ByteBuffer> i = stream.getBlockIterator();
+ int count = 0;
+ while (i.hasNext()) {
+ ByteBuffer b = i.next();
+ if (count == 0) {
+ b0 = b;
+ }
+ if (count == 1) {
+ b1 = b;
+ }
+ if (count == 22) {
+ b22 = b;
+ }
+
+ count++;
+ }
+ assertEquals(23, count);
+
+ // Check the contents
+ // 1st block is at 0
+ assertNotNull(b0);
+ assertEquals((byte) 0x9e, b0.get());
+ assertEquals((byte) 0x75, b0.get());
+ assertEquals((byte) 0x97, b0.get());
+ assertEquals((byte) 0xf6, b0.get());
+
+ // 2nd block is at 1
+ assertNotNull(b1);
+ assertEquals((byte) 0x86, b1.get());
+ assertEquals((byte) 0x09, b1.get());
+ assertEquals((byte) 0x22, b1.get());
+ assertEquals((byte) 0xfb, b1.get());
+
+ // last block is at 89
+ assertNotNull(b22);
+ assertEquals((byte) 0xfe, b22.get());
+ assertEquals((byte) 0xff, b22.get());
+ assertEquals((byte) 0x00, b22.get());
+ assertEquals((byte) 0x00, b22.get());
+ assertEquals((byte) 0x05, b22.get());
+ assertEquals((byte) 0x01, b22.get());
+ assertEquals((byte) 0x02, b22.get());
+ assertEquals((byte) 0x00, b22.get());
+
+ fs.close();
+ }
+
+ /**
+ * Read a stream with several blocks in a 4096 byte block file
+ */
+ @Test
+ public void testReadStream4096() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+
+ // 0 -> 1 -> 2 -> end
+ POIFSStream stream = new POIFSStream(fs, 0);
+ Iterator<ByteBuffer> i = stream.getBlockIterator();
+ assertTrue(i.hasNext());
+ ByteBuffer b0 = i.next();
+ assertTrue(i.hasNext());
+ ByteBuffer b1 = i.next();
+ assertTrue(i.hasNext());
+ ByteBuffer b2 = i.next();
+ assertFalse(i.hasNext());
+
+ // Check the contents of the 1st block
+ assertEquals((byte) 0x9E, b0.get());
+ assertEquals((byte) 0x75, b0.get());
+ assertEquals((byte) 0x97, b0.get());
+ assertEquals((byte) 0xF6, b0.get());
+ assertEquals((byte) 0xFF, b0.get());
+ assertEquals((byte) 0x21, b0.get());
+ assertEquals((byte) 0xD2, b0.get());
+ assertEquals((byte) 0x11, b0.get());
+
+ // Check the contents of the 2nd block
+ assertEquals((byte) 0x00, b1.get());
+ assertEquals((byte) 0x00, b1.get());
+ assertEquals((byte) 0x03, b1.get());
+ assertEquals((byte) 0x00, b1.get());
+ assertEquals((byte) 0x00, b1.get());
+ assertEquals((byte) 0x00, b1.get());
+ assertEquals((byte) 0x00, b1.get());
+ assertEquals((byte) 0x00, b1.get());
+
+ // Check the contents of the 3rd block
+ assertEquals((byte) 0x6D, b2.get());
+ assertEquals((byte) 0x00, b2.get());
+ assertEquals((byte) 0x00, b2.get());
+ assertEquals((byte) 0x00, b2.get());
+ assertEquals((byte) 0x03, b2.get());
+ assertEquals((byte) 0x00, b2.get());
+ assertEquals((byte) 0x46, b2.get());
+ assertEquals((byte) 0x00, b2.get());
+
+ fs.close();
+ }
+
+ /**
+ * Craft a nasty file with a loop, and ensure we don't get stuck
+ */
+ @Test
+ public void testReadFailsOnLoop() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+
+ // Hack the FAT so that it goes 0->1->2->0
+ fs.setNextBlock(0, 1);
+ fs.setNextBlock(1, 2);
+ fs.setNextBlock(2, 0);
+
+ // Now try to read
+ POIFSStream stream = new POIFSStream(fs, 0);
+ Iterator<ByteBuffer> i = stream.getBlockIterator();
+ assertTrue(i.hasNext());
+
+ // 1st read works
+ i.next();
+ assertTrue(i.hasNext());
+
+ // 2nd read works
+ i.next();
+ assertTrue(i.hasNext());
+
+ // 3rd read works
+ i.next();
+ assertTrue(i.hasNext());
+
+ // 4th read blows up as it loops back to 0
+ assertThrows(RuntimeException.class, i::next, "Loop should have been detected but wasn't!");
+ assertTrue(i.hasNext());
+
+ fs.close();
+ }
+
+ /**
+ * Tests that we can load some streams that are
+ * stored in the mini stream.
+ */
+ @Test
+ public void testReadMiniStreams() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ POIFSMiniStore ministore = fs.getMiniStore();
+
+ // 178 -> 179 -> 180 -> end
+ POIFSStream stream = new POIFSStream(ministore, 178);
+ Iterator<ByteBuffer> i = stream.getBlockIterator();
+ assertTrue(i.hasNext());
+ ByteBuffer b178 = i.next();
+ assertTrue(i.hasNext());
+ ByteBuffer b179 = i.next();
+ assertTrue(i.hasNext());
+ ByteBuffer b180 = i.next();
+ assertFalse(i.hasNext());
+
+ // Check the contents of the 1st block
+ assertEquals((byte) 0xfe, b178.get());
+ assertEquals((byte) 0xff, b178.get());
+ assertEquals((byte) 0x00, b178.get());
+ assertEquals((byte) 0x00, b178.get());
+ assertEquals((byte) 0x05, b178.get());
+ assertEquals((byte) 0x01, b178.get());
+ assertEquals((byte) 0x02, b178.get());
+ assertEquals((byte) 0x00, b178.get());
+
+ // And the 2nd
+ assertEquals((byte) 0x6c, b179.get());
+ assertEquals((byte) 0x00, b179.get());
+ assertEquals((byte) 0x00, b179.get());
+ assertEquals((byte) 0x00, b179.get());
+ assertEquals((byte) 0x28, b179.get());
+ assertEquals((byte) 0x00, b179.get());
+ assertEquals((byte) 0x00, b179.get());
+ assertEquals((byte) 0x00, b179.get());
+
+ // And the 3rd
+ assertEquals((byte) 0x30, b180.get());
+ assertEquals((byte) 0x00, b180.get());
+ assertEquals((byte) 0x00, b180.get());
+ assertEquals((byte) 0x00, b180.get());
+ assertEquals((byte) 0x00, b180.get());
+ assertEquals((byte) 0x00, b180.get());
+ assertEquals((byte) 0x00, b180.get());
+ assertEquals((byte) 0x80, b180.get());
+
+ fs.close();
+ }
+
+ /**
+ * Writing the same amount of data as before
+ */
+ @Test
+ public void testReplaceStream() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+
+ byte[] data = new byte[512];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i % 256);
+ }
+
+ // 98 is actually the last block in a two block stream...
+ POIFSStream stream = new POIFSStream(fs, 98);
+ stream.updateContents(data);
+
+ // Check the reading of blocks
+ Iterator<ByteBuffer> it = stream.getBlockIterator();
+ assertTrue(it.hasNext());
+ ByteBuffer b = it.next();
+ assertFalse(it.hasNext());
+
+ // Now check the contents
+ data = new byte[512];
+ b.get(data);
+ for (int i = 0; i < data.length; i++) {
+ byte exp = (byte) (i % 256);
assertEquals(exp, data[i]);
- }
- count++;
- }
- assertEquals(5, count);
-
- fs.close();
- }
-
- /**
- * Tests that we can write into the mini stream
- */
- @Test
- public void testWriteMiniStreams() throws Exception {
- try (InputStream is = _inst.openResourceAsStream("BlockSize512.zvi");
- POIFSFileSystem fs = new POIFSFileSystem(is)) {
-
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // 178 -> 179 -> 180 -> end
- assertEquals(179, ministore.getNextBlock(178));
- assertEquals(180, ministore.getNextBlock(179));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
-
-
- // Try writing 3 full blocks worth
- byte[] data = new byte[64 * 3];
- for (int i = 0; i < data.length; i++) {
- data[i] = (byte) i;
- }
- POIFSStream stream = new POIFSStream(ministore, 178);
- stream.updateContents(data);
-
- // Check
- assertEquals(179, ministore.getNextBlock(178));
- assertEquals(180, ministore.getNextBlock(179));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
-
- stream = new POIFSStream(ministore, 178);
- Iterator<ByteBuffer> it = stream.getBlockIterator();
- ByteBuffer b178 = it.next();
- ByteBuffer b179 = it.next();
- ByteBuffer b180 = it.next();
- assertFalse(it.hasNext());
-
- assertEquals((byte) 0x00, b178.get());
- assertEquals((byte) 0x01, b178.get());
- assertEquals((byte) 0x40, b179.get());
- assertEquals((byte) 0x41, b179.get());
- assertEquals((byte) 0x80, b180.get());
- assertEquals((byte) 0x81, b180.get());
-
-
- // Try writing just into 3 blocks worth
- data = new byte[64 * 2 + 12];
- for (int i = 0; i < data.length; i++) {
- data[i] = (byte) (i + 4);
- }
- stream = new POIFSStream(ministore, 178);
- stream.updateContents(data);
-
- // Check
- assertEquals(179, ministore.getNextBlock(178));
- assertEquals(180, ministore.getNextBlock(179));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
-
- stream = new POIFSStream(ministore, 178);
- it = stream.getBlockIterator();
- b178 = it.next();
- b179 = it.next();
- b180 = it.next();
- assertFalse(it.hasNext());
-
- assertEquals((byte) 0x04, b178.get(0));
- assertEquals((byte) 0x05, b178.get(1));
- assertEquals((byte) 0x44, b179.get(0));
- assertEquals((byte) 0x45, b179.get(1));
- assertEquals((byte) 0x84, b180.get(0));
- assertEquals((byte) 0x85, b180.get(1));
-
-
- // Try writing 1, should truncate
- data = new byte[12];
- for (int i = 0; i < data.length; i++) {
- data[i] = (byte) (i + 9);
- }
- stream = new POIFSStream(ministore, 178);
- stream.updateContents(data);
-
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(178));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(179));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(180));
-
- stream = new POIFSStream(ministore, 178);
- it = stream.getBlockIterator();
- b178 = it.next();
- assertFalse(it.hasNext());
-
- assertEquals((byte) 0x09, b178.get(0));
- assertEquals((byte) 0x0a, b178.get(1));
-
-
- // Try writing 5, should extend
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(178));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(179));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(180));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(181));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(182));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(183));
-
- data = new byte[64 * 4 + 12];
- for (int i = 0; i < data.length; i++) {
- data[i] = (byte) (i + 3);
- }
- stream = new POIFSStream(ministore, 178);
- stream.updateContents(data);
-
- assertEquals(179, ministore.getNextBlock(178));
- assertEquals(180, ministore.getNextBlock(179));
- assertEquals(181, ministore.getNextBlock(180));
- assertEquals(182, ministore.getNextBlock(181));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(182));
-
- stream = new POIFSStream(ministore, 178);
- it = stream.getBlockIterator();
- b178 = it.next();
- b179 = it.next();
- b180 = it.next();
- ByteBuffer b181 = it.next();
- ByteBuffer b182 = it.next();
- assertFalse(it.hasNext());
-
- assertEquals((byte) 0x03, b178.get(0));
- assertEquals((byte) 0x04, b178.get(1));
- assertEquals((byte) 0x43, b179.get(0));
- assertEquals((byte) 0x44, b179.get(1));
- assertEquals((byte) 0x83, b180.get(0));
- assertEquals((byte) 0x84, b180.get(1));
- assertEquals((byte) 0xc3, b181.get(0));
- assertEquals((byte) 0xc4, b181.get(1));
- assertEquals((byte) 0x03, b182.get(0));
- assertEquals((byte) 0x04, b182.get(1));
-
-
- // Write lots, so it needs another big block
- ministore.getBlockAt(183);
- try {
- ministore.getBlockAt(184);
- fail("Block 184 should be off the end of the list");
- } catch (NoSuchElementException e) {
- }
-
- data = new byte[64 * 6 + 12];
- for (int i = 0; i < data.length; i++) {
- data[i] = (byte) (i + 1);
- }
- stream = new POIFSStream(ministore, 178);
- stream.updateContents(data);
-
- // Should have added 2 more blocks to the chain
- assertEquals(179, ministore.getNextBlock(178));
- assertEquals(180, ministore.getNextBlock(179));
- assertEquals(181, ministore.getNextBlock(180));
- assertEquals(182, ministore.getNextBlock(181));
- assertEquals(183, ministore.getNextBlock(182));
- assertEquals(184, ministore.getNextBlock(183));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(184));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(185));
-
- // Block 184 should exist
- ministore.getBlockAt(183);
- ministore.getBlockAt(184);
- ministore.getBlockAt(185);
-
- // Check contents
- stream = new POIFSStream(ministore, 178);
- it = stream.getBlockIterator();
- b178 = it.next();
- b179 = it.next();
- b180 = it.next();
- b181 = it.next();
- b182 = it.next();
- ByteBuffer b183 = it.next();
- ByteBuffer b184 = it.next();
- assertFalse(it.hasNext());
-
- assertEquals((byte) 0x01, b178.get(0));
- assertEquals((byte) 0x02, b178.get(1));
- assertEquals((byte) 0x41, b179.get(0));
- assertEquals((byte) 0x42, b179.get(1));
- assertEquals((byte) 0x81, b180.get(0));
- assertEquals((byte) 0x82, b180.get(1));
- assertEquals((byte) 0xc1, b181.get(0));
- assertEquals((byte) 0xc2, b181.get(1));
- assertEquals((byte) 0x01, b182.get(0));
- assertEquals((byte) 0x02, b182.get(1));
- assertEquals((byte) 0x41, b183.get(0));
- assertEquals((byte) 0x42, b183.get(1));
- assertEquals((byte) 0x81, b184.get(0));
- assertEquals((byte) 0x82, b184.get(1));
-
- }
- }
-
- /**
- * Craft a nasty file with a loop, and ensure we don't get stuck
- */
- @Test
- public void testWriteFailsOnLoop() throws Exception {
- try (POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"))) {
-
- // Hack the FAT so that it goes 0->1->2->0
- fs.setNextBlock(0, 1);
- fs.setNextBlock(1, 2);
- fs.setNextBlock(2, 0);
-
- // Try to write a large amount, should fail on the write
- byte[] data = new byte[512 * 4];
- POIFSStream stream = new POIFSStream(fs, 0);
- try {
- stream.updateContents(data);
- fail("Loop should have been detected but wasn't!");
- } catch (IllegalStateException e) {
- }
-
- // Now reset, and try on a small bit
- // Should fail during the freeing set
- fs.setNextBlock(0, 1);
- fs.setNextBlock(1, 2);
- fs.setNextBlock(2, 0);
-
- data = new byte[512];
- stream = new POIFSStream(fs, 0);
- try {
- stream.updateContents(data);
- fail("Loop should have been detected but wasn't!");
- } catch (IllegalStateException e) {
- }
- }
- }
-
- /**
- * Tests adding a new stream, writing and reading it.
- */
- @Test
- public void testReadWriteNewStream() throws Exception {
- try (POIFSFileSystem fs = new POIFSFileSystem()) {
- POIFSStream stream = new POIFSStream(fs);
-
- // Check our filesystem has Properties then BAT
- assertEquals(2, fs.getFreeBlock());
- BATBlock bat = fs.getBATBlockAndIndex(0).getBlock();
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(2));
-
- // Check the stream as-is
- assertEquals(POIFSConstants.END_OF_CHAIN, stream.getStartBlock());
- try {
- stream.getBlockIterator();
- fail("Shouldn't be able to get an iterator before writing");
- } catch (IllegalStateException e) {
- }
-
- // Write in two blocks
- byte[] data = new byte[512 + 20];
- for (int i = 0; i < 512; i++) {
- data[i] = (byte) (i % 256);
- }
- for (int i = 512; i < data.length; i++) {
- data[i] = (byte) (i % 256 + 100);
- }
- stream.updateContents(data);
-
- // Check now
- assertEquals(4, fs.getFreeBlock());
- bat = fs.getBATBlockAndIndex(0).getBlock();
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
- assertEquals(3, bat.getValueAt(2));
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(4));
-
-
- Iterator<ByteBuffer> it = stream.getBlockIterator();
- assertTrue(it.hasNext());
- ByteBuffer b = it.next();
-
- byte[] read = new byte[512];
- b.get(read);
- for (int i = 0; i < read.length; i++) {
- assertEquals("Wrong value at " + i, data[i], read[i]);
- }
-
- assertTrue(it.hasNext());
- b = it.next();
-
- read = new byte[512];
- b.get(read);
- for (int i = 0; i < 20; i++) {
- assertEquals(data[i + 512], read[i]);
- }
- for (int i = 20; i < read.length; i++) {
- assertEquals(0, read[i]);
- }
-
- assertFalse(it.hasNext());
- }
- }
-
- /**
- * Writes a stream, then replaces it
- */
- @Test
- public void testWriteThenReplace() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem();
-
- // Starts empty, other that Properties and BAT
- BATBlock bat = fs.getBATBlockAndIndex(0).getBlock();
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(2));
-
- // Write something that uses a main stream
- byte[] main4106 = new byte[4106];
- main4106[0] = -10;
- main4106[4105] = -11;
- fs.getRoot().createDocument("Normal", new ByteArrayInputStream(main4106));
-
- // Should have used 9 blocks
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
- assertEquals(3, bat.getValueAt(2));
- assertEquals(4, bat.getValueAt(3));
- assertEquals(5, bat.getValueAt(4));
- assertEquals(6, bat.getValueAt(5));
- assertEquals(7, bat.getValueAt(6));
- assertEquals(8, bat.getValueAt(7));
- assertEquals(9, bat.getValueAt(8));
- assertEquals(10, bat.getValueAt(9));
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(10));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
-
- DocumentEntry normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
- assertEquals(4106, normal.getSize());
- assertEquals(4106, ((DocumentNode)normal).getProperty().getSize());
-
-
- // Replace with one still big enough for a main stream, but one block smaller
- byte[] main4096 = new byte[4096];
- main4096[0] = -10;
- main4096[4095] = -11;
-
- DocumentOutputStream nout = new DocumentOutputStream(normal);
- nout.write(main4096);
- nout.close();
-
- // Will have dropped to 8
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
- assertEquals(3, bat.getValueAt(2));
- assertEquals(4, bat.getValueAt(3));
- assertEquals(5, bat.getValueAt(4));
- assertEquals(6, bat.getValueAt(5));
- assertEquals(7, bat.getValueAt(6));
- assertEquals(8, bat.getValueAt(7));
- assertEquals(9, bat.getValueAt(8));
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(9));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(10));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
-
- normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
- assertEquals(4096, normal.getSize());
- assertEquals(4096, ((DocumentNode)normal).getProperty().getSize());
-
-
- // Write and check
- fs = writeOutAndReadBack(fs);
- bat = fs.getBATBlockAndIndex(0).getBlock();
-
- // No change after write
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0)); // Properties
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
- assertEquals(3, bat.getValueAt(2));
- assertEquals(4, bat.getValueAt(3));
- assertEquals(5, bat.getValueAt(4));
- assertEquals(6, bat.getValueAt(5));
- assertEquals(7, bat.getValueAt(6));
- assertEquals(8, bat.getValueAt(7));
- assertEquals(9, bat.getValueAt(8));
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(9)); // End of Normal
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(10));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
-
- normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
- assertEquals(4096, normal.getSize());
- assertEquals(4096, ((DocumentNode)normal).getProperty().getSize());
-
-
- // Make longer, take 1 block at the end
- normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
- nout = new DocumentOutputStream(normal);
- nout.write(main4106);
- nout.close();
-
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
- assertEquals(3, bat.getValueAt(2));
- assertEquals(4, bat.getValueAt(3));
- assertEquals(5, bat.getValueAt(4));
- assertEquals(6, bat.getValueAt(5));
- assertEquals(7, bat.getValueAt(6));
- assertEquals(8, bat.getValueAt(7));
- assertEquals(9, bat.getValueAt(8));
- assertEquals(10, bat.getValueAt(9));
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(10)); // Normal
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
-
- normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
- assertEquals(4106, normal.getSize());
- assertEquals(4106, ((DocumentNode)normal).getProperty().getSize());
-
-
- // Make it small, will trigger the SBAT stream and free lots up
- byte[] mini = new byte[] { 42, 0, 1, 2, 3, 4, 42 };
- normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
- nout = new DocumentOutputStream(normal);
- nout.write(mini);
- nout.close();
-
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(2)); // SBAT
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3)); // Mini Stream
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(4));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(5));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(6));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(7));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(8));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(9));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(10));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
-
- normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
- assertEquals(7, normal.getSize());
- assertEquals(7, ((DocumentNode)normal).getProperty().getSize());
-
-
- // Finally back to big again
- nout = new DocumentOutputStream(normal);
- nout.write(main4096);
- nout.close();
-
- // Will keep the mini stream, now empty
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(2)); // SBAT
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3)); // Mini Stream
- assertEquals(5, bat.getValueAt(4));
- assertEquals(6, bat.getValueAt(5));
- assertEquals(7, bat.getValueAt(6));
- assertEquals(8, bat.getValueAt(7));
- assertEquals(9, bat.getValueAt(8));
- assertEquals(10, bat.getValueAt(9));
- assertEquals(11, bat.getValueAt(10));
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(11));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(13));
-
- normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
- assertEquals(4096, normal.getSize());
- assertEquals(4096, ((DocumentNode)normal).getProperty().getSize());
-
-
- // Save, re-load, re-check
- fs = writeOutAndReadBack(fs);
- bat = fs.getBATBlockAndIndex(0).getBlock();
-
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(2)); // SBAT
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3)); // Mini Stream
- assertEquals(5, bat.getValueAt(4));
- assertEquals(6, bat.getValueAt(5));
- assertEquals(7, bat.getValueAt(6));
- assertEquals(8, bat.getValueAt(7));
- assertEquals(9, bat.getValueAt(8));
- assertEquals(10, bat.getValueAt(9));
- assertEquals(11, bat.getValueAt(10));
- assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(11));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
- assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(13));
-
- normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
- assertEquals(4096, normal.getSize());
- assertEquals(4096, ((DocumentNode)normal).getProperty().getSize());
-
- fs.close();
- }
-
-
- /**
- * Returns test files with 512 byte and 4k block sizes, loaded
- * both from InputStreams and Files
- */
- private POIFSFileSystem[] get512and4kFileAndInput() throws IOException {
- POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- POIFSFileSystem fsC = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
- POIFSFileSystem fsD = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
- return new POIFSFileSystem[] {fsA,fsB,fsC,fsD};
- }
-
- private static void assertBATCount(POIFSFileSystem fs, int expectedBAT, int expectedXBAT) throws IOException {
- int foundBAT = 0;
- int foundXBAT = 0;
- int sz = (int)(fs.size() / fs.getBigBlockSize());
- for (int i=0; i<sz; i++) {
- if(fs.getNextBlock(i) == POIFSConstants.FAT_SECTOR_BLOCK) {
- foundBAT++;
- }
- if(fs.getNextBlock(i) == POIFSConstants.DIFAT_SECTOR_BLOCK) {
- foundXBAT++;
- }
- }
- assertEquals("Wrong number of BATs", expectedBAT, foundBAT);
- assertEquals("Wrong number of XBATs with " + expectedBAT + " BATs", expectedXBAT, foundXBAT);
- }
- private void assertContentsMatches(byte[] expected, DocumentEntry doc) throws IOException {
- DocumentInputStream inp = new DocumentInputStream(doc);
- byte[] contents = new byte[doc.getSize()];
- assertEquals(doc.getSize(), inp.read(contents));
- inp.close();
-
- if (expected != null) {
- assertThat(expected, equalTo(contents));
- }
- }
-
- private static HeaderBlock writeOutAndReadHeader(POIFSFileSystem fs) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- fs.writeFilesystem(baos);
-
- return new HeaderBlock(new ByteArrayInputStream(baos.toByteArray()));
- }
-
- private static POIFSFileSystem writeOutAndReadBack(POIFSFileSystem original) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- original.writeFilesystem(baos);
- return new POIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
- }
-
- private static POIFSFileSystem writeOutFileAndReadBack(POIFSFileSystem original) throws IOException {
- final File file = TempFile.createTempFile("TestPOIFS", ".ole2");
- try (OutputStream fout = new FileOutputStream(file)) {
- original.writeFilesystem(fout);
- }
- return new POIFSFileSystem(file, false);
- }
-
- @Test
- public void basicOpen() throws IOException {
- POIFSFileSystem fsA, fsB;
-
- // With a simple 512 block file
- fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB}) {
- assertEquals(512, fs.getBigBlockSize());
- }
- fsA.close();
- fsB.close();
-
- // Now with a simple 4096 block file
- fsA = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
- fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB}) {
- assertEquals(4096, fs.getBigBlockSize());
- }
- fsA.close();
- fsB.close();
- }
-
- @Test
- public void propertiesAndFatOnRead() throws IOException {
- POIFSFileSystem fsA, fsB;
-
- // With a simple 512 block file
- fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB}) {
- // Check the FAT was properly processed:
- // Verify we only got one block
- fs.getBATBlockAndIndex(0);
- fs.getBATBlockAndIndex(1);
- try {
- fs.getBATBlockAndIndex(140);
- fail("Should only be one BAT, but a 2nd was found");
- } catch(IndexOutOfBoundsException e) {
- // expected here
- }
-
- // Verify a few next offsets
- // 97 -> 98 -> END
- assertEquals(98, fs.getNextBlock(97));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(98));
-
-
- // Check the properties
- PropertyTable props = fs._get_property_table();
- assertEquals(90, props.getStartBlock());
- assertEquals(7, props.countBlocks());
-
- // Root property tells us about the Mini Stream
- RootProperty root = props.getRoot();
- assertEquals("Root Entry", root.getName());
- assertEquals(11564, root.getSize());
- assertEquals(0, root.getStartBlock());
-
- // Check its children too
- Property prop;
- Iterator<Property> pi = root.getChildren();
- prop = pi.next();
- assertEquals("Thumbnail", prop.getName());
- prop = pi.next();
- assertEquals("\u0005DocumentSummaryInformation", prop.getName());
- prop = pi.next();
- assertEquals("\u0005SummaryInformation", prop.getName());
- prop = pi.next();
- assertEquals("Image", prop.getName());
- prop = pi.next();
- assertEquals("Tags", prop.getName());
- assertFalse(pi.hasNext());
-
-
- // Check the SBAT (Small Blocks FAT) was properly processed
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // Verify we only got two SBAT blocks
- ministore.getBATBlockAndIndex(0);
- ministore.getBATBlockAndIndex(128);
- try {
- ministore.getBATBlockAndIndex(256);
- fail("Should only be two SBATs, but a 3rd was found");
- } catch(IndexOutOfBoundsException e) {
- // expected here
- }
-
- // Verify a few offsets: 0->50 is a stream
- for(int i=0; i<50; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(50));
-
- fs.close();
- }
-
- // Now with a simple 4096 block file
- fsA = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
- fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB}) {
- // Check the FAT was properly processed
- // Verify we only got one block
- fs.getBATBlockAndIndex(0);
- fs.getBATBlockAndIndex(1);
- try {
- fs.getBATBlockAndIndex(1040);
- fail("Should only be one BAT, but a 2nd was found");
- } catch(IndexOutOfBoundsException e) {
- // expected here
- }
-
- // Verify a few next offsets
- // 0 -> 1 -> 2 -> END
- assertEquals(1, fs.getNextBlock(0));
- assertEquals(2, fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
-
-
- // Check the properties
- PropertyTable props = fs._get_property_table();
- assertEquals(12, props.getStartBlock());
- assertEquals(1, props.countBlocks());
-
- // Root property tells us about the Mini Stream
- RootProperty root = props.getRoot();
- assertEquals("Root Entry", root.getName());
- assertEquals(11564, root.getSize());
- assertEquals(0, root.getStartBlock());
-
- // Check its children too
- Property prop;
- Iterator<Property> pi = root.getChildren();
- prop = pi.next();
- assertEquals("Thumbnail", prop.getName());
- prop = pi.next();
- assertEquals("\u0005DocumentSummaryInformation", prop.getName());
- prop = pi.next();
- assertEquals("\u0005SummaryInformation", prop.getName());
- prop = pi.next();
- assertEquals("Image", prop.getName());
- prop = pi.next();
- assertEquals("Tags", prop.getName());
- assertFalse(pi.hasNext());
-
-
- // Check the SBAT (Small Blocks FAT) was properly processed
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // Verify we only got one SBAT block
- ministore.getBATBlockAndIndex(0);
- ministore.getBATBlockAndIndex(128);
- ministore.getBATBlockAndIndex(1023);
- try {
- ministore.getBATBlockAndIndex(1024);
- fail("Should only be one SBAT, but a 2nd was found");
- } catch(IndexOutOfBoundsException e) {
- // expected here
- }
-
- // Verify a few offsets: 0->50 is a stream
- for(int i=0; i<50; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(50));
-
- fs.close();
- }
- }
-
- /**
- * Check that for a given block, we can correctly figure
- * out what the next one is
- */
- @Test
- public void nextBlock() throws IOException {
- POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB}) {
- // 0 -> 21 are simple
- for(int i=0; i<21; i++) {
- assertEquals(i+1, fs.getNextBlock(i));
- }
- // 21 jumps to 89, then ends
- assertEquals(89, fs.getNextBlock(21));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(89));
-
- // 22 -> 88 simple sequential stream
- for(int i=22; i<88; i++) {
- assertEquals(i+1, fs.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(88));
-
- // 90 -> 96 is another stream
- for(int i=90; i<96; i++) {
- assertEquals(i+1, fs.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(96));
-
- // 97+98 is another
- assertEquals(98, fs.getNextBlock(97));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(98));
-
- // 99 is our FAT block
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
-
- // 100 onwards is free
- for(int i=100; i<fs.getBigBlockSizeDetails().getBATEntriesPerBlock(); i++) {
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(i));
- }
-
- fs.close();
- }
-
- // Quick check on 4096 byte blocks too
- fsA = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
- fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB}) {
- // 0 -> 1 -> 2 -> end
- assertEquals(1, fs.getNextBlock(0));
- assertEquals(2, fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
-
- // 4 -> 11 then end
- for(int i=4; i<11; i++) {
- assertEquals(i+1, fs.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(11));
-
- fs.close();
- }
- }
-
- /**
- * Check we get the right data back for each block
- */
- @Test
- public void getBlock() throws IOException {
- POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB}) {
- ByteBuffer b;
-
- // The 0th block is the first data block
- b = fs.getBlockAt(0);
- assertEquals((byte)0x9e, b.get());
- assertEquals((byte)0x75, b.get());
- assertEquals((byte)0x97, b.get());
- assertEquals((byte)0xf6, b.get());
-
- // And the next block
- b = fs.getBlockAt(1);
- assertEquals((byte)0x86, b.get());
- assertEquals((byte)0x09, b.get());
- assertEquals((byte)0x22, b.get());
- assertEquals((byte)0xfb, b.get());
-
- // Check the final block too
- b = fs.getBlockAt(99);
- assertEquals((byte)0x01, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x02, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
-
- fs.close();
- }
-
- // Quick check on 4096 byte blocks too
- fsA = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
- fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB}) {
- ByteBuffer b;
-
- // The 0th block is the first data block
- b = fs.getBlockAt(0);
- assertEquals((byte)0x9e, b.get());
- assertEquals((byte)0x75, b.get());
- assertEquals((byte)0x97, b.get());
- assertEquals((byte)0xf6, b.get());
-
- // And the next block
- b = fs.getBlockAt(1);
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x03, b.get());
- assertEquals((byte)0x00, b.get());
-
- // The 14th block is the FAT
- b = fs.getBlockAt(14);
- assertEquals((byte)0x01, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x02, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
-
- fs.close();
- }
- }
-
- /**
- * Ask for free blocks where there are some already
- * to be had from the FAT
- */
- @Test
- public void getFreeBlockWithSpare() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
-
- // Our first BAT block has spares
- assertTrue(fs.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
-
- // First free one is 100
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(100));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(101));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(102));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(103));
-
- // Ask, will get 100
- assertEquals(100, fs.getFreeBlock());
-
- // Ask again, will still get 100 as not written to
- assertEquals(100, fs.getFreeBlock());
-
- // Allocate it, then ask again
- fs.setNextBlock(100, POIFSConstants.END_OF_CHAIN);
- assertEquals(101, fs.getFreeBlock());
-
- // All done
- fs.close();
- }
-
- /**
- * Ask for free blocks where no free ones exist, and so the
- * file needs to be extended and another BAT/XBAT added
- */
- @Test
- public void getFreeBlockWithNoneSpare() throws IOException {
- POIFSFileSystem fs1 = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- int free;
-
- // We have one BAT at block 99
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs1.getNextBlock(99));
- assertBATCount(fs1, 1, 0);
-
- // We've spare ones from 100 to 128
- for(int i=100; i<128; i++) {
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs1.getNextBlock(i));
- }
-
- // Check our BAT knows it's free
- assertTrue(fs1.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
-
- // Allocate all the spare ones
- for(int i=100; i<128; i++) {
- fs1.setNextBlock(i, POIFSConstants.END_OF_CHAIN);
- }
-
- // BAT is now full, but there's only the one
- assertFalse(fs1.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- try {
- assertFalse(fs1.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
- fail("Should only be one BAT");
- } catch(IndexOutOfBoundsException e) {
- // expected here
- }
- assertBATCount(fs1, 1, 0);
-
-
- // Now ask for a free one, will need to extend the file
- assertEquals(129, fs1.getFreeBlock());
-
- assertFalse(fs1.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- assertTrue(fs1.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs1.getNextBlock(128));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs1.getNextBlock(129));
-
- // We now have 2 BATs, but no XBATs
- assertBATCount(fs1, 2, 0);
-
-
- // Fill up to hold 109 BAT blocks
- for(int i=0; i<109; i++) {
- fs1.getFreeBlock();
- int startOffset = i*128;
- while( fs1.getBATBlockAndIndex(startOffset).getBlock().hasFreeSectors() ) {
- free = fs1.getFreeBlock();
- fs1.setNextBlock(free, POIFSConstants.END_OF_CHAIN);
- }
- }
-
- assertFalse(fs1.getBATBlockAndIndex(109 * 128 - 1).getBlock().hasFreeSectors());
- try {
- assertFalse(fs1.getBATBlockAndIndex(109 * 128).getBlock().hasFreeSectors());
- fail("Should only be 109 BATs");
- } catch(IndexOutOfBoundsException e) {
- // expected here
- }
-
- // We now have 109 BATs, but no XBATs
- assertBATCount(fs1, 109, 0);
-
-
- // Ask for it to be written out, and check the header
- HeaderBlock header = writeOutAndReadHeader(fs1);
- assertEquals(109, header.getBATCount());
- assertEquals(0, header.getXBATCount());
-
-
- // Ask for another, will get our first XBAT
- free = fs1.getFreeBlock();
- assertTrue("Had: " + free, free > 0);
-
- assertFalse(fs1.getBATBlockAndIndex(109 * 128 - 1).getBlock().hasFreeSectors());
- assertTrue(fs1.getBATBlockAndIndex(110 * 128 - 1).getBlock().hasFreeSectors());
- try {
- assertFalse(fs1.getBATBlockAndIndex(110 * 128).getBlock().hasFreeSectors());
- fail("Should only be 110 BATs");
- } catch(IndexOutOfBoundsException e) {
- // expected here
- }
- assertBATCount(fs1, 110, 1);
-
- header = writeOutAndReadHeader(fs1);
- assertEquals(110, header.getBATCount());
- assertEquals(1, header.getXBATCount());
-
-
- // Fill the XBAT, which means filling 127 BATs
- for(int i=109; i<109+127; i++) {
- fs1.getFreeBlock();
- int startOffset = i*128;
- while( fs1.getBATBlockAndIndex(startOffset).getBlock().hasFreeSectors() ) {
- free = fs1.getFreeBlock();
- fs1.setNextBlock(free, POIFSConstants.END_OF_CHAIN);
- }
- assertBATCount(fs1, i+1, 1);
- }
-
- // Should now have 109+127 = 236 BATs
- assertFalse(fs1.getBATBlockAndIndex(236 * 128 - 1).getBlock().hasFreeSectors());
- try {
- assertFalse(fs1.getBATBlockAndIndex(236 * 128).getBlock().hasFreeSectors());
- fail("Should only be 236 BATs");
- } catch(IndexOutOfBoundsException e) {
- // expected here
- }
- assertBATCount(fs1, 236, 1);
-
-
- // Ask for another, will get our 2nd XBAT
- free = fs1.getFreeBlock();
- assertTrue("Had: " + free, free > 0);
-
- assertFalse(fs1.getBATBlockAndIndex(236 * 128 - 1).getBlock().hasFreeSectors());
- assertTrue(fs1.getBATBlockAndIndex(237 * 128 - 1).getBlock().hasFreeSectors());
- try {
- assertFalse(fs1.getBATBlockAndIndex(237 * 128).getBlock().hasFreeSectors());
- fail("Should only be 237 BATs");
- } catch(IndexOutOfBoundsException e) {
- // expected here
- }
-
-
- // Check the counts now
- assertBATCount(fs1, 237, 2);
-
- // Check the header
- header = writeOutAndReadHeader(fs1);
- assertNotNull(header);
-
- // Now, write it out, and read it back in again fully
- POIFSFileSystem fs2 = writeOutAndReadBack(fs1);
- fs1.close();
-
- // Check that it is seen correctly
- assertBATCount(fs2, 237, 2);
-
- assertFalse(fs2.getBATBlockAndIndex(236 * 128 - 1).getBlock().hasFreeSectors());
- assertTrue(fs2.getBATBlockAndIndex(237 * 128 - 1).getBlock().hasFreeSectors());
- try {
- assertFalse(fs2.getBATBlockAndIndex(237 * 128).getBlock().hasFreeSectors());
- fail("Should only be 237 BATs");
- } catch(IndexOutOfBoundsException e) {
- // expected here
- }
-
-
- // All done
- fs2.close();
- }
-
- /**
- * Test that we can correctly get the list of directory
- * entries, and the details on the files in them
- */
- @Test
- public void listEntries() throws IOException {
- for(POIFSFileSystem fs : get512and4kFileAndInput()) {
- DirectoryEntry root = fs.getRoot();
- assertEquals(5, root.getEntryCount());
-
- // Check by the names
- Entry thumbnail = root.getEntry("Thumbnail");
- Entry dsi = root.getEntry("\u0005DocumentSummaryInformation");
- Entry si = root.getEntry("\u0005SummaryInformation");
- Entry image = root.getEntry("Image");
- Entry tags = root.getEntry("Tags");
-
- assertFalse(thumbnail.isDirectoryEntry());
- assertFalse(dsi.isDirectoryEntry());
- assertFalse(si.isDirectoryEntry());
- assertTrue(image.isDirectoryEntry());
- assertFalse(tags.isDirectoryEntry());
-
- // Check via the iterator
- Iterator<Entry> it = root.getEntries();
- assertEquals(thumbnail.getName(), it.next().getName());
- assertEquals(dsi.getName(), it.next().getName());
- assertEquals(si.getName(), it.next().getName());
- assertEquals(image.getName(), it.next().getName());
- assertEquals(tags.getName(), it.next().getName());
-
- // Look inside another
- DirectoryEntry imageD = (DirectoryEntry)image;
- assertEquals(7, imageD.getEntryCount());
-
- fs.close();
- }
- }
-
- /**
- * Tests that we can get the correct contents for
- * a document in the filesystem
- */
- @Test
- public void getDocumentEntry() throws Exception {
- for(POIFSFileSystem fs : get512and4kFileAndInput()) {
- DirectoryEntry root = fs.getRoot();
- Entry si = root.getEntry("\u0005SummaryInformation");
-
- assertTrue(si.isDocumentEntry());
- DocumentNode doc = (DocumentNode)si;
-
- // Check we can read it
- assertContentsMatches(null, doc);
-
- // Now try to build the property set
- DocumentInputStream inp = new DocumentInputStream(doc);
- PropertySet ps = PropertySetFactory.create(inp);
- SummaryInformation inf = (SummaryInformation)ps;
-
- // Check some bits in it
- assertNull(inf.getApplicationName());
- assertNull(inf.getAuthor());
- assertNull(inf.getSubject());
- assertEquals(131333, inf.getOSVersion());
-
- // Finish with this one
- inp.close();
-
-
- // Try the other summary information
- si = root.getEntry("\u0005DocumentSummaryInformation");
- assertTrue(si.isDocumentEntry());
- doc = (DocumentNode)si;
- assertContentsMatches(null, doc);
-
- inp = new DocumentInputStream(doc);
- ps = PropertySetFactory.create(inp);
- DocumentSummaryInformation dinf = (DocumentSummaryInformation)ps;
- assertEquals(131333, dinf.getOSVersion());
-
- fs.close();
- }
- }
-
- /**
- * Read a file, write it and read it again.
- * Then, alter+add some streams, write and read
- */
- @Test
- public void readWriteRead() throws Exception {
- SummaryInformation sinf;
- DocumentSummaryInformation dinf;
- DirectoryEntry root, testDir;
-
- for(POIFSFileSystem fs1 : get512and4kFileAndInput()) {
- // Check we can find the entries we expect
- root = fs1.getRoot();
- assertEquals(5, root.getEntryCount());
- assertThat(root.getEntryNames(), hasItem("Thumbnail"));
- assertThat(root.getEntryNames(), hasItem("Image"));
- assertThat(root.getEntryNames(), hasItem("Tags"));
- assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
- assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
-
-
- // Write out, re-load
- POIFSFileSystem fs2 = writeOutAndReadBack(fs1);
- fs1.close();
-
- // Check they're still there
- root = fs2.getRoot();
- assertEquals(5, root.getEntryCount());
- assertThat(root.getEntryNames(), hasItem("Thumbnail"));
- assertThat(root.getEntryNames(), hasItem("Image"));
- assertThat(root.getEntryNames(), hasItem("Tags"));
- assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
- assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
-
-
- // Check the contents of them - parse the summary block and check
- sinf = (SummaryInformation)PropertySetFactory.create(new DocumentInputStream(
- (DocumentEntry)root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
- assertEquals(131333, sinf.getOSVersion());
-
- dinf = (DocumentSummaryInformation)PropertySetFactory.create(new DocumentInputStream(
- (DocumentEntry)root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
- assertEquals(131333, dinf.getOSVersion());
-
-
- // Add a test mini stream
- testDir = root.createDirectory("Testing 123");
- testDir.createDirectory("Testing 456");
- testDir.createDirectory("Testing 789");
- byte[] mini = new byte[] { 42, 0, 1, 2, 3, 4, 42 };
- testDir.createDocument("Mini", new ByteArrayInputStream(mini));
-
-
- // Write out, re-load
- POIFSFileSystem fs3 = writeOutAndReadBack(fs2);
- fs2.close();
-
- root = fs3.getRoot();
- testDir = (DirectoryEntry)root.getEntry("Testing 123");
- assertEquals(6, root.getEntryCount());
- assertThat(root.getEntryNames(), hasItem("Thumbnail"));
- assertThat(root.getEntryNames(), hasItem("Image"));
- assertThat(root.getEntryNames(), hasItem("Tags"));
- assertThat(root.getEntryNames(), hasItem("Testing 123"));
- assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
- assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
-
-
- // Check old and new are there
- sinf = (SummaryInformation)PropertySetFactory.create(new DocumentInputStream(
- (DocumentEntry)root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
- assertEquals(131333, sinf.getOSVersion());
-
- dinf = (DocumentSummaryInformation)PropertySetFactory.create(new DocumentInputStream(
- (DocumentEntry)root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
- assertEquals(131333, dinf.getOSVersion());
-
- assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini"));
-
-
- // Write out and read once more, just to be sure
- POIFSFileSystem fs4 = writeOutAndReadBack(fs3);
- fs3.close();
-
- root = fs4.getRoot();
- testDir = (DirectoryEntry)root.getEntry("Testing 123");
- assertEquals(6, root.getEntryCount());
- assertThat(root.getEntryNames(), hasItem("Thumbnail"));
- assertThat(root.getEntryNames(), hasItem("Image"));
- assertThat(root.getEntryNames(), hasItem("Tags"));
- assertThat(root.getEntryNames(), hasItem("Testing 123"));
- assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
- assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
-
- sinf = (SummaryInformation)PropertySetFactory.create(new DocumentInputStream(
- (DocumentEntry)root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
- assertEquals(131333, sinf.getOSVersion());
-
- dinf = (DocumentSummaryInformation)PropertySetFactory.create(new DocumentInputStream(
- (DocumentEntry)root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
- assertEquals(131333, dinf.getOSVersion());
-
- assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini"));
+ }
+
+ fs.close();
+ }
+
+ /**
+ * Writes less data than before, some blocks will need
+ * to be freed
+ */
+ @Test
+ public void testReplaceStreamWithLess() throws Exception {
+ try (InputStream is = _inst.openResourceAsStream("BlockSize512.zvi");
+ POIFSFileSystem fs = new POIFSFileSystem(is)) {
+
+ byte[] data = new byte[512];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i % 256);
+ }
+ // 97 -> 98 -> end
+ assertEquals(98, fs.getNextBlock(97));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(98));
+
+ // Create a 2 block stream, will become a 1 block one
+ POIFSStream stream = new POIFSStream(fs, 97);
+ stream.updateContents(data);
+
+ // 97 should now be the end, and 98 free
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(97));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(98));
+
+ // Check the reading of blocks
+ Iterator<ByteBuffer> it = stream.getBlockIterator();
+ assertTrue(it.hasNext());
+ ByteBuffer b = it.next();
+ assertFalse(it.hasNext());
+
+ // Now check the contents
+ data = new byte[512];
+ b.get(data);
+ for (int i = 0; i < data.length; i++) {
+ byte exp = (byte) (i % 256);
+ assertEquals(exp, data[i]);
+ }
+ }
+ }
+
+ /**
+ * Writes more data than before, new blocks will be needed
+ */
+ @Test
+ public void testReplaceStreamWithMore() throws Exception {
+ try (InputStream is = _inst.openResourceAsStream("BlockSize512.zvi");
+ POIFSFileSystem fs = new POIFSFileSystem(is)) {
+
+ byte[] data = new byte[512 * 3];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i % 256);
+ }
- // Add a full stream, delete a full stream
- byte[] main4096 = new byte[4096];
- main4096[0] = -10;
- main4096[4095] = -11;
- testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096));
+ // 97 -> 98 -> end
+ assertEquals(98, fs.getNextBlock(97));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(98));
+
+ // 100 is our first free one
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(100));
+
+ // Create a 2 block stream, will become a 3 block one
+ POIFSStream stream = new POIFSStream(fs, 97);
+ stream.updateContents(data);
+
+ // 97 -> 98 -> 100 -> end
+ assertEquals(98, fs.getNextBlock(97));
+ assertEquals(100, fs.getNextBlock(98));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(100));
+
+ // Check the reading of blocks
+ Iterator<ByteBuffer> it = stream.getBlockIterator();
+ int count = 0;
+ while (it.hasNext()) {
+ ByteBuffer b = it.next();
+ data = new byte[512];
+ b.get(data);
+ for (int i = 0; i < data.length; i++) {
+ byte exp = (byte) (i % 256);
+ assertEquals(exp, data[i]);
+ }
+ count++;
+ }
+ assertEquals(3, count);
+ }
+ }
+
+ /**
+ * Writes to a new stream in the file
+ */
+ @Test
+ public void testWriteNewStream() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+
+ // 100 is our first free one
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(100));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(101));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(102));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(103));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(104));
+
+
+ // Add a single block one
+ byte[] data = new byte[512];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i % 256);
+ }
+
+ POIFSStream stream = new POIFSStream(fs);
+ stream.updateContents(data);
+
+ // Check it was allocated properly
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(100));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(101));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(102));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(103));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(104));
+
+ // And check the contents
+ Iterator<ByteBuffer> it = stream.getBlockIterator();
+ int count = 0;
+ while (it.hasNext()) {
+ ByteBuffer b = it.next();
+ data = new byte[512];
+ b.get(data);
+ for (int i = 0; i < data.length; i++) {
+ byte exp = (byte) (i % 256);
+ assertEquals(exp, data[i]);
+ }
+ count++;
+ }
+ assertEquals(1, count);
+
+
+ // And a multi block one
+ data = new byte[512 * 3];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i % 256);
+ }
+
+ stream = new POIFSStream(fs);
+ stream.updateContents(data);
+
+ // Check it was allocated properly
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(100));
+ assertEquals(102, fs.getNextBlock(101));
+ assertEquals(103, fs.getNextBlock(102));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(103));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(104));
+
+ // And check the contents
+ it = stream.getBlockIterator();
+ count = 0;
+ while (it.hasNext()) {
+ ByteBuffer b = it.next();
+ data = new byte[512];
+ b.get(data);
+ for (int i = 0; i < data.length; i++) {
+ byte exp = (byte) (i % 256);
+ assertEquals(exp, data[i]);
+ }
+ count++;
+ }
+ assertEquals(3, count);
+
+ // Free it
+ stream.free();
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(100));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(101));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(102));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(103));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(104));
+
+ fs.close();
+ }
+
+ /**
+ * Writes to a new stream in the file, where we've not enough
+ * free blocks so new FAT segments will need to be allocated
+ * to support this
+ */
+ @Test
+ public void testWriteNewStreamExtraFATs() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+
+ // Allocate almost all the blocks
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(100));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(127));
+ for (int i = 100; i < 127; i++) {
+ fs.setNextBlock(i, POIFSConstants.END_OF_CHAIN);
+ }
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(127));
+ assertTrue(fs.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+
+
+ // Write a 3 block stream
+ byte[] data = new byte[512 * 3];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i % 256);
+ }
+ POIFSStream stream = new POIFSStream(fs);
+ stream.updateContents(data);
+
+ // Check we got another BAT
+ assertFalse(fs.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertTrue(fs.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+
+ // the BAT will be in the first spot of the new block
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(126));
+ assertEquals(129, fs.getNextBlock(127));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(128));
+ assertEquals(130, fs.getNextBlock(129));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(130));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(131));
+
+ fs.close();
+ }
+
+ /**
+ * Replaces data in an existing stream, with a bit
+ * more data than before, in a 4096 byte block file
+ */
+ @Test
+ public void testWriteStream4096() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+
+ // 0 -> 1 -> 2 -> end
+ assertEquals(1, fs.getNextBlock(0));
+ assertEquals(2, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
+ assertEquals(4, fs.getNextBlock(3));
+
+ // First free one is at 15
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(14));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(15));
+
+
+ // Write a 5 block file
+ byte[] data = new byte[4096 * 5];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i % 256);
+ }
+ POIFSStream stream = new POIFSStream(fs, 0);
+ stream.updateContents(data);
+
+
+ // Check it
+ assertEquals(1, fs.getNextBlock(0));
+ assertEquals(2, fs.getNextBlock(1));
+ assertEquals(15, fs.getNextBlock(2)); // Jumps
+ assertEquals(4, fs.getNextBlock(3)); // Next stream
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(14));
+ assertEquals(16, fs.getNextBlock(15)); // Continues
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(16)); // Ends
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(17)); // Free
+
+ // Check the contents too
+ Iterator<ByteBuffer> it = stream.getBlockIterator();
+ int count = 0;
+ while (it.hasNext()) {
+ ByteBuffer b = it.next();
+ data = new byte[512];
+ b.get(data);
+ for (int i = 0; i < data.length; i++) {
+ byte exp = (byte) (i % 256);
+ assertEquals(exp, data[i]);
+ }
+ count++;
+ }
+ assertEquals(5, count);
- root.getEntry("Tags").delete();
+ fs.close();
+ }
+ /**
+ * Tests that we can write into the mini stream
+ */
+ @Test
+ public void testWriteMiniStreams() throws Exception {
+ try (InputStream is = _inst.openResourceAsStream("BlockSize512.zvi");
+ POIFSFileSystem fs = new POIFSFileSystem(is)) {
- // Write out, re-load
- POIFSFileSystem fs5 = writeOutAndReadBack(fs4);
- fs4.close();
+ POIFSMiniStore ministore = fs.getMiniStore();
- // Check it's all there
- root = fs5.getRoot();
- testDir = (DirectoryEntry)root.getEntry("Testing 123");
- assertEquals(5, root.getEntryCount());
- assertThat(root.getEntryNames(), hasItem("Thumbnail"));
- assertThat(root.getEntryNames(), hasItem("Image"));
- assertThat(root.getEntryNames(), hasItem("Testing 123"));
- assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
- assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+ // 178 -> 179 -> 180 -> end
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
- // Check old and new are there
- sinf = (SummaryInformation)PropertySetFactory.create(new DocumentInputStream(
- (DocumentEntry)root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
- assertEquals(131333, sinf.getOSVersion());
+ // Try writing 3 full blocks worth
+ byte[] data = new byte[64 * 3];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) i;
+ }
+ POIFSStream stream = new POIFSStream(ministore, 178);
+ stream.updateContents(data);
+
+ // Check
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
+
+ stream = new POIFSStream(ministore, 178);
+ Iterator<ByteBuffer> it = stream.getBlockIterator();
+ ByteBuffer b178 = it.next();
+ ByteBuffer b179 = it.next();
+ ByteBuffer b180 = it.next();
+ assertFalse(it.hasNext());
+
+ assertEquals((byte) 0x00, b178.get());
+ assertEquals((byte) 0x01, b178.get());
+ assertEquals((byte) 0x40, b179.get());
+ assertEquals((byte) 0x41, b179.get());
+ assertEquals((byte) 0x80, b180.get());
+ assertEquals((byte) 0x81, b180.get());
+
+
+ // Try writing just into 3 blocks worth
+ data = new byte[64 * 2 + 12];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i + 4);
+ }
+ stream = new POIFSStream(ministore, 178);
+ stream.updateContents(data);
+
+ // Check
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
+
+ stream = new POIFSStream(ministore, 178);
+ it = stream.getBlockIterator();
+ b178 = it.next();
+ b179 = it.next();
+ b180 = it.next();
+ assertFalse(it.hasNext());
+
+ assertEquals((byte) 0x04, b178.get(0));
+ assertEquals((byte) 0x05, b178.get(1));
+ assertEquals((byte) 0x44, b179.get(0));
+ assertEquals((byte) 0x45, b179.get(1));
+ assertEquals((byte) 0x84, b180.get(0));
+ assertEquals((byte) 0x85, b180.get(1));
+
+
+ // Try writing 1, should truncate
+ data = new byte[12];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i + 9);
+ }
+ stream = new POIFSStream(ministore, 178);
+ stream.updateContents(data);
- dinf = (DocumentSummaryInformation)PropertySetFactory.create(new DocumentInputStream(
- (DocumentEntry)root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
- assertEquals(131333, dinf.getOSVersion());
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(178));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(179));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(180));
- assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini"));
- assertContentsMatches(main4096, (DocumentEntry)testDir.getEntry("Normal4096"));
+ stream = new POIFSStream(ministore, 178);
+ it = stream.getBlockIterator();
+ b178 = it.next();
+ assertFalse(it.hasNext());
+ assertEquals((byte) 0x09, b178.get(0));
+ assertEquals((byte) 0x0a, b178.get(1));
- // Delete a directory, and add one more
- testDir.getEntry("Testing 456").delete();
- testDir.createDirectory("Testing ABC");
+ // Try writing 5, should extend
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(178));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(179));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(180));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(181));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(182));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(183));
- // Save
- POIFSFileSystem fs6 = writeOutAndReadBack(fs5);
- fs5.close();
+ data = new byte[64 * 4 + 12];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i + 3);
+ }
+ stream = new POIFSStream(ministore, 178);
+ stream.updateContents(data);
+
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(181, ministore.getNextBlock(180));
+ assertEquals(182, ministore.getNextBlock(181));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(182));
+
+ stream = new POIFSStream(ministore, 178);
+ it = stream.getBlockIterator();
+ b178 = it.next();
+ b179 = it.next();
+ b180 = it.next();
+ ByteBuffer b181 = it.next();
+ ByteBuffer b182 = it.next();
+ assertFalse(it.hasNext());
+
+ assertEquals((byte) 0x03, b178.get(0));
+ assertEquals((byte) 0x04, b178.get(1));
+ assertEquals((byte) 0x43, b179.get(0));
+ assertEquals((byte) 0x44, b179.get(1));
+ assertEquals((byte) 0x83, b180.get(0));
+ assertEquals((byte) 0x84, b180.get(1));
+ assertEquals((byte) 0xc3, b181.get(0));
+ assertEquals((byte) 0xc4, b181.get(1));
+ assertEquals((byte) 0x03, b182.get(0));
+ assertEquals((byte) 0x04, b182.get(1));
+
+
+ // Write lots, so it needs another big block
+ ministore.getBlockAt(183);
+ assertThrows(NoSuchElementException.class, () -> ministore.getBlockAt(184), "Block 184 should be off the end of the list");
+
+ data = new byte[64 * 6 + 12];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i + 1);
+ }
+ stream = new POIFSStream(ministore, 178);
+ stream.updateContents(data);
+
+ // Should have added 2 more blocks to the chain
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(181, ministore.getNextBlock(180));
+ assertEquals(182, ministore.getNextBlock(181));
+ assertEquals(183, ministore.getNextBlock(182));
+ assertEquals(184, ministore.getNextBlock(183));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(184));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(185));
+
+ // Block 184 should exist
+ ministore.getBlockAt(183);
+ ministore.getBlockAt(184);
+ ministore.getBlockAt(185);
+
+ // Check contents
+ stream = new POIFSStream(ministore, 178);
+ it = stream.getBlockIterator();
+ b178 = it.next();
+ b179 = it.next();
+ b180 = it.next();
+ b181 = it.next();
+ b182 = it.next();
+ ByteBuffer b183 = it.next();
+ ByteBuffer b184 = it.next();
+ assertFalse(it.hasNext());
+
+ assertEquals((byte) 0x01, b178.get(0));
+ assertEquals((byte) 0x02, b178.get(1));
+ assertEquals((byte) 0x41, b179.get(0));
+ assertEquals((byte) 0x42, b179.get(1));
+ assertEquals((byte) 0x81, b180.get(0));
+ assertEquals((byte) 0x82, b180.get(1));
+ assertEquals((byte) 0xc1, b181.get(0));
+ assertEquals((byte) 0xc2, b181.get(1));
+ assertEquals((byte) 0x01, b182.get(0));
+ assertEquals((byte) 0x02, b182.get(1));
+ assertEquals((byte) 0x41, b183.get(0));
+ assertEquals((byte) 0x42, b183.get(1));
+ assertEquals((byte) 0x81, b184.get(0));
+ assertEquals((byte) 0x82, b184.get(1));
+
+ }
+ }
+
+ /**
+ * Craft a nasty file with a loop, and ensure we don't get stuck
+ */
+ @Test
+ public void testWriteFailsOnLoop() throws Exception {
+ try (POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"))) {
+
+ // Hack the FAT so that it goes 0->1->2->0
+ fs.setNextBlock(0, 1);
+ fs.setNextBlock(1, 2);
+ fs.setNextBlock(2, 0);
+
+ // Try to write a large amount, should fail on the write
+ POIFSStream stream1 = new POIFSStream(fs, 0);
+ assertThrows(IllegalStateException.class,
+ () -> stream1.updateContents(new byte[512 * 4]), "Loop should have been detected but wasn't!");
+
+ // Now reset, and try on a small bit
+ // Should fail during the freeing set
+ fs.setNextBlock(0, 1);
+ fs.setNextBlock(1, 2);
+ fs.setNextBlock(2, 0);
+
+ POIFSStream stream2 = new POIFSStream(fs, 0);
+ assertThrows(IllegalStateException.class,
+ () -> stream2.updateContents(new byte[512]), "Loop should have been detected but wasn't!");
+ }
+ }
+
+ /**
+ * Tests adding a new stream, writing and reading it.
+ */
+ @Test
+ public void testReadWriteNewStream() throws Exception {
+ try (POIFSFileSystem fs = new POIFSFileSystem()) {
+ POIFSStream stream = new POIFSStream(fs);
+
+ // Check our filesystem has Properties then BAT
+ assertEquals(2, fs.getFreeBlock());
+ BATBlock bat = fs.getBATBlockAndIndex(0).getBlock();
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(2));
+
+ // Check the stream as-is
+ assertEquals(POIFSConstants.END_OF_CHAIN, stream.getStartBlock());
+ assertThrows(IllegalStateException.class, stream::getBlockIterator,
+ "Shouldn't be able to get an iterator before writing");
+
+ // Write in two blocks
+ byte[] data = new byte[512 + 20];
+ for (int i = 0; i < 512; i++) {
+ data[i] = (byte) (i % 256);
+ }
+ for (int i = 512; i < data.length; i++) {
+ data[i] = (byte) (i % 256 + 100);
+ }
+ stream.updateContents(data);
+
+ // Check now
+ assertEquals(4, fs.getFreeBlock());
+ bat = fs.getBATBlockAndIndex(0).getBlock();
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
+ assertEquals(3, bat.getValueAt(2));
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(4));
+
+
+ Iterator<ByteBuffer> it = stream.getBlockIterator();
+ assertTrue(it.hasNext());
+ ByteBuffer b = it.next();
+
+ byte[] read = new byte[512];
+ b.get(read);
+ for (int i = 0; i < read.length; i++) {
+ assertEquals(data[i], read[i], "Wrong value at " + i);
+ }
+
+ assertTrue(it.hasNext());
+ b = it.next();
+
+ read = new byte[512];
+ b.get(read);
+ for (int i = 0; i < 20; i++) {
+ assertEquals(data[i + 512], read[i]);
+ }
+ for (int i = 20; i < read.length; i++) {
+ assertEquals(0, read[i]);
+ }
+
+ assertFalse(it.hasNext());
+ }
+ }
+
+ /**
+ * Writes a stream, then replaces it
+ */
+ @Test
+ public void testWriteThenReplace() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem();
+
+ // Starts empty, other that Properties and BAT
+ BATBlock bat = fs.getBATBlockAndIndex(0).getBlock();
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(2));
+
+ // Write something that uses a main stream
+ byte[] main4106 = new byte[4106];
+ main4106[0] = -10;
+ main4106[4105] = -11;
+ fs.getRoot().createDocument("Normal", new ByteArrayInputStream(main4106));
+
+ // Should have used 9 blocks
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
+ assertEquals(3, bat.getValueAt(2));
+ assertEquals(4, bat.getValueAt(3));
+ assertEquals(5, bat.getValueAt(4));
+ assertEquals(6, bat.getValueAt(5));
+ assertEquals(7, bat.getValueAt(6));
+ assertEquals(8, bat.getValueAt(7));
+ assertEquals(9, bat.getValueAt(8));
+ assertEquals(10, bat.getValueAt(9));
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(10));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
+
+ DocumentEntry normal = (DocumentEntry) fs.getRoot().getEntry("Normal");
+ assertEquals(4106, normal.getSize());
+ assertEquals(4106, ((DocumentNode) normal).getProperty().getSize());
+
+
+ // Replace with one still big enough for a main stream, but one block smaller
+ byte[] main4096 = new byte[4096];
+ main4096[0] = -10;
+ main4096[4095] = -11;
+
+ DocumentOutputStream nout = new DocumentOutputStream(normal);
+ nout.write(main4096);
+ nout.close();
+
+ // Will have dropped to 8
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
+ assertEquals(3, bat.getValueAt(2));
+ assertEquals(4, bat.getValueAt(3));
+ assertEquals(5, bat.getValueAt(4));
+ assertEquals(6, bat.getValueAt(5));
+ assertEquals(7, bat.getValueAt(6));
+ assertEquals(8, bat.getValueAt(7));
+ assertEquals(9, bat.getValueAt(8));
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(9));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(10));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
+
+ normal = (DocumentEntry) fs.getRoot().getEntry("Normal");
+ assertEquals(4096, normal.getSize());
+ assertEquals(4096, ((DocumentNode) normal).getProperty().getSize());
+
+
+ // Write and check
+ fs = writeOutAndReadBack(fs);
+ bat = fs.getBATBlockAndIndex(0).getBlock();
+
+ // No change after write
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0)); // Properties
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
+ assertEquals(3, bat.getValueAt(2));
+ assertEquals(4, bat.getValueAt(3));
+ assertEquals(5, bat.getValueAt(4));
+ assertEquals(6, bat.getValueAt(5));
+ assertEquals(7, bat.getValueAt(6));
+ assertEquals(8, bat.getValueAt(7));
+ assertEquals(9, bat.getValueAt(8));
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(9)); // End of Normal
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(10));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
+
+ normal = (DocumentEntry) fs.getRoot().getEntry("Normal");
+ assertEquals(4096, normal.getSize());
+ assertEquals(4096, ((DocumentNode) normal).getProperty().getSize());
+
+
+ // Make longer, take 1 block at the end
+ normal = (DocumentEntry) fs.getRoot().getEntry("Normal");
+ nout = new DocumentOutputStream(normal);
+ nout.write(main4106);
+ nout.close();
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
+ assertEquals(3, bat.getValueAt(2));
+ assertEquals(4, bat.getValueAt(3));
+ assertEquals(5, bat.getValueAt(4));
+ assertEquals(6, bat.getValueAt(5));
+ assertEquals(7, bat.getValueAt(6));
+ assertEquals(8, bat.getValueAt(7));
+ assertEquals(9, bat.getValueAt(8));
+ assertEquals(10, bat.getValueAt(9));
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(10)); // Normal
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
+
+ normal = (DocumentEntry) fs.getRoot().getEntry("Normal");
+ assertEquals(4106, normal.getSize());
+ assertEquals(4106, ((DocumentNode) normal).getProperty().getSize());
+
+
+ // Make it small, will trigger the SBAT stream and free lots up
+ byte[] mini = new byte[]{42, 0, 1, 2, 3, 4, 42};
+ normal = (DocumentEntry) fs.getRoot().getEntry("Normal");
+ nout = new DocumentOutputStream(normal);
+ nout.write(mini);
+ nout.close();
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(2)); // SBAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3)); // Mini Stream
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(4));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(5));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(6));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(7));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(8));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(9));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(10));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
+
+ normal = (DocumentEntry) fs.getRoot().getEntry("Normal");
+ assertEquals(7, normal.getSize());
+ assertEquals(7, ((DocumentNode) normal).getProperty().getSize());
+
+
+ // Finally back to big again
+ nout = new DocumentOutputStream(normal);
+ nout.write(main4096);
+ nout.close();
+
+ // Will keep the mini stream, now empty
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(2)); // SBAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3)); // Mini Stream
+ assertEquals(5, bat.getValueAt(4));
+ assertEquals(6, bat.getValueAt(5));
+ assertEquals(7, bat.getValueAt(6));
+ assertEquals(8, bat.getValueAt(7));
+ assertEquals(9, bat.getValueAt(8));
+ assertEquals(10, bat.getValueAt(9));
+ assertEquals(11, bat.getValueAt(10));
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(11));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(13));
+
+ normal = (DocumentEntry) fs.getRoot().getEntry("Normal");
+ assertEquals(4096, normal.getSize());
+ assertEquals(4096, ((DocumentNode) normal).getProperty().getSize());
+
+
+ // Save, re-load, re-check
+ fs = writeOutAndReadBack(fs);
+ bat = fs.getBATBlockAndIndex(0).getBlock();
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(2)); // SBAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3)); // Mini Stream
+ assertEquals(5, bat.getValueAt(4));
+ assertEquals(6, bat.getValueAt(5));
+ assertEquals(7, bat.getValueAt(6));
+ assertEquals(8, bat.getValueAt(7));
+ assertEquals(9, bat.getValueAt(8));
+ assertEquals(10, bat.getValueAt(9));
+ assertEquals(11, bat.getValueAt(10));
+ assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(11));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(13));
+
+ normal = (DocumentEntry) fs.getRoot().getEntry("Normal");
+ assertEquals(4096, normal.getSize());
+ assertEquals(4096, ((DocumentNode) normal).getProperty().getSize());
+
+ fs.close();
+ }
+
+
+ /**
+ * Returns test files with 512 byte and 4k block sizes, loaded
+ * both from InputStreams and Files
+ */
+ private POIFSFileSystem[] get512and4kFileAndInput() throws IOException {
+ POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ POIFSFileSystem fsC = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+ POIFSFileSystem fsD = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+ return new POIFSFileSystem[]{fsA, fsB, fsC, fsD};
+ }
+
+ private static void assertBATCount(POIFSFileSystem fs, int expectedBAT, int expectedXBAT) throws IOException {
+ int foundBAT = 0;
+ int foundXBAT = 0;
+ int sz = (int) (fs.size() / fs.getBigBlockSize());
+ for (int i = 0; i < sz; i++) {
+ if (fs.getNextBlock(i) == POIFSConstants.FAT_SECTOR_BLOCK) {
+ foundBAT++;
+ }
+ if (fs.getNextBlock(i) == POIFSConstants.DIFAT_SECTOR_BLOCK) {
+ foundXBAT++;
+ }
+ }
+ assertEquals(expectedBAT, foundBAT, "Wrong number of BATs");
+ assertEquals(expectedXBAT, foundXBAT, "Wrong number of XBATs with " + expectedBAT + " BATs");
+ }
+
+ private void assertContentsMatches(byte[] expected, DocumentEntry doc) throws IOException {
+ DocumentInputStream inp = new DocumentInputStream(doc);
+ byte[] contents = new byte[doc.getSize()];
+ assertEquals(doc.getSize(), inp.read(contents));
+ inp.close();
+
+ if (expected != null) {
+ assertThat(expected, equalTo(contents));
+ }
+ }
+
+ private static HeaderBlock writeOutAndReadHeader(POIFSFileSystem fs) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ fs.writeFilesystem(baos);
+
+ return new HeaderBlock(new ByteArrayInputStream(baos.toByteArray()));
+ }
+
+ private static POIFSFileSystem writeOutAndReadBack(POIFSFileSystem original) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ original.writeFilesystem(baos);
+ return new POIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
+ }
+
+ private static POIFSFileSystem writeOutFileAndReadBack(POIFSFileSystem original) throws IOException {
+ final File file = TempFile.createTempFile("TestPOIFS", ".ole2");
+ try (OutputStream fout = new FileOutputStream(file)) {
+ original.writeFilesystem(fout);
+ }
+ return new POIFSFileSystem(file, false);
+ }
+
+ @Test
+ public void basicOpen() throws IOException {
+ POIFSFileSystem fsA, fsB;
+
+ // With a simple 512 block file
+ fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB}) {
+ assertEquals(512, fs.getBigBlockSize());
+ }
+ fsA.close();
+ fsB.close();
+
+ // Now with a simple 4096 block file
+ fsA = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+ fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB}) {
+ assertEquals(4096, fs.getBigBlockSize());
+ }
+ fsA.close();
+ fsB.close();
+ }
+
+ @Test
+ public void propertiesAndFatOnRead() throws IOException {
+ POIFSFileSystem fsA, fsB;
+
+ // With a simple 512 block file
+ fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB}) {
+ // Check the FAT was properly processed:
+ // Verify we only got one block
+ fs.getBATBlockAndIndex(0);
+ fs.getBATBlockAndIndex(1);
+ assertThrows(IndexOutOfBoundsException.class, () -> fs.getBATBlockAndIndex(140),
+ "Should only be one BAT, but a 2nd was found");
+
+ // Verify a few next offsets
+ // 97 -> 98 -> END
+ assertEquals(98, fs.getNextBlock(97));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(98));
+
+
+ // Check the properties
+ PropertyTable props = fs._get_property_table();
+ assertEquals(90, props.getStartBlock());
+ assertEquals(7, props.countBlocks());
+
+ // Root property tells us about the Mini Stream
+ RootProperty root = props.getRoot();
+ assertEquals("Root Entry", root.getName());
+ assertEquals(11564, root.getSize());
+ assertEquals(0, root.getStartBlock());
+
+ // Check its children too
+ Property prop;
+ Iterator<Property> pi = root.getChildren();
+ prop = pi.next();
+ assertEquals("Thumbnail", prop.getName());
+ prop = pi.next();
+ assertEquals("\u0005DocumentSummaryInformation", prop.getName());
+ prop = pi.next();
+ assertEquals("\u0005SummaryInformation", prop.getName());
+ prop = pi.next();
+ assertEquals("Image", prop.getName());
+ prop = pi.next();
+ assertEquals("Tags", prop.getName());
+ assertFalse(pi.hasNext());
+
+
+ // Check the SBAT (Small Blocks FAT) was properly processed
+ POIFSMiniStore ministore = fs.getMiniStore();
+
+ // Verify we only got two SBAT blocks
+ ministore.getBATBlockAndIndex(0);
+ ministore.getBATBlockAndIndex(128);
+ assertThrows(IndexOutOfBoundsException.class, () -> ministore.getBATBlockAndIndex(256),
+ "Should only be two SBATs, but a 3rd was found");
+
+ // Verify a few offsets: 0->50 is a stream
+ for (int i = 0; i < 50; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(50));
+
+ fs.close();
+ }
+
+ // Now with a simple 4096 block file
+ fsA = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+ fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB}) {
+ // Check the FAT was properly processed
+ // Verify we only got one block
+ fs.getBATBlockAndIndex(0);
+ fs.getBATBlockAndIndex(1);
+ assertThrows(IndexOutOfBoundsException.class, () -> fs.getBATBlockAndIndex(1040),
+ "Should only be one BAT, but a 2nd was found");
+
+ // Verify a few next offsets
+ // 0 -> 1 -> 2 -> END
+ assertEquals(1, fs.getNextBlock(0));
+ assertEquals(2, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
+
+
+ // Check the properties
+ PropertyTable props = fs._get_property_table();
+ assertEquals(12, props.getStartBlock());
+ assertEquals(1, props.countBlocks());
+
+ // Root property tells us about the Mini Stream
+ RootProperty root = props.getRoot();
+ assertEquals("Root Entry", root.getName());
+ assertEquals(11564, root.getSize());
+ assertEquals(0, root.getStartBlock());
+
+ // Check its children too
+ Property prop;
+ Iterator<Property> pi = root.getChildren();
+ prop = pi.next();
+ assertEquals("Thumbnail", prop.getName());
+ prop = pi.next();
+ assertEquals("\u0005DocumentSummaryInformation", prop.getName());
+ prop = pi.next();
+ assertEquals("\u0005SummaryInformation", prop.getName());
+ prop = pi.next();
+ assertEquals("Image", prop.getName());
+ prop = pi.next();
+ assertEquals("Tags", prop.getName());
+ assertFalse(pi.hasNext());
+
+
+ // Check the SBAT (Small Blocks FAT) was properly processed
+ POIFSMiniStore ministore = fs.getMiniStore();
+
+ // Verify we only got one SBAT block
+ ministore.getBATBlockAndIndex(0);
+ ministore.getBATBlockAndIndex(128);
+ ministore.getBATBlockAndIndex(1023);
+ assertThrows(IndexOutOfBoundsException.class, () -> ministore.getBATBlockAndIndex(1024),
+ "Should only be one SBAT, but a 2nd was found");
+
+ // Verify a few offsets: 0->50 is a stream
+ for (int i = 0; i < 50; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(50));
+
+ fs.close();
+ }
+ }
+
+ /**
+ * Check that for a given block, we can correctly figure
+ * out what the next one is
+ */
+ @Test
+ public void nextBlock() throws IOException {
+ POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB}) {
+ // 0 -> 21 are simple
+ for (int i = 0; i < 21; i++) {
+ assertEquals(i + 1, fs.getNextBlock(i));
+ }
+ // 21 jumps to 89, then ends
+ assertEquals(89, fs.getNextBlock(21));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(89));
- // Check
- root = fs6.getRoot();
- testDir = (DirectoryEntry)root.getEntry("Testing 123");
+ // 22 -> 88 simple sequential stream
+ for (int i = 22; i < 88; i++) {
+ assertEquals(i + 1, fs.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(88));
- assertEquals(5, root.getEntryCount());
- assertThat(root.getEntryNames(), hasItem("Thumbnail"));
- assertThat(root.getEntryNames(), hasItem("Image"));
- assertThat(root.getEntryNames(), hasItem("Testing 123"));
- assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
- assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+ // 90 -> 96 is another stream
+ for (int i = 90; i < 96; i++) {
+ assertEquals(i + 1, fs.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(96));
- assertEquals(4, testDir.getEntryCount());
- assertThat(testDir.getEntryNames(), hasItem("Mini"));
- assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
- assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
- assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
+ // 97+98 is another
+ assertEquals(98, fs.getNextBlock(97));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(98));
+ // 99 is our FAT block
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
- // Add another mini stream
- byte[] mini2 = new byte[] { -42, 0, -1, -2, -3, -4, -42 };
- testDir.createDocument("Mini2", new ByteArrayInputStream(mini2));
+ // 100 onwards is free
+ for (int i = 100; i < fs.getBigBlockSizeDetails().getBATEntriesPerBlock(); i++) {
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(i));
+ }
- // Save, load, check
- POIFSFileSystem fs7 = writeOutAndReadBack(fs6);
- fs6.close();
+ fs.close();
+ }
+
+ // Quick check on 4096 byte blocks too
+ fsA = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+ fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB}) {
+ // 0 -> 1 -> 2 -> end
+ assertEquals(1, fs.getNextBlock(0));
+ assertEquals(2, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
+
+ // 4 -> 11 then end
+ for (int i = 4; i < 11; i++) {
+ assertEquals(i + 1, fs.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(11));
+
+ fs.close();
+ }
+ }
+
+ /**
+ * Check we get the right data back for each block
+ */
+ @Test
+ public void getBlock() throws IOException {
+ POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB}) {
+ ByteBuffer b;
+
+ // The 0th block is the first data block
+ b = fs.getBlockAt(0);
+ assertEquals((byte) 0x9e, b.get());
+ assertEquals((byte) 0x75, b.get());
+ assertEquals((byte) 0x97, b.get());
+ assertEquals((byte) 0xf6, b.get());
+
+ // And the next block
+ b = fs.getBlockAt(1);
+ assertEquals((byte) 0x86, b.get());
+ assertEquals((byte) 0x09, b.get());
+ assertEquals((byte) 0x22, b.get());
+ assertEquals((byte) 0xfb, b.get());
+
+ // Check the final block too
+ b = fs.getBlockAt(99);
+ assertEquals((byte) 0x01, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x02, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+
+ fs.close();
+ }
+
+ // Quick check on 4096 byte blocks too
+ fsA = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+ fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB}) {
+ ByteBuffer b;
+
+ // The 0th block is the first data block
+ b = fs.getBlockAt(0);
+ assertEquals((byte) 0x9e, b.get());
+ assertEquals((byte) 0x75, b.get());
+ assertEquals((byte) 0x97, b.get());
+ assertEquals((byte) 0xf6, b.get());
+
+ // And the next block
+ b = fs.getBlockAt(1);
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x03, b.get());
+ assertEquals((byte) 0x00, b.get());
+
+ // The 14th block is the FAT
+ b = fs.getBlockAt(14);
+ assertEquals((byte) 0x01, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x02, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+
+ fs.close();
+ }
+ }
+
+ /**
+ * Ask for free blocks where there are some already
+ * to be had from the FAT
+ */
+ @Test
+ public void getFreeBlockWithSpare() throws IOException {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+
+ // Our first BAT block has spares
+ assertTrue(fs.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+
+ // First free one is 100
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(100));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(101));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(102));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(103));
+
+ // Ask, will get 100
+ assertEquals(100, fs.getFreeBlock());
+
+ // Ask again, will still get 100 as not written to
+ assertEquals(100, fs.getFreeBlock());
+
+ // Allocate it, then ask again
+ fs.setNextBlock(100, POIFSConstants.END_OF_CHAIN);
+ assertEquals(101, fs.getFreeBlock());
+
+ // All done
+ fs.close();
+ }
+
+ /**
+ * Ask for free blocks where no free ones exist, and so the
+ * file needs to be extended and another BAT/XBAT added
+ */
+ @Test
+ public void getFreeBlockWithNoneSpare() throws IOException {
+ POIFSFileSystem fs1 = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ int free;
+
+ // We have one BAT at block 99
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs1.getNextBlock(99));
+ assertBATCount(fs1, 1, 0);
+
+ // We've spare ones from 100 to 128
+ for (int i = 100; i < 128; i++) {
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs1.getNextBlock(i));
+ }
+
+ // Check our BAT knows it's free
+ assertTrue(fs1.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+
+ // Allocate all the spare ones
+ for (int i = 100; i < 128; i++) {
+ fs1.setNextBlock(i, POIFSConstants.END_OF_CHAIN);
+ }
+
+ // BAT is now full, but there's only the one
+ assertFalse(fs1.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertThrows(IndexOutOfBoundsException.class, () -> fs1.getBATBlockAndIndex(128), "Should only be one BAT");
+ assertBATCount(fs1, 1, 0);
+
+
+ // Now ask for a free one, will need to extend the file
+ assertEquals(129, fs1.getFreeBlock());
+
+ assertFalse(fs1.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertTrue(fs1.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs1.getNextBlock(128));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs1.getNextBlock(129));
+
+ // We now have 2 BATs, but no XBATs
+ assertBATCount(fs1, 2, 0);
+
+
+ // Fill up to hold 109 BAT blocks
+ for (int i = 0; i < 109; i++) {
+ fs1.getFreeBlock();
+ int startOffset = i * 128;
+ while (fs1.getBATBlockAndIndex(startOffset).getBlock().hasFreeSectors()) {
+ free = fs1.getFreeBlock();
+ fs1.setNextBlock(free, POIFSConstants.END_OF_CHAIN);
+ }
+ }
- root = fs7.getRoot();
- testDir = (DirectoryEntry)root.getEntry("Testing 123");
+ assertFalse(fs1.getBATBlockAndIndex(109 * 128 - 1).getBlock().hasFreeSectors());
+ assertThrows(IndexOutOfBoundsException.class, () -> fs1.getBATBlockAndIndex(109 * 128), "Should only be 109 BATs");
- assertEquals(5, root.getEntryCount());
- assertThat(root.getEntryNames(), hasItem("Thumbnail"));
- assertThat(root.getEntryNames(), hasItem("Image"));
- assertThat(root.getEntryNames(), hasItem("Testing 123"));
- assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
- assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
-
- assertEquals(5, testDir.getEntryCount());
- assertThat(testDir.getEntryNames(), hasItem("Mini"));
- assertThat(testDir.getEntryNames(), hasItem("Mini2"));
- assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
- assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
- assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
+ // We now have 109 BATs, but no XBATs
+ assertBATCount(fs1, 109, 0);
- assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini"));
- assertContentsMatches(mini2, (DocumentEntry)testDir.getEntry("Mini2"));
- assertContentsMatches(main4096, (DocumentEntry)testDir.getEntry("Normal4096"));
+ // Ask for it to be written out, and check the header
+ HeaderBlock header = writeOutAndReadHeader(fs1);
+ assertEquals(109, header.getBATCount());
+ assertEquals(0, header.getXBATCount());
- // Delete a mini stream, add one more
- testDir.getEntry("Mini").delete();
- byte[] mini3 = new byte[] { 42, 0, 42, 0, 42, 0, 42 };
- testDir.createDocument("Mini3", new ByteArrayInputStream(mini3));
-
-
- // Save, load, check
- POIFSFileSystem fs8 = writeOutAndReadBack(fs7);
- fs7.close();
-
- root = fs8.getRoot();
- testDir = (DirectoryEntry)root.getEntry("Testing 123");
-
- assertEquals(5, root.getEntryCount());
- assertThat(root.getEntryNames(), hasItem("Thumbnail"));
- assertThat(root.getEntryNames(), hasItem("Image"));
- assertThat(root.getEntryNames(), hasItem("Testing 123"));
- assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
- assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
-
- assertEquals(5, testDir.getEntryCount());
- assertThat(testDir.getEntryNames(), hasItem("Mini2"));
- assertThat(testDir.getEntryNames(), hasItem("Mini3"));
- assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
- assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
- assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
+ // Ask for another, will get our first XBAT
+ free = fs1.getFreeBlock();
+ assertTrue(free > 0, "Had: " + free);
- assertContentsMatches(mini2, (DocumentEntry)testDir.getEntry("Mini2"));
- assertContentsMatches(mini3, (DocumentEntry)testDir.getEntry("Mini3"));
- assertContentsMatches(main4096, (DocumentEntry)testDir.getEntry("Normal4096"));
-
-
- // Change some existing streams
- POIFSDocument mini2Doc = new POIFSDocument((DocumentNode)testDir.getEntry("Mini2"));
- mini2Doc.replaceContents(new ByteArrayInputStream(mini));
-
- byte[] main4106 = new byte[4106];
- main4106[0] = 41;
- main4106[4105] = 42;
- POIFSDocument mainDoc = new POIFSDocument((DocumentNode)testDir.getEntry("Normal4096"));
- mainDoc.replaceContents(new ByteArrayInputStream(main4106));
-
-
- // Re-check
- POIFSFileSystem fs9 = writeOutAndReadBack(fs8);
- fs8.close();
-
- root = fs9.getRoot();
- testDir = (DirectoryEntry)root.getEntry("Testing 123");
-
- assertEquals(5, root.getEntryCount());
- assertThat(root.getEntryNames(), hasItem("Thumbnail"));
- assertThat(root.getEntryNames(), hasItem("Image"));
- assertThat(root.getEntryNames(), hasItem("Testing 123"));
- assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
- assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
-
- assertEquals(5, testDir.getEntryCount());
- assertThat(testDir.getEntryNames(), hasItem("Mini2"));
- assertThat(testDir.getEntryNames(), hasItem("Mini3"));
- assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
- assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
- assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
-
- assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini2"));
- assertContentsMatches(mini3, (DocumentEntry)testDir.getEntry("Mini3"));
- assertContentsMatches(main4106, (DocumentEntry)testDir.getEntry("Normal4096"));
-
-
- // All done
- fs9.close();
- }
- }
-
- /**
- * Create a new file, write it and read it again
- * Then, add some streams, write and read
- */
- @Test
- public void createWriteRead() throws IOException {
- POIFSFileSystem fs1 = new POIFSFileSystem();
- DocumentEntry miniDoc;
- DocumentEntry normDoc;
-
- // Initially has Properties + BAT but not SBAT
- assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs1.getNextBlock(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs1.getNextBlock(2));
-
- // Check that the SBAT is empty
- assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getRoot().getProperty().getStartBlock());
-
- // Check that properties table was given block 0
- assertEquals(0, fs1._get_property_table().getStartBlock());
-
- // Write and read it
- POIFSFileSystem fs2 = writeOutAndReadBack(fs1);
- fs1.close();
-
- // No change, SBAT remains empty
- assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs2.getNextBlock(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs2.getNextBlock(2));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs2.getNextBlock(3));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getRoot().getProperty().getStartBlock());
- assertEquals(0, fs2._get_property_table().getStartBlock());
- fs2.close();
-
- // Check the same but with saving to a file
- POIFSFileSystem fs3 = new POIFSFileSystem();
- POIFSFileSystem fs4 = writeOutFileAndReadBack(fs3);
- fs3.close();
-
- // Same, no change, SBAT remains empty
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs4.getNextBlock(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(2));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(3));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getRoot().getProperty().getStartBlock());
- assertEquals(0, fs4._get_property_table().getStartBlock());
-
-
-
- // Put everything within a new directory
- DirectoryEntry testDir = fs4.createDirectory("Test Directory");
-
- // Add a new Normal Stream (Normal Streams minimum 4096 bytes)
- byte[] main4096 = new byte[4096];
- main4096[0] = -10;
- main4096[4095] = -11;
- testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096));
-
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs4.getNextBlock(1));
- assertEquals(3, fs4.getNextBlock(2));
- assertEquals(4, fs4.getNextBlock(3));
- assertEquals(5, fs4.getNextBlock(4));
- assertEquals(6, fs4.getNextBlock(5));
- assertEquals(7, fs4.getNextBlock(6));
- assertEquals(8, fs4.getNextBlock(7));
- assertEquals(9, fs4.getNextBlock(8));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(9));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(10));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(11));
- // SBAT still unused
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getRoot().getProperty().getStartBlock());
-
-
- // Add a bigger Normal Stream
- byte[] main5124 = new byte[5124];
- main5124[0] = -22;
- main5124[5123] = -33;
- testDir.createDocument("Normal5124", new ByteArrayInputStream(main5124));
-
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs4.getNextBlock(1));
- assertEquals(3, fs4.getNextBlock(2));
- assertEquals(4, fs4.getNextBlock(3));
- assertEquals(5, fs4.getNextBlock(4));
- assertEquals(6, fs4.getNextBlock(5));
- assertEquals(7, fs4.getNextBlock(6));
- assertEquals(8, fs4.getNextBlock(7));
- assertEquals(9, fs4.getNextBlock(8));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(9));
-
- assertEquals(11, fs4.getNextBlock(10));
- assertEquals(12, fs4.getNextBlock(11));
- assertEquals(13, fs4.getNextBlock(12));
- assertEquals(14, fs4.getNextBlock(13));
- assertEquals(15, fs4.getNextBlock(14));
- assertEquals(16, fs4.getNextBlock(15));
- assertEquals(17, fs4.getNextBlock(16));
- assertEquals(18, fs4.getNextBlock(17));
- assertEquals(19, fs4.getNextBlock(18));
- assertEquals(20, fs4.getNextBlock(19));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(20));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(21));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(22));
-
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getRoot().getProperty().getStartBlock());
-
-
- // Now Add a mini stream
- byte[] mini = new byte[] { 42, 0, 1, 2, 3, 4, 42 };
- testDir.createDocument("Mini", new ByteArrayInputStream(mini));
-
- // Mini stream will get one block for fat + one block for data
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs4.getNextBlock(1));
- assertEquals(3, fs4.getNextBlock(2));
- assertEquals(4, fs4.getNextBlock(3));
- assertEquals(5, fs4.getNextBlock(4));
- assertEquals(6, fs4.getNextBlock(5));
- assertEquals(7, fs4.getNextBlock(6));
- assertEquals(8, fs4.getNextBlock(7));
- assertEquals(9, fs4.getNextBlock(8));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(9));
-
- assertEquals(11, fs4.getNextBlock(10));
- assertEquals(12, fs4.getNextBlock(11));
- assertEquals(13, fs4.getNextBlock(12));
- assertEquals(14, fs4.getNextBlock(13));
- assertEquals(15, fs4.getNextBlock(14));
- assertEquals(16, fs4.getNextBlock(15));
- assertEquals(17, fs4.getNextBlock(16));
- assertEquals(18, fs4.getNextBlock(17));
- assertEquals(19, fs4.getNextBlock(18));
- assertEquals(20, fs4.getNextBlock(19));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(20));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(21));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(22));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(23));
-
- // Check the mini stream location was set
- // (21 is mini fat, 22 is first mini stream block)
- assertEquals(22, fs4.getRoot().getProperty().getStartBlock());
-
-
- // Write and read back
- POIFSFileSystem fs5 = writeOutAndReadBack(fs4);
- fs4.close();
- HeaderBlock header = writeOutAndReadHeader(fs5);
-
- // Check the header has the right points in it
- assertEquals(1, header.getBATCount());
- assertEquals(1, header.getBATArray()[0]);
- assertEquals(0, header.getPropertyStart());
- assertEquals(1, header.getSBATCount());
- assertEquals(21, header.getSBATStart());
- assertEquals(22, fs5._get_property_table().getRoot().getStartBlock());
-
- // Block use should be almost the same, except the properties
- // stream will have grown out to cover 2 blocks
- // Check the block use is all unchanged
- assertEquals(23, fs5.getNextBlock(0)); // Properties now extends over 2 blocks
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs5.getNextBlock(1));
-
- assertEquals(3, fs5.getNextBlock(2));
- assertEquals(4, fs5.getNextBlock(3));
- assertEquals(5, fs5.getNextBlock(4));
- assertEquals(6, fs5.getNextBlock(5));
- assertEquals(7, fs5.getNextBlock(6));
- assertEquals(8, fs5.getNextBlock(7));
- assertEquals(9, fs5.getNextBlock(8));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs5.getNextBlock(9)); // End of normal4096
-
- assertEquals(11, fs5.getNextBlock(10));
- assertEquals(12, fs5.getNextBlock(11));
- assertEquals(13, fs5.getNextBlock(12));
- assertEquals(14, fs5.getNextBlock(13));
- assertEquals(15, fs5.getNextBlock(14));
- assertEquals(16, fs5.getNextBlock(15));
- assertEquals(17, fs5.getNextBlock(16));
- assertEquals(18, fs5.getNextBlock(17));
- assertEquals(19, fs5.getNextBlock(18));
- assertEquals(20, fs5.getNextBlock(19));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs5.getNextBlock(20)); // End of normal5124
-
- assertEquals(POIFSConstants.END_OF_CHAIN, fs5.getNextBlock(21)); // Mini Stream FAT
- assertEquals(POIFSConstants.END_OF_CHAIN, fs5.getNextBlock(22)); // Mini Stream data
- assertEquals(POIFSConstants.END_OF_CHAIN, fs5.getNextBlock(23)); // Properties #2
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs5.getNextBlock(24));
-
-
- // Check some data
- assertEquals(1, fs5.getRoot().getEntryCount());
- testDir = (DirectoryEntry)fs5.getRoot().getEntry("Test Directory");
- assertEquals(3, testDir.getEntryCount());
-
- miniDoc = (DocumentEntry)testDir.getEntry("Mini");
- assertContentsMatches(mini, miniDoc);
-
- normDoc = (DocumentEntry)testDir.getEntry("Normal4096");
- assertContentsMatches(main4096, normDoc);
-
- normDoc = (DocumentEntry)testDir.getEntry("Normal5124");
- assertContentsMatches(main5124, normDoc);
-
-
- // Delete a couple of streams
- miniDoc.delete();
- normDoc.delete();
-
-
- // Check - will have un-used sectors now
- POIFSFileSystem fs6 = writeOutAndReadBack(fs5);
- fs5.close();
-
- assertEquals(POIFSConstants.END_OF_CHAIN, fs6.getNextBlock(0)); // Props back in 1 block
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs6.getNextBlock(1));
-
- assertEquals(3, fs6.getNextBlock(2));
- assertEquals(4, fs6.getNextBlock(3));
- assertEquals(5, fs6.getNextBlock(4));
- assertEquals(6, fs6.getNextBlock(5));
- assertEquals(7, fs6.getNextBlock(6));
- assertEquals(8, fs6.getNextBlock(7));
- assertEquals(9, fs6.getNextBlock(8));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs6.getNextBlock(9)); // End of normal4096
-
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(10));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(11));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(12));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(13));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(14));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(15));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(16));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(17));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(18));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(19));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(20));
-
- assertEquals(POIFSConstants.END_OF_CHAIN, fs6.getNextBlock(21)); // Mini Stream FAT
- assertEquals(POIFSConstants.END_OF_CHAIN, fs6.getNextBlock(22)); // Mini Stream data
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(23)); // Properties gone
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(24));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(25));
-
- // All done
- fs6.close();
- }
-
- @Test
- public void addBeforeWrite() throws IOException {
- POIFSFileSystem fs1 = new POIFSFileSystem();
- DocumentEntry miniDoc;
- DocumentEntry normDoc;
- HeaderBlock hdr;
-
- // Initially has Properties + BAT but nothing else
- assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs1.getNextBlock(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs1.getNextBlock(2));
-
- hdr = writeOutAndReadHeader(fs1);
- // No mini stream, and no xbats
- // Will have fat then properties stream
- assertEquals(1, hdr.getBATCount());
- assertEquals(1, hdr.getBATArray()[0]);
- assertEquals(0, hdr.getPropertyStart());
- assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getSBATStart());
- assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
- assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE*3, fs1.size());
- fs1.close();
-
- // Get a clean filesystem to start with
- fs1 = new POIFSFileSystem();
-
- // Put our test files in a non-standard place
- DirectoryEntry parentDir = fs1.createDirectory("Parent Directory");
- DirectoryEntry testDir = parentDir.createDirectory("Test Directory");
-
-
- // Add to the mini stream
- byte[] mini = new byte[] { 42, 0, 1, 2, 3, 4, 42 };
- testDir.createDocument("Mini", new ByteArrayInputStream(mini));
-
- // Add to the main stream
- byte[] main4096 = new byte[4096];
- main4096[0] = -10;
- main4096[4095] = -11;
- testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096));
-
-
- // Check the mini stream was added, then the main stream
- assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs1.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(2)); // Mini Fat
- assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(3)); // Mini Stream
- assertEquals(5, fs1.getNextBlock(4)); // Main Stream
- assertEquals(6, fs1.getNextBlock(5));
- assertEquals(7, fs1.getNextBlock(6));
- assertEquals(8, fs1.getNextBlock(7));
- assertEquals(9, fs1.getNextBlock(8));
- assertEquals(10, fs1.getNextBlock(9));
- assertEquals(11, fs1.getNextBlock(10));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(11));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs1.getNextBlock(12));
- assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE*13, fs1.size());
-
-
- // Check that we can read the right data pre-write
- miniDoc = (DocumentEntry)testDir.getEntry("Mini");
- assertContentsMatches(mini, miniDoc);
-
- normDoc = (DocumentEntry)testDir.getEntry("Normal4096");
- assertContentsMatches(main4096, normDoc);
-
-
- // Write, read, check
- hdr = writeOutAndReadHeader(fs1);
- POIFSFileSystem fs2 = writeOutAndReadBack(fs1);
- fs1.close();
-
- // Check the header details - will have the sbat near the start,
- // then the properties at the end
- assertEquals(1, hdr.getBATCount());
- assertEquals(1, hdr.getBATArray()[0]);
- assertEquals(2, hdr.getSBATStart());
- assertEquals(0, hdr.getPropertyStart());
- assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
-
- // Check the block allocation is unchanged, other than
- // the properties stream going in at the end
- assertEquals(12, fs2.getNextBlock(0)); // Properties
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs2.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getNextBlock(2));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getNextBlock(3));
- assertEquals(5, fs2.getNextBlock(4));
- assertEquals(6, fs2.getNextBlock(5));
- assertEquals(7, fs2.getNextBlock(6));
- assertEquals(8, fs2.getNextBlock(7));
- assertEquals(9, fs2.getNextBlock(8));
- assertEquals(10, fs2.getNextBlock(9));
- assertEquals(11, fs2.getNextBlock(10));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getNextBlock(11));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getNextBlock(12));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs2.getNextBlock(13));
- assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE*14, fs2.size());
-
-
- // Check the data
- DirectoryEntry fsRoot = fs2.getRoot();
- assertEquals(1, fsRoot.getEntryCount());
-
- parentDir = (DirectoryEntry)fsRoot.getEntry("Parent Directory");
- assertEquals(1, parentDir.getEntryCount());
-
- testDir = (DirectoryEntry)parentDir.getEntry("Test Directory");
- assertEquals(2, testDir.getEntryCount());
-
- miniDoc = (DocumentEntry)testDir.getEntry("Mini");
- assertContentsMatches(mini, miniDoc);
-
- normDoc = (DocumentEntry)testDir.getEntry("Normal4096");
- assertContentsMatches(main4096, normDoc);
-
-
- // Add one more stream to each, then save and re-load
- byte[] mini2 = new byte[] { -42, 0, -1, -2, -3, -4, -42 };
- testDir.createDocument("Mini2", new ByteArrayInputStream(mini2));
-
- // Add to the main stream
- byte[] main4106 = new byte[4106];
- main4106[0] = 41;
- main4106[4105] = 42;
- testDir.createDocument("Normal4106", new ByteArrayInputStream(main4106));
-
-
- // Recheck the data in all 4 streams
- POIFSFileSystem fs3 = writeOutAndReadBack(fs2);
- fs2.close();
-
- fsRoot = fs3.getRoot();
- assertEquals(1, fsRoot.getEntryCount());
-
- parentDir = (DirectoryEntry)fsRoot.getEntry("Parent Directory");
- assertEquals(1, parentDir.getEntryCount());
-
- testDir = (DirectoryEntry)parentDir.getEntry("Test Directory");
- assertEquals(4, testDir.getEntryCount());
-
- miniDoc = (DocumentEntry)testDir.getEntry("Mini");
- assertContentsMatches(mini, miniDoc);
-
- miniDoc = (DocumentEntry)testDir.getEntry("Mini2");
- assertContentsMatches(mini2, miniDoc);
-
- normDoc = (DocumentEntry)testDir.getEntry("Normal4106");
- assertContentsMatches(main4106, normDoc);
-
- // All done
- fs3.close();
- }
-
- @Test
- public void readZeroLengthEntries() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("only-zero-byte-streams.ole2"));
- DirectoryNode testDir = fs.getRoot();
- assertEquals(3, testDir.getEntryCount());
- DocumentEntry entry;
-
- entry = (DocumentEntry)testDir.getEntry("test-zero-1");
- assertNotNull(entry);
- assertEquals(0, entry.getSize());
-
- entry = (DocumentEntry)testDir.getEntry("test-zero-2");
- assertNotNull(entry);
- assertEquals(0, entry.getSize());
-
- entry = (DocumentEntry)testDir.getEntry("test-zero-3");
- assertNotNull(entry);
- assertEquals(0, entry.getSize());
-
- // Check properties, all have zero length, no blocks
- PropertyTable props = fs._get_property_table();
- assertEquals(POIFSConstants.END_OF_CHAIN, props.getRoot().getStartBlock());
- for (Property prop : props.getRoot()) {
- assertEquals("test-zero-", prop.getName().substring(0, 10));
- assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
- }
-
- // All done
- fs.close();
- }
-
- @Test
- public void writeZeroLengthEntries() throws IOException {
- POIFSFileSystem fs1 = new POIFSFileSystem();
- DirectoryNode testDir = fs1.getRoot();
- DocumentEntry miniDoc;
- DocumentEntry normDoc;
- DocumentEntry emptyDoc;
-
- // Add mini and normal sized entries to start
- byte[] mini2 = new byte[] { -42, 0, -1, -2, -3, -4, -42 };
- testDir.createDocument("Mini2", new ByteArrayInputStream(mini2));
+ assertFalse(fs1.getBATBlockAndIndex(109 * 128 - 1).getBlock().hasFreeSectors());
+ assertTrue(fs1.getBATBlockAndIndex(110 * 128 - 1).getBlock().hasFreeSectors());
+ assertThrows(IndexOutOfBoundsException.class, () -> fs1.getBATBlockAndIndex(110 * 128), "Should only be 110 BATs");
+ assertBATCount(fs1, 110, 1);
- // Add to the main stream
- byte[] main4106 = new byte[4106];
- main4106[0] = 41;
- main4106[4105] = 42;
- testDir.createDocument("Normal4106", new ByteArrayInputStream(main4106));
+ header = writeOutAndReadHeader(fs1);
+ assertEquals(110, header.getBATCount());
+ assertEquals(1, header.getXBATCount());
- // Now add some empty ones
- byte[] empty = new byte[0];
- testDir.createDocument("empty-1", new ByteArrayInputStream(empty));
- testDir.createDocument("empty-2", new ByteArrayInputStream(empty));
- testDir.createDocument("empty-3", new ByteArrayInputStream(empty));
- // Check
- miniDoc = (DocumentEntry)testDir.getEntry("Mini2");
- assertContentsMatches(mini2, miniDoc);
-
- normDoc = (DocumentEntry)testDir.getEntry("Normal4106");
- assertContentsMatches(main4106, normDoc);
-
- emptyDoc = (DocumentEntry)testDir.getEntry("empty-1");
- assertContentsMatches(empty, emptyDoc);
-
- emptyDoc = (DocumentEntry)testDir.getEntry("empty-2");
- assertContentsMatches(empty, emptyDoc);
-
- emptyDoc = (DocumentEntry)testDir.getEntry("empty-3");
- assertContentsMatches(empty, emptyDoc);
-
- // Look at the properties entry, and check the empty ones
- // have zero size and no start block
- PropertyTable props = fs1._get_property_table();
- Iterator<Property> propsIt = props.getRoot().getChildren();
-
- Property prop = propsIt.next();
- assertEquals("Mini2", prop.getName());
- assertEquals(0, prop.getStartBlock());
- assertEquals(7, prop.getSize());
-
- prop = propsIt.next();
- assertEquals("Normal4106", prop.getName());
- assertEquals(4, prop.getStartBlock()); // BAT, Props, SBAT, MIni
- assertEquals(4106, prop.getSize());
-
- prop = propsIt.next();
- assertEquals("empty-1", prop.getName());
- assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
- assertEquals(0, prop.getSize());
-
- prop = propsIt.next();
- assertEquals("empty-2", prop.getName());
- assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
- assertEquals(0, prop.getSize());
-
- prop = propsIt.next();
- assertEquals("empty-3", prop.getName());
- assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
- assertEquals(0, prop.getSize());
-
-
- // Save and re-check
- POIFSFileSystem fs2 = writeOutAndReadBack(fs1);
- fs1.close();
- testDir = fs2.getRoot();
-
- miniDoc = (DocumentEntry)testDir.getEntry("Mini2");
- assertContentsMatches(mini2, miniDoc);
-
- normDoc = (DocumentEntry)testDir.getEntry("Normal4106");
- assertContentsMatches(main4106, normDoc);
-
- emptyDoc = (DocumentEntry)testDir.getEntry("empty-1");
- assertContentsMatches(empty, emptyDoc);
-
- emptyDoc = (DocumentEntry)testDir.getEntry("empty-2");
- assertContentsMatches(empty, emptyDoc);
-
- emptyDoc = (DocumentEntry)testDir.getEntry("empty-3");
- assertContentsMatches(empty, emptyDoc);
-
- // Check that a mini-stream was assigned, with one block used
- assertEquals(3, testDir.getProperty().getStartBlock());
- assertEquals(64, testDir.getProperty().getSize());
-
- // All done
- fs2.close();
- }
-
- /**
- * Test that we can read a file with POIFS, create a new POIFS instance,
- * write it out, read it with POIFS, and see the original data
- */
- @Test
- public void POIFSReadCopyWritePOIFSRead() throws IOException {
- File testFile = POIDataSamples.getSpreadSheetInstance().getFile("Simple.xls");
- POIFSFileSystem src = new POIFSFileSystem(testFile);
- byte[] wbDataExp = IOUtils.toByteArray(src.createDocumentInputStream("Workbook"));
-
- POIFSFileSystem nfs = new POIFSFileSystem();
- EntryUtils.copyNodes(src.getRoot(), nfs.getRoot());
- src.close();
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- nfs.writeFilesystem(bos);
- nfs.close();
-
- POIFSFileSystem pfs = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
- byte[] wbDataAct = IOUtils.toByteArray(pfs.createDocumentInputStream("Workbook"));
-
- assertThat(wbDataExp, equalTo(wbDataAct));
- pfs.close();
- }
-
- /**
- * Ensure that you can recursively delete directories and their
- * contents
- */
- @Test
- public void RecursiveDelete() throws IOException {
- File testFile = POIDataSamples.getSpreadSheetInstance().getFile("SimpleMacro.xls");
- POIFSFileSystem src = new POIFSFileSystem(testFile);
-
- // Starts out with 5 entries:
- // _VBA_PROJECT_CUR
- // SummaryInformation <(0x05)SummaryInformation>
- // DocumentSummaryInformation <(0x05)DocumentSummaryInformation>
- // Workbook
- // CompObj <(0x01)CompObj>
- assertEquals(5, _countChildren(src._get_property_table().getRoot()));
- assertEquals(5, src.getRoot().getEntryCount());
-
- // Grab the VBA project root
- DirectoryEntry vbaProj = (DirectoryEntry)src.getRoot().getEntry("_VBA_PROJECT_CUR");
- assertEquals(3, vbaProj.getEntryCount());
- // Can't delete yet, has stuff
- assertFalse(vbaProj.delete());
- // Recursively delete
- _recursiveDeletee(vbaProj);
-
- // Entries gone
- assertEquals(4, _countChildren(src._get_property_table().getRoot()));
- assertEquals(4, src.getRoot().getEntryCount());
-
- // Done
- src.close();
- }
- private void _recursiveDeletee(Entry entry) throws IOException {
- if (entry.isDocumentEntry()) {
- assertTrue(entry.delete());
- return;
- }
-
- DirectoryEntry dir = (DirectoryEntry)entry;
- String[] names = dir.getEntryNames().toArray(new String[dir.getEntryCount()]);
- for (String name : names) {
- Entry ce = dir.getEntry(name);
- _recursiveDeletee(ce);
- }
- assertTrue(dir.delete());
- }
- @SuppressWarnings("unused")
- private int _countChildren(DirectoryProperty p) {
- int count = 0;
- for (Property cp : p) { count++; }
- return count;
- }
-
- /**
- * To ensure we can create a file >2gb in size, as well as to
- * extend existing files past the 2gb boundary.
- *
- * Note that to run this test, you will require 2.5+gb of free
- * space on your TMP/TEMP partition/disk
- *
- * Note that to run this test, you need to be able to mmap 2.5+gb
- * files, which may need bigger kernel.shmmax and vm.max_map_count
- * settings on Linux.
- *
- * TODO Fix this to work...
- */
- @Test
- @Ignore("Work in progress test for #60670")
- public void creationAndExtensionPast2GB() throws Exception {
- File big = TempFile.createTempFile("poi-test-", ".ole2");
- Assume.assumeTrue("2.5gb of free space is required on your tmp/temp " +
- "partition/disk to run large file tests",
- big.getFreeSpace() > 2.5*1024*1024*1024);
- System.out.println("Slow, memory heavy test in progress....");
-
- int s100mb = 100*1024*1024;
- int s512mb = 512*1024*1024;
- long s2gb = 2L *1024*1024*1024;
- DocumentEntry entry;
- POIFSFileSystem fs;
-
- // Create a just-sub 2gb file
- fs = POIFSFileSystem.create(big);
- for (int i=0; i<19; i++) {
- fs.createDocument(new DummyDataInputStream(s100mb), "Entry"+i);
- }
- fs.writeFilesystem();
- fs.close();
-
- // Extend it past the 2gb mark
- fs = new POIFSFileSystem(big, false);
- for (int i=0; i<19; i++) {
- entry = (DocumentEntry)fs.getRoot().getEntry("Entry"+i);
- assertNotNull(entry);
- assertEquals(s100mb, entry.getSize());
- }
-
- fs.createDocument(new DummyDataInputStream(s512mb), "Bigger");
- fs.writeFilesystem();
- fs.close();
-
- // Check it still works
- fs = new POIFSFileSystem(big, false);
- for (int i=0; i<19; i++) {
- entry = (DocumentEntry)fs.getRoot().getEntry("Entry"+i);
- assertNotNull(entry);
- assertEquals(s100mb, entry.getSize());
- }
- entry = (DocumentEntry)fs.getRoot().getEntry("Bigger");
- assertNotNull(entry);
- assertEquals(s512mb, entry.getSize());
-
- // Tidy
- fs.close();
- assertTrue(big.delete());
-
-
- // Create a >2gb file
- fs = POIFSFileSystem.create(big);
- for (int i=0; i<4; i++) {
- fs.createDocument(new DummyDataInputStream(s512mb), "Entry"+i);
- }
- fs.writeFilesystem();
- fs.close();
-
- // Read it
- fs = new POIFSFileSystem(big, false);
- for (int i=0; i<4; i++) {
- entry = (DocumentEntry)fs.getRoot().getEntry("Entry"+i);
- assertNotNull(entry);
- assertEquals(s512mb, entry.getSize());
- }
-
- // Extend it
- fs.createDocument(new DummyDataInputStream(s512mb), "Entry4");
- fs.writeFilesystem();
- fs.close();
-
- // Check it worked
- fs = new POIFSFileSystem(big, false);
- for (int i=0; i<5; i++) {
- entry = (DocumentEntry)fs.getRoot().getEntry("Entry"+i);
- assertNotNull(entry);
- assertEquals(s512mb, entry.getSize());
- }
-
- // Tidy
- fs.close();
- assertTrue(big.delete());
-
- // Create a file with a 2gb entry
- fs = POIFSFileSystem.create(big);
- fs.createDocument(new DummyDataInputStream(s100mb), "Small");
- // TODO Check we get a helpful error about the max size
- fs.createDocument(new DummyDataInputStream(s2gb), "Big");
- }
-
- private static final class DummyDataInputStream extends InputStream {
- private final long maxSize;
- private long size;
- private DummyDataInputStream(long maxSize) {
- this.maxSize = maxSize;
- this.size = 0;
- }
-
- public int read() {
- if (size >= maxSize) return -1;
- size++;
- return (int)(size % 128);
- }
-
- public int read(byte[] b) {
- return read(b, 0, b.length);
- }
- public int read(byte[] b, int offset, int len) {
- if (size >= maxSize) return -1;
- int sz = (int)Math.min(len, maxSize-size);
- for (int i=0; i<sz; i++) {
- b[i+offset] = (byte)((size+i) % 128);
- }
- size += sz;
- return sz;
- }
- }
-
- @Ignore("Takes a long time to run")
- @Test
- public void performance() throws Exception {
- int iterations = 200;//1_000;
-
- System.out.println("NPOI:");
- long start = System.currentTimeMillis();
-
- for (int i = 0; i < iterations; i++) {
-
- try (InputStream inputStream = POIDataSamples.getHSMFInstance().openResourceAsStream("lots-of-recipients.msg");
- POIFSFileSystem srcFileSystem = new POIFSFileSystem(inputStream);
- POIFSFileSystem destFileSystem = new POIFSFileSystem()) {
-
- copyAllEntries(srcFileSystem.getRoot(), destFileSystem.getRoot());
-
- File file = File.createTempFile("npoi", ".dat");
- try (OutputStream outputStream = new FileOutputStream(file)) {
- destFileSystem.writeFilesystem(outputStream);
+ // Fill the XBAT, which means filling 127 BATs
+ for (int i = 109; i < 109 + 127; i++) {
+ fs1.getFreeBlock();
+ int startOffset = i * 128;
+ while (fs1.getBATBlockAndIndex(startOffset).getBlock().hasFreeSectors()) {
+ free = fs1.getFreeBlock();
+ fs1.setNextBlock(free, POIFSConstants.END_OF_CHAIN);
}
+ assertBATCount(fs1, i + 1, 1);
+ }
+
+ // Should now have 109+127 = 236 BATs
+ assertFalse(fs1.getBATBlockAndIndex(236 * 128 - 1).getBlock().hasFreeSectors());
+ assertThrows(IndexOutOfBoundsException.class, () -> fs1.getBATBlockAndIndex(236 * 128), "Should only be 236 BATs");
+ assertBATCount(fs1, 236, 1);
+
+
+ // Ask for another, will get our 2nd XBAT
+ free = fs1.getFreeBlock();
+ assertTrue(free > 0, "Had: " + free);
+
+ assertFalse(fs1.getBATBlockAndIndex(236 * 128 - 1).getBlock().hasFreeSectors());
+ assertTrue(fs1.getBATBlockAndIndex(237 * 128 - 1).getBlock().hasFreeSectors());
+ assertThrows(IndexOutOfBoundsException.class, () -> fs1.getBATBlockAndIndex(237 * 128), "Should only be 237 BATs");
+
+
+ // Check the counts now
+ assertBATCount(fs1, 237, 2);
+
+ // Check the header
+ header = writeOutAndReadHeader(fs1);
+ assertNotNull(header);
+
+ // Now, write it out, and read it back in again fully
+ POIFSFileSystem fs2 = writeOutAndReadBack(fs1);
+ fs1.close();
+
+ // Check that it is seen correctly
+ assertBATCount(fs2, 237, 2);
+
+ assertFalse(fs2.getBATBlockAndIndex(236 * 128 - 1).getBlock().hasFreeSectors());
+ assertTrue(fs2.getBATBlockAndIndex(237 * 128 - 1).getBlock().hasFreeSectors());
+ assertThrows(IndexOutOfBoundsException.class, () -> fs2.getBATBlockAndIndex(237 * 128), "Should only be 237 BATs");
+
+ // All done
+ fs2.close();
+ }
+
+ /**
+ * Test that we can correctly get the list of directory
+ * entries, and the details on the files in them
+ */
+ @Test
+ public void listEntries() throws IOException {
+ for (POIFSFileSystem fs : get512and4kFileAndInput()) {
+ DirectoryEntry root = fs.getRoot();
+ assertEquals(5, root.getEntryCount());
+
+ // Check by the names
+ Entry thumbnail = root.getEntry("Thumbnail");
+ Entry dsi = root.getEntry("\u0005DocumentSummaryInformation");
+ Entry si = root.getEntry("\u0005SummaryInformation");
+ Entry image = root.getEntry("Image");
+ Entry tags = root.getEntry("Tags");
+
+ assertFalse(thumbnail.isDirectoryEntry());
+ assertFalse(dsi.isDirectoryEntry());
+ assertFalse(si.isDirectoryEntry());
+ assertTrue(image.isDirectoryEntry());
+ assertFalse(tags.isDirectoryEntry());
+
+ // Check via the iterator
+ Iterator<Entry> it = root.getEntries();
+ assertEquals(thumbnail.getName(), it.next().getName());
+ assertEquals(dsi.getName(), it.next().getName());
+ assertEquals(si.getName(), it.next().getName());
+ assertEquals(image.getName(), it.next().getName());
+ assertEquals(tags.getName(), it.next().getName());
+
+ // Look inside another
+ DirectoryEntry imageD = (DirectoryEntry) image;
+ assertEquals(7, imageD.getEntryCount());
+
+ fs.close();
+ }
+ }
+
+ /**
+ * Tests that we can get the correct contents for
+ * a document in the filesystem
+ */
+ @Test
+ public void getDocumentEntry() throws Exception {
+ for (POIFSFileSystem fs : get512and4kFileAndInput()) {
+ DirectoryEntry root = fs.getRoot();
+ Entry si = root.getEntry("\u0005SummaryInformation");
+
+ assertTrue(si.isDocumentEntry());
+ DocumentNode doc = (DocumentNode) si;
+
+ // Check we can read it
+ assertContentsMatches(null, doc);
+
+ // Now try to build the property set
+ DocumentInputStream inp = new DocumentInputStream(doc);
+ PropertySet ps = PropertySetFactory.create(inp);
+ SummaryInformation inf = (SummaryInformation) ps;
+
+ // Check some bits in it
+ assertNull(inf.getApplicationName());
+ assertNull(inf.getAuthor());
+ assertNull(inf.getSubject());
+ assertEquals(131333, inf.getOSVersion());
+
+ // Finish with this one
+ inp.close();
+
+
+ // Try the other summary information
+ si = root.getEntry("\u0005DocumentSummaryInformation");
+ assertTrue(si.isDocumentEntry());
+ doc = (DocumentNode) si;
+ assertContentsMatches(null, doc);
+
+ inp = new DocumentInputStream(doc);
+ ps = PropertySetFactory.create(inp);
+ DocumentSummaryInformation dinf = (DocumentSummaryInformation) ps;
+ assertEquals(131333, dinf.getOSVersion());
+
+ fs.close();
+ }
+ }
+
+ /**
+ * Read a file, write it and read it again.
+ * Then, alter+add some streams, write and read
+ */
+ @Test
+ public void readWriteRead() throws Exception {
+ SummaryInformation sinf;
+ DocumentSummaryInformation dinf;
+ DirectoryEntry root, testDir;
+
+ for (POIFSFileSystem fs1 : get512and4kFileAndInput()) {
+ // Check we can find the entries we expect
+ root = fs1.getRoot();
+ assertEquals(5, root.getEntryCount());
+ assertThat(root.getEntryNames(), hasItem("Thumbnail"));
+ assertThat(root.getEntryNames(), hasItem("Image"));
+ assertThat(root.getEntryNames(), hasItem("Tags"));
+ assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
+ assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+
+
+ // Write out, re-load
+ POIFSFileSystem fs2 = writeOutAndReadBack(fs1);
+ fs1.close();
+
+ // Check they're still there
+ root = fs2.getRoot();
+ assertEquals(5, root.getEntryCount());
+ assertThat(root.getEntryNames(), hasItem("Thumbnail"));
+ assertThat(root.getEntryNames(), hasItem("Image"));
+ assertThat(root.getEntryNames(), hasItem("Tags"));
+ assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
+ assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+
+
+ // Check the contents of them - parse the summary block and check
+ sinf = (SummaryInformation) PropertySetFactory.create(new DocumentInputStream(
+ (DocumentEntry) root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
+ assertEquals(131333, sinf.getOSVersion());
+
+ dinf = (DocumentSummaryInformation) PropertySetFactory.create(new DocumentInputStream(
+ (DocumentEntry) root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
+ assertEquals(131333, dinf.getOSVersion());
+
+
+ // Add a test mini stream
+ testDir = root.createDirectory("Testing 123");
+ testDir.createDirectory("Testing 456");
+ testDir.createDirectory("Testing 789");
+ byte[] mini = new byte[]{42, 0, 1, 2, 3, 4, 42};
+ testDir.createDocument("Mini", new ByteArrayInputStream(mini));
+
+
+ // Write out, re-load
+ POIFSFileSystem fs3 = writeOutAndReadBack(fs2);
+ fs2.close();
+
+ root = fs3.getRoot();
+ testDir = (DirectoryEntry) root.getEntry("Testing 123");
+ assertEquals(6, root.getEntryCount());
+ assertThat(root.getEntryNames(), hasItem("Thumbnail"));
+ assertThat(root.getEntryNames(), hasItem("Image"));
+ assertThat(root.getEntryNames(), hasItem("Tags"));
+ assertThat(root.getEntryNames(), hasItem("Testing 123"));
+ assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
+ assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+
+
+ // Check old and new are there
+ sinf = (SummaryInformation) PropertySetFactory.create(new DocumentInputStream(
+ (DocumentEntry) root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
+ assertEquals(131333, sinf.getOSVersion());
+
+ dinf = (DocumentSummaryInformation) PropertySetFactory.create(new DocumentInputStream(
+ (DocumentEntry) root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
+ assertEquals(131333, dinf.getOSVersion());
+
+ assertContentsMatches(mini, (DocumentEntry) testDir.getEntry("Mini"));
+
+
+ // Write out and read once more, just to be sure
+ POIFSFileSystem fs4 = writeOutAndReadBack(fs3);
+ fs3.close();
+
+ root = fs4.getRoot();
+ testDir = (DirectoryEntry) root.getEntry("Testing 123");
+ assertEquals(6, root.getEntryCount());
+ assertThat(root.getEntryNames(), hasItem("Thumbnail"));
+ assertThat(root.getEntryNames(), hasItem("Image"));
+ assertThat(root.getEntryNames(), hasItem("Tags"));
+ assertThat(root.getEntryNames(), hasItem("Testing 123"));
+ assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
+ assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+
+ sinf = (SummaryInformation) PropertySetFactory.create(new DocumentInputStream(
+ (DocumentEntry) root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
+ assertEquals(131333, sinf.getOSVersion());
+
+ dinf = (DocumentSummaryInformation) PropertySetFactory.create(new DocumentInputStream(
+ (DocumentEntry) root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
+ assertEquals(131333, dinf.getOSVersion());
+
+ assertContentsMatches(mini, (DocumentEntry) testDir.getEntry("Mini"));
+
- assertTrue(file.delete());
- if (i % 10 == 0) System.out.print(".");
- }
- }
+ // Add a full stream, delete a full stream
+ byte[] main4096 = new byte[4096];
+ main4096[0] = -10;
+ main4096[4095] = -11;
+ testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096));
+
+ root.getEntry("Tags").delete();
+
+
+ // Write out, re-load
+ POIFSFileSystem fs5 = writeOutAndReadBack(fs4);
+ fs4.close();
+
+ // Check it's all there
+ root = fs5.getRoot();
+ testDir = (DirectoryEntry) root.getEntry("Testing 123");
+ assertEquals(5, root.getEntryCount());
+ assertThat(root.getEntryNames(), hasItem("Thumbnail"));
+ assertThat(root.getEntryNames(), hasItem("Image"));
+ assertThat(root.getEntryNames(), hasItem("Testing 123"));
+ assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
+ assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+
+
+ // Check old and new are there
+ sinf = (SummaryInformation) PropertySetFactory.create(new DocumentInputStream(
+ (DocumentEntry) root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
+ assertEquals(131333, sinf.getOSVersion());
+
+ dinf = (DocumentSummaryInformation) PropertySetFactory.create(new DocumentInputStream(
+ (DocumentEntry) root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
+ assertEquals(131333, dinf.getOSVersion());
+
+ assertContentsMatches(mini, (DocumentEntry) testDir.getEntry("Mini"));
+ assertContentsMatches(main4096, (DocumentEntry) testDir.getEntry("Normal4096"));
+
+
+ // Delete a directory, and add one more
+ testDir.getEntry("Testing 456").delete();
+ testDir.createDirectory("Testing ABC");
+
+
+ // Save
+ POIFSFileSystem fs6 = writeOutAndReadBack(fs5);
+ fs5.close();
+
+ // Check
+ root = fs6.getRoot();
+ testDir = (DirectoryEntry) root.getEntry("Testing 123");
+
+ assertEquals(5, root.getEntryCount());
+ assertThat(root.getEntryNames(), hasItem("Thumbnail"));
+ assertThat(root.getEntryNames(), hasItem("Image"));
+ assertThat(root.getEntryNames(), hasItem("Testing 123"));
+ assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
+ assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+
+ assertEquals(4, testDir.getEntryCount());
+ assertThat(testDir.getEntryNames(), hasItem("Mini"));
+ assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
+ assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
+ assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
+
+
+ // Add another mini stream
+ byte[] mini2 = new byte[]{-42, 0, -1, -2, -3, -4, -42};
+ testDir.createDocument("Mini2", new ByteArrayInputStream(mini2));
+
+ // Save, load, check
+ POIFSFileSystem fs7 = writeOutAndReadBack(fs6);
+ fs6.close();
+
+ root = fs7.getRoot();
+ testDir = (DirectoryEntry) root.getEntry("Testing 123");
+
+ assertEquals(5, root.getEntryCount());
+ assertThat(root.getEntryNames(), hasItem("Thumbnail"));
+ assertThat(root.getEntryNames(), hasItem("Image"));
+ assertThat(root.getEntryNames(), hasItem("Testing 123"));
+ assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
+ assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+
+ assertEquals(5, testDir.getEntryCount());
+ assertThat(testDir.getEntryNames(), hasItem("Mini"));
+ assertThat(testDir.getEntryNames(), hasItem("Mini2"));
+ assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
+ assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
+ assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
+
+ assertContentsMatches(mini, (DocumentEntry) testDir.getEntry("Mini"));
+ assertContentsMatches(mini2, (DocumentEntry) testDir.getEntry("Mini2"));
+ assertContentsMatches(main4096, (DocumentEntry) testDir.getEntry("Normal4096"));
+
+
+ // Delete a mini stream, add one more
+ testDir.getEntry("Mini").delete();
+
+ byte[] mini3 = new byte[]{42, 0, 42, 0, 42, 0, 42};
+ testDir.createDocument("Mini3", new ByteArrayInputStream(mini3));
+
+
+ // Save, load, check
+ POIFSFileSystem fs8 = writeOutAndReadBack(fs7);
+ fs7.close();
+
+ root = fs8.getRoot();
+ testDir = (DirectoryEntry) root.getEntry("Testing 123");
+
+ assertEquals(5, root.getEntryCount());
+ assertThat(root.getEntryNames(), hasItem("Thumbnail"));
+ assertThat(root.getEntryNames(), hasItem("Image"));
+ assertThat(root.getEntryNames(), hasItem("Testing 123"));
+ assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
+ assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+
+ assertEquals(5, testDir.getEntryCount());
+ assertThat(testDir.getEntryNames(), hasItem("Mini2"));
+ assertThat(testDir.getEntryNames(), hasItem("Mini3"));
+ assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
+ assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
+ assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
+
+ assertContentsMatches(mini2, (DocumentEntry) testDir.getEntry("Mini2"));
+ assertContentsMatches(mini3, (DocumentEntry) testDir.getEntry("Mini3"));
+ assertContentsMatches(main4096, (DocumentEntry) testDir.getEntry("Normal4096"));
+
+
+ // Change some existing streams
+ POIFSDocument mini2Doc = new POIFSDocument((DocumentNode) testDir.getEntry("Mini2"));
+ mini2Doc.replaceContents(new ByteArrayInputStream(mini));
+
+ byte[] main4106 = new byte[4106];
+ main4106[0] = 41;
+ main4106[4105] = 42;
+ POIFSDocument mainDoc = new POIFSDocument((DocumentNode) testDir.getEntry("Normal4096"));
+ mainDoc.replaceContents(new ByteArrayInputStream(main4106));
+
+
+ // Re-check
+ POIFSFileSystem fs9 = writeOutAndReadBack(fs8);
+ fs8.close();
+
+ root = fs9.getRoot();
+ testDir = (DirectoryEntry) root.getEntry("Testing 123");
+
+ assertEquals(5, root.getEntryCount());
+ assertThat(root.getEntryNames(), hasItem("Thumbnail"));
+ assertThat(root.getEntryNames(), hasItem("Image"));
+ assertThat(root.getEntryNames(), hasItem("Testing 123"));
+ assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
+ assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
+
+ assertEquals(5, testDir.getEntryCount());
+ assertThat(testDir.getEntryNames(), hasItem("Mini2"));
+ assertThat(testDir.getEntryNames(), hasItem("Mini3"));
+ assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
+ assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
+ assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
+
+ assertContentsMatches(mini, (DocumentEntry) testDir.getEntry("Mini2"));
+ assertContentsMatches(mini3, (DocumentEntry) testDir.getEntry("Mini3"));
+ assertContentsMatches(main4106, (DocumentEntry) testDir.getEntry("Normal4096"));
+
+
+ // All done
+ fs9.close();
+ }
+ }
+
+ /**
+ * Create a new file, write it and read it again
+ * Then, add some streams, write and read
+ */
+ @Test
+ public void createWriteRead() throws IOException {
+ POIFSFileSystem fs1 = new POIFSFileSystem();
+ DocumentEntry miniDoc;
+ DocumentEntry normDoc;
+
+ // Initially has Properties + BAT but not SBAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs1.getNextBlock(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs1.getNextBlock(2));
+
+ // Check that the SBAT is empty
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getRoot().getProperty().getStartBlock());
+
+ // Check that properties table was given block 0
+ assertEquals(0, fs1._get_property_table().getStartBlock());
+
+ // Write and read it
+ POIFSFileSystem fs2 = writeOutAndReadBack(fs1);
+ fs1.close();
+
+ // No change, SBAT remains empty
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs2.getNextBlock(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs2.getNextBlock(2));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs2.getNextBlock(3));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getRoot().getProperty().getStartBlock());
+ assertEquals(0, fs2._get_property_table().getStartBlock());
+ fs2.close();
+
+ // Check the same but with saving to a file
+ POIFSFileSystem fs3 = new POIFSFileSystem();
+ POIFSFileSystem fs4 = writeOutFileAndReadBack(fs3);
+ fs3.close();
+
+ // Same, no change, SBAT remains empty
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs4.getNextBlock(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(2));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(3));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getRoot().getProperty().getStartBlock());
+ assertEquals(0, fs4._get_property_table().getStartBlock());
+
+
+ // Put everything within a new directory
+ DirectoryEntry testDir = fs4.createDirectory("Test Directory");
+
+ // Add a new Normal Stream (Normal Streams minimum 4096 bytes)
+ byte[] main4096 = new byte[4096];
+ main4096[0] = -10;
+ main4096[4095] = -11;
+ testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096));
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs4.getNextBlock(1));
+ assertEquals(3, fs4.getNextBlock(2));
+ assertEquals(4, fs4.getNextBlock(3));
+ assertEquals(5, fs4.getNextBlock(4));
+ assertEquals(6, fs4.getNextBlock(5));
+ assertEquals(7, fs4.getNextBlock(6));
+ assertEquals(8, fs4.getNextBlock(7));
+ assertEquals(9, fs4.getNextBlock(8));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(9));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(10));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(11));
+ // SBAT still unused
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getRoot().getProperty().getStartBlock());
+
+
+ // Add a bigger Normal Stream
+ byte[] main5124 = new byte[5124];
+ main5124[0] = -22;
+ main5124[5123] = -33;
+ testDir.createDocument("Normal5124", new ByteArrayInputStream(main5124));
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs4.getNextBlock(1));
+ assertEquals(3, fs4.getNextBlock(2));
+ assertEquals(4, fs4.getNextBlock(3));
+ assertEquals(5, fs4.getNextBlock(4));
+ assertEquals(6, fs4.getNextBlock(5));
+ assertEquals(7, fs4.getNextBlock(6));
+ assertEquals(8, fs4.getNextBlock(7));
+ assertEquals(9, fs4.getNextBlock(8));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(9));
+
+ assertEquals(11, fs4.getNextBlock(10));
+ assertEquals(12, fs4.getNextBlock(11));
+ assertEquals(13, fs4.getNextBlock(12));
+ assertEquals(14, fs4.getNextBlock(13));
+ assertEquals(15, fs4.getNextBlock(14));
+ assertEquals(16, fs4.getNextBlock(15));
+ assertEquals(17, fs4.getNextBlock(16));
+ assertEquals(18, fs4.getNextBlock(17));
+ assertEquals(19, fs4.getNextBlock(18));
+ assertEquals(20, fs4.getNextBlock(19));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(20));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(21));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(22));
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getRoot().getProperty().getStartBlock());
+
+
+ // Now Add a mini stream
+ byte[] mini = new byte[]{42, 0, 1, 2, 3, 4, 42};
+ testDir.createDocument("Mini", new ByteArrayInputStream(mini));
+
+ // Mini stream will get one block for fat + one block for data
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs4.getNextBlock(1));
+ assertEquals(3, fs4.getNextBlock(2));
+ assertEquals(4, fs4.getNextBlock(3));
+ assertEquals(5, fs4.getNextBlock(4));
+ assertEquals(6, fs4.getNextBlock(5));
+ assertEquals(7, fs4.getNextBlock(6));
+ assertEquals(8, fs4.getNextBlock(7));
+ assertEquals(9, fs4.getNextBlock(8));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(9));
+
+ assertEquals(11, fs4.getNextBlock(10));
+ assertEquals(12, fs4.getNextBlock(11));
+ assertEquals(13, fs4.getNextBlock(12));
+ assertEquals(14, fs4.getNextBlock(13));
+ assertEquals(15, fs4.getNextBlock(14));
+ assertEquals(16, fs4.getNextBlock(15));
+ assertEquals(17, fs4.getNextBlock(16));
+ assertEquals(18, fs4.getNextBlock(17));
+ assertEquals(19, fs4.getNextBlock(18));
+ assertEquals(20, fs4.getNextBlock(19));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(20));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(21));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs4.getNextBlock(22));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs4.getNextBlock(23));
+
+ // Check the mini stream location was set
+ // (21 is mini fat, 22 is first mini stream block)
+ assertEquals(22, fs4.getRoot().getProperty().getStartBlock());
+
+
+ // Write and read back
+ POIFSFileSystem fs5 = writeOutAndReadBack(fs4);
+ fs4.close();
+ HeaderBlock header = writeOutAndReadHeader(fs5);
+
+ // Check the header has the right points in it
+ assertEquals(1, header.getBATCount());
+ assertEquals(1, header.getBATArray()[0]);
+ assertEquals(0, header.getPropertyStart());
+ assertEquals(1, header.getSBATCount());
+ assertEquals(21, header.getSBATStart());
+ assertEquals(22, fs5._get_property_table().getRoot().getStartBlock());
+
+ // Block use should be almost the same, except the properties
+ // stream will have grown out to cover 2 blocks
+ // Check the block use is all unchanged
+ assertEquals(23, fs5.getNextBlock(0)); // Properties now extends over 2 blocks
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs5.getNextBlock(1));
+
+ assertEquals(3, fs5.getNextBlock(2));
+ assertEquals(4, fs5.getNextBlock(3));
+ assertEquals(5, fs5.getNextBlock(4));
+ assertEquals(6, fs5.getNextBlock(5));
+ assertEquals(7, fs5.getNextBlock(6));
+ assertEquals(8, fs5.getNextBlock(7));
+ assertEquals(9, fs5.getNextBlock(8));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs5.getNextBlock(9)); // End of normal4096
+
+ assertEquals(11, fs5.getNextBlock(10));
+ assertEquals(12, fs5.getNextBlock(11));
+ assertEquals(13, fs5.getNextBlock(12));
+ assertEquals(14, fs5.getNextBlock(13));
+ assertEquals(15, fs5.getNextBlock(14));
+ assertEquals(16, fs5.getNextBlock(15));
+ assertEquals(17, fs5.getNextBlock(16));
+ assertEquals(18, fs5.getNextBlock(17));
+ assertEquals(19, fs5.getNextBlock(18));
+ assertEquals(20, fs5.getNextBlock(19));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs5.getNextBlock(20)); // End of normal5124
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs5.getNextBlock(21)); // Mini Stream FAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs5.getNextBlock(22)); // Mini Stream data
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs5.getNextBlock(23)); // Properties #2
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs5.getNextBlock(24));
+
+
+ // Check some data
+ assertEquals(1, fs5.getRoot().getEntryCount());
+ testDir = (DirectoryEntry) fs5.getRoot().getEntry("Test Directory");
+ assertEquals(3, testDir.getEntryCount());
+
+ miniDoc = (DocumentEntry) testDir.getEntry("Mini");
+ assertContentsMatches(mini, miniDoc);
+
+ normDoc = (DocumentEntry) testDir.getEntry("Normal4096");
+ assertContentsMatches(main4096, normDoc);
+
+ normDoc = (DocumentEntry) testDir.getEntry("Normal5124");
+ assertContentsMatches(main5124, normDoc);
+
+
+ // Delete a couple of streams
+ miniDoc.delete();
+ normDoc.delete();
+
+
+ // Check - will have un-used sectors now
+ POIFSFileSystem fs6 = writeOutAndReadBack(fs5);
+ fs5.close();
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs6.getNextBlock(0)); // Props back in 1 block
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs6.getNextBlock(1));
+
+ assertEquals(3, fs6.getNextBlock(2));
+ assertEquals(4, fs6.getNextBlock(3));
+ assertEquals(5, fs6.getNextBlock(4));
+ assertEquals(6, fs6.getNextBlock(5));
+ assertEquals(7, fs6.getNextBlock(6));
+ assertEquals(8, fs6.getNextBlock(7));
+ assertEquals(9, fs6.getNextBlock(8));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs6.getNextBlock(9)); // End of normal4096
+
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(10));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(11));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(12));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(13));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(14));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(15));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(16));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(17));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(18));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(19));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(20));
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs6.getNextBlock(21)); // Mini Stream FAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs6.getNextBlock(22)); // Mini Stream data
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(23)); // Properties gone
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(24));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs6.getNextBlock(25));
+
+ // All done
+ fs6.close();
+ }
+
+ @Test
+ public void addBeforeWrite() throws IOException {
+ POIFSFileSystem fs1 = new POIFSFileSystem();
+ DocumentEntry miniDoc;
+ DocumentEntry normDoc;
+ HeaderBlock hdr;
+
+ // Initially has Properties + BAT but nothing else
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs1.getNextBlock(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs1.getNextBlock(2));
+
+ hdr = writeOutAndReadHeader(fs1);
+ // No mini stream, and no xbats
+ // Will have fat then properties stream
+ assertEquals(1, hdr.getBATCount());
+ assertEquals(1, hdr.getBATArray()[0]);
+ assertEquals(0, hdr.getPropertyStart());
+ assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getSBATStart());
+ assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
+ assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE * 3, fs1.size());
+ fs1.close();
+
+ // Get a clean filesystem to start with
+ fs1 = new POIFSFileSystem();
+
+ // Put our test files in a non-standard place
+ DirectoryEntry parentDir = fs1.createDirectory("Parent Directory");
+ DirectoryEntry testDir = parentDir.createDirectory("Test Directory");
+
+
+ // Add to the mini stream
+ byte[] mini = new byte[]{42, 0, 1, 2, 3, 4, 42};
+ testDir.createDocument("Mini", new ByteArrayInputStream(mini));
+
+ // Add to the main stream
+ byte[] main4096 = new byte[4096];
+ main4096[0] = -10;
+ main4096[4095] = -11;
+ testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096));
+
+
+ // Check the mini stream was added, then the main stream
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs1.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(2)); // Mini Fat
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(3)); // Mini Stream
+ assertEquals(5, fs1.getNextBlock(4)); // Main Stream
+ assertEquals(6, fs1.getNextBlock(5));
+ assertEquals(7, fs1.getNextBlock(6));
+ assertEquals(8, fs1.getNextBlock(7));
+ assertEquals(9, fs1.getNextBlock(8));
+ assertEquals(10, fs1.getNextBlock(9));
+ assertEquals(11, fs1.getNextBlock(10));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs1.getNextBlock(11));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs1.getNextBlock(12));
+ assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE * 13, fs1.size());
+
+
+ // Check that we can read the right data pre-write
+ miniDoc = (DocumentEntry) testDir.getEntry("Mini");
+ assertContentsMatches(mini, miniDoc);
+
+ normDoc = (DocumentEntry) testDir.getEntry("Normal4096");
+ assertContentsMatches(main4096, normDoc);
+
+
+ // Write, read, check
+ hdr = writeOutAndReadHeader(fs1);
+ POIFSFileSystem fs2 = writeOutAndReadBack(fs1);
+ fs1.close();
+
+ // Check the header details - will have the sbat near the start,
+ // then the properties at the end
+ assertEquals(1, hdr.getBATCount());
+ assertEquals(1, hdr.getBATArray()[0]);
+ assertEquals(2, hdr.getSBATStart());
+ assertEquals(0, hdr.getPropertyStart());
+ assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
+
+ // Check the block allocation is unchanged, other than
+ // the properties stream going in at the end
+ assertEquals(12, fs2.getNextBlock(0)); // Properties
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs2.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getNextBlock(2));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getNextBlock(3));
+ assertEquals(5, fs2.getNextBlock(4));
+ assertEquals(6, fs2.getNextBlock(5));
+ assertEquals(7, fs2.getNextBlock(6));
+ assertEquals(8, fs2.getNextBlock(7));
+ assertEquals(9, fs2.getNextBlock(8));
+ assertEquals(10, fs2.getNextBlock(9));
+ assertEquals(11, fs2.getNextBlock(10));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getNextBlock(11));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs2.getNextBlock(12));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs2.getNextBlock(13));
+ assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE * 14, fs2.size());
+
+
+ // Check the data
+ DirectoryEntry fsRoot = fs2.getRoot();
+ assertEquals(1, fsRoot.getEntryCount());
+
+ parentDir = (DirectoryEntry) fsRoot.getEntry("Parent Directory");
+ assertEquals(1, parentDir.getEntryCount());
+
+ testDir = (DirectoryEntry) parentDir.getEntry("Test Directory");
+ assertEquals(2, testDir.getEntryCount());
+
+ miniDoc = (DocumentEntry) testDir.getEntry("Mini");
+ assertContentsMatches(mini, miniDoc);
+
+ normDoc = (DocumentEntry) testDir.getEntry("Normal4096");
+ assertContentsMatches(main4096, normDoc);
+
+
+ // Add one more stream to each, then save and re-load
+ byte[] mini2 = new byte[]{-42, 0, -1, -2, -3, -4, -42};
+ testDir.createDocument("Mini2", new ByteArrayInputStream(mini2));
+
+ // Add to the main stream
+ byte[] main4106 = new byte[4106];
+ main4106[0] = 41;
+ main4106[4105] = 42;
+ testDir.createDocument("Normal4106", new ByteArrayInputStream(main4106));
+
+
+ // Recheck the data in all 4 streams
+ POIFSFileSystem fs3 = writeOutAndReadBack(fs2);
+ fs2.close();
+
+ fsRoot = fs3.getRoot();
+ assertEquals(1, fsRoot.getEntryCount());
+
+ parentDir = (DirectoryEntry) fsRoot.getEntry("Parent Directory");
+ assertEquals(1, parentDir.getEntryCount());
+
+ testDir = (DirectoryEntry) parentDir.getEntry("Test Directory");
+ assertEquals(4, testDir.getEntryCount());
+
+ miniDoc = (DocumentEntry) testDir.getEntry("Mini");
+ assertContentsMatches(mini, miniDoc);
+
+ miniDoc = (DocumentEntry) testDir.getEntry("Mini2");
+ assertContentsMatches(mini2, miniDoc);
+
+ normDoc = (DocumentEntry) testDir.getEntry("Normal4106");
+ assertContentsMatches(main4106, normDoc);
+
+ // All done
+ fs3.close();
+ }
+
+ @Test
+ public void readZeroLengthEntries() throws IOException {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("only-zero-byte-streams.ole2"));
+ DirectoryNode testDir = fs.getRoot();
+ assertEquals(3, testDir.getEntryCount());
+ DocumentEntry entry;
+
+ entry = (DocumentEntry) testDir.getEntry("test-zero-1");
+ assertNotNull(entry);
+ assertEquals(0, entry.getSize());
+
+ entry = (DocumentEntry) testDir.getEntry("test-zero-2");
+ assertNotNull(entry);
+ assertEquals(0, entry.getSize());
+
+ entry = (DocumentEntry) testDir.getEntry("test-zero-3");
+ assertNotNull(entry);
+ assertEquals(0, entry.getSize());
+
+ // Check properties, all have zero length, no blocks
+ PropertyTable props = fs._get_property_table();
+ assertEquals(POIFSConstants.END_OF_CHAIN, props.getRoot().getStartBlock());
+ for (Property prop : props.getRoot()) {
+ assertEquals("test-zero-", prop.getName().substring(0, 10));
+ assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
+ }
+
+ // All done
+ fs.close();
+ }
+
+ @Test
+ public void writeZeroLengthEntries() throws IOException {
+ POIFSFileSystem fs1 = new POIFSFileSystem();
+ DirectoryNode testDir = fs1.getRoot();
+ DocumentEntry miniDoc;
+ DocumentEntry normDoc;
+ DocumentEntry emptyDoc;
+
+ // Add mini and normal sized entries to start
+ byte[] mini2 = new byte[]{-42, 0, -1, -2, -3, -4, -42};
+ testDir.createDocument("Mini2", new ByteArrayInputStream(mini2));
+
+ // Add to the main stream
+ byte[] main4106 = new byte[4106];
+ main4106[0] = 41;
+ main4106[4105] = 42;
+ testDir.createDocument("Normal4106", new ByteArrayInputStream(main4106));
+
+ // Now add some empty ones
+ byte[] empty = new byte[0];
+ testDir.createDocument("empty-1", new ByteArrayInputStream(empty));
+ testDir.createDocument("empty-2", new ByteArrayInputStream(empty));
+ testDir.createDocument("empty-3", new ByteArrayInputStream(empty));
+
+ // Check
+ miniDoc = (DocumentEntry) testDir.getEntry("Mini2");
+ assertContentsMatches(mini2, miniDoc);
+
+ normDoc = (DocumentEntry) testDir.getEntry("Normal4106");
+ assertContentsMatches(main4106, normDoc);
+
+ emptyDoc = (DocumentEntry) testDir.getEntry("empty-1");
+ assertContentsMatches(empty, emptyDoc);
+
+ emptyDoc = (DocumentEntry) testDir.getEntry("empty-2");
+ assertContentsMatches(empty, emptyDoc);
+
+ emptyDoc = (DocumentEntry) testDir.getEntry("empty-3");
+ assertContentsMatches(empty, emptyDoc);
+
+ // Look at the properties entry, and check the empty ones
+ // have zero size and no start block
+ PropertyTable props = fs1._get_property_table();
+ Iterator<Property> propsIt = props.getRoot().getChildren();
+
+ Property prop = propsIt.next();
+ assertEquals("Mini2", prop.getName());
+ assertEquals(0, prop.getStartBlock());
+ assertEquals(7, prop.getSize());
+
+ prop = propsIt.next();
+ assertEquals("Normal4106", prop.getName());
+ assertEquals(4, prop.getStartBlock()); // BAT, Props, SBAT, MIni
+ assertEquals(4106, prop.getSize());
+
+ prop = propsIt.next();
+ assertEquals("empty-1", prop.getName());
+ assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
+ assertEquals(0, prop.getSize());
+
+ prop = propsIt.next();
+ assertEquals("empty-2", prop.getName());
+ assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
+ assertEquals(0, prop.getSize());
+
+ prop = propsIt.next();
+ assertEquals("empty-3", prop.getName());
+ assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
+ assertEquals(0, prop.getSize());
+
+
+ // Save and re-check
+ POIFSFileSystem fs2 = writeOutAndReadBack(fs1);
+ fs1.close();
+ testDir = fs2.getRoot();
+
+ miniDoc = (DocumentEntry) testDir.getEntry("Mini2");
+ assertContentsMatches(mini2, miniDoc);
+
+ normDoc = (DocumentEntry) testDir.getEntry("Normal4106");
+ assertContentsMatches(main4106, normDoc);
+
+ emptyDoc = (DocumentEntry) testDir.getEntry("empty-1");
+ assertContentsMatches(empty, emptyDoc);
+
+ emptyDoc = (DocumentEntry) testDir.getEntry("empty-2");
+ assertContentsMatches(empty, emptyDoc);
+
+ emptyDoc = (DocumentEntry) testDir.getEntry("empty-3");
+ assertContentsMatches(empty, emptyDoc);
+
+ // Check that a mini-stream was assigned, with one block used
+ assertEquals(3, testDir.getProperty().getStartBlock());
+ assertEquals(64, testDir.getProperty().getSize());
+
+ // All done
+ fs2.close();
+ }
+
+ /**
+ * Test that we can read a file with POIFS, create a new POIFS instance,
+ * write it out, read it with POIFS, and see the original data
+ */
+ @Test
+ public void POIFSReadCopyWritePOIFSRead() throws IOException {
+ File testFile = POIDataSamples.getSpreadSheetInstance().getFile("Simple.xls");
+ POIFSFileSystem src = new POIFSFileSystem(testFile);
+ byte[] wbDataExp = IOUtils.toByteArray(src.createDocumentInputStream("Workbook"));
+
+ POIFSFileSystem nfs = new POIFSFileSystem();
+ EntryUtils.copyNodes(src.getRoot(), nfs.getRoot());
+ src.close();
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ nfs.writeFilesystem(bos);
+ nfs.close();
+
+ POIFSFileSystem pfs = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
+ byte[] wbDataAct = IOUtils.toByteArray(pfs.createDocumentInputStream("Workbook"));
+
+ assertThat(wbDataExp, equalTo(wbDataAct));
+ pfs.close();
+ }
+
+ /**
+ * Ensure that you can recursively delete directories and their
+ * contents
+ */
+ @Test
+ public void RecursiveDelete() throws IOException {
+ File testFile = POIDataSamples.getSpreadSheetInstance().getFile("SimpleMacro.xls");
+ POIFSFileSystem src = new POIFSFileSystem(testFile);
+
+ // Starts out with 5 entries:
+ // _VBA_PROJECT_CUR
+ // SummaryInformation <(0x05)SummaryInformation>
+ // DocumentSummaryInformation <(0x05)DocumentSummaryInformation>
+ // Workbook
+ // CompObj <(0x01)CompObj>
+ assertEquals(5, _countChildren(src._get_property_table().getRoot()));
+ assertEquals(5, src.getRoot().getEntryCount());
+
+ // Grab the VBA project root
+ DirectoryEntry vbaProj = (DirectoryEntry) src.getRoot().getEntry("_VBA_PROJECT_CUR");
+ assertEquals(3, vbaProj.getEntryCount());
+ // Can't delete yet, has stuff
+ assertFalse(vbaProj.delete());
+ // Recursively delete
+ _recursiveDeletee(vbaProj);
+
+ // Entries gone
+ assertEquals(4, _countChildren(src._get_property_table().getRoot()));
+ assertEquals(4, src.getRoot().getEntryCount());
+
+ // Done
+ src.close();
+ }
+
+ private void _recursiveDeletee(Entry entry) throws IOException {
+ if (entry.isDocumentEntry()) {
+ assertTrue(entry.delete());
+ return;
+ }
+
+ DirectoryEntry dir = (DirectoryEntry) entry;
+ String[] names = dir.getEntryNames().toArray(new String[dir.getEntryCount()]);
+ for (String name : names) {
+ Entry ce = dir.getEntry(name);
+ _recursiveDeletee(ce);
+ }
+ assertTrue(dir.delete());
+ }
+
+ @SuppressWarnings("unused")
+ private int _countChildren(DirectoryProperty p) {
+ int count = 0;
+ for (Property cp : p) {
+ count++;
+ }
+ return count;
+ }
+
+ /**
+ * To ensure we can create a file >2gb in size, as well as to
+ * extend existing files past the 2gb boundary.
+ * <p>
+ * Note that to run this test, you will require 2.5+gb of free
+ * space on your TMP/TEMP partition/disk
+ * <p>
+ * Note that to run this test, you need to be able to mmap 2.5+gb
+ * files, which may need bigger kernel.shmmax and vm.max_map_count
+ * settings on Linux.
+ * <p>
+ * TODO Fix this to work...
+ */
+ @Test
+ @Disabled("Work in progress test for #60670")
+ public void creationAndExtensionPast2GB() throws Exception {
+ File big = TempFile.createTempFile("poi-test-", ".ole2");
+ assumeTrue(big.getFreeSpace() > 2.5 * 1024 * 1024 * 1024,
+ "2.5gb of free space is required on your tmp/temp partition/disk to run large file tests");
+ System.out.println("Slow, memory heavy test in progress....");
+
+ int s100mb = 100 * 1024 * 1024;
+ int s512mb = 512 * 1024 * 1024;
+ long s2gb = 2L * 1024 * 1024 * 1024;
+ DocumentEntry entry;
+ POIFSFileSystem fs;
+
+ // Create a just-sub 2gb file
+ fs = POIFSFileSystem.create(big);
+ for (int i = 0; i < 19; i++) {
+ fs.createDocument(new DummyDataInputStream(s100mb), "Entry" + i);
+ }
+ fs.writeFilesystem();
+ fs.close();
+
+ // Extend it past the 2gb mark
+ fs = new POIFSFileSystem(big, false);
+ for (int i = 0; i < 19; i++) {
+ entry = (DocumentEntry) fs.getRoot().getEntry("Entry" + i);
+ assertNotNull(entry);
+ assertEquals(s100mb, entry.getSize());
+ }
+
+ fs.createDocument(new DummyDataInputStream(s512mb), "Bigger");
+ fs.writeFilesystem();
+ fs.close();
+
+ // Check it still works
+ fs = new POIFSFileSystem(big, false);
+ for (int i = 0; i < 19; i++) {
+ entry = (DocumentEntry) fs.getRoot().getEntry("Entry" + i);
+ assertNotNull(entry);
+ assertEquals(s100mb, entry.getSize());
+ }
+ entry = (DocumentEntry) fs.getRoot().getEntry("Bigger");
+ assertNotNull(entry);
+ assertEquals(s512mb, entry.getSize());
+
+ // Tidy
+ fs.close();
+ assertTrue(big.delete());
+
+
+ // Create a >2gb file
+ fs = POIFSFileSystem.create(big);
+ for (int i = 0; i < 4; i++) {
+ fs.createDocument(new DummyDataInputStream(s512mb), "Entry" + i);
+ }
+ fs.writeFilesystem();
+ fs.close();
+
+ // Read it
+ fs = new POIFSFileSystem(big, false);
+ for (int i = 0; i < 4; i++) {
+ entry = (DocumentEntry) fs.getRoot().getEntry("Entry" + i);
+ assertNotNull(entry);
+ assertEquals(s512mb, entry.getSize());
+ }
+
+ // Extend it
+ fs.createDocument(new DummyDataInputStream(s512mb), "Entry4");
+ fs.writeFilesystem();
+ fs.close();
+
+ // Check it worked
+ fs = new POIFSFileSystem(big, false);
+ for (int i = 0; i < 5; i++) {
+ entry = (DocumentEntry) fs.getRoot().getEntry("Entry" + i);
+ assertNotNull(entry);
+ assertEquals(s512mb, entry.getSize());
+ }
+
+ // Tidy
+ fs.close();
+ assertTrue(big.delete());
+
+ // Create a file with a 2gb entry
+ fs = POIFSFileSystem.create(big);
+ fs.createDocument(new DummyDataInputStream(s100mb), "Small");
+ // TODO Check we get a helpful error about the max size
+ fs.createDocument(new DummyDataInputStream(s2gb), "Big");
+ }
+
+ private static final class DummyDataInputStream extends InputStream {
+ private final long maxSize;
+ private long size;
+
+ private DummyDataInputStream(long maxSize) {
+ this.maxSize = maxSize;
+ this.size = 0;
+ }
+
+ public int read() {
+ if (size >= maxSize) return -1;
+ size++;
+ return (int) (size % 128);
+ }
+
+ public int read(byte[] b) {
+ return read(b, 0, b.length);
+ }
+
+ public int read(byte[] b, int offset, int len) {
+ if (size >= maxSize) return -1;
+ int sz = (int) Math.min(len, maxSize - size);
+ for (int i = 0; i < sz; i++) {
+ b[i + offset] = (byte) ((size + i) % 128);
+ }
+ size += sz;
+ return sz;
+ }
+ }
+
+ @Disabled("Takes a long time to run")
+ @Test
+ public void performance() throws Exception {
+ int iterations = 200;//1_000;
+
+ System.out.println("NPOI:");
+ long start = System.currentTimeMillis();
+
+ for (int i = 0; i < iterations; i++) {
+
+ try (InputStream inputStream = POIDataSamples.getHSMFInstance().openResourceAsStream("lots-of-recipients.msg");
+ POIFSFileSystem srcFileSystem = new POIFSFileSystem(inputStream);
+ POIFSFileSystem destFileSystem = new POIFSFileSystem()) {
+
+ copyAllEntries(srcFileSystem.getRoot(), destFileSystem.getRoot());
+
+ File file = File.createTempFile("npoi", ".dat");
+ try (OutputStream outputStream = new FileOutputStream(file)) {
+ destFileSystem.writeFilesystem(outputStream);
+ }
+
+ assertTrue(file.delete());
+ if (i % 10 == 0) System.out.print(".");
+ }
+ }
- System.out.println();
- System.out.println("NPOI took: " + (System.currentTimeMillis() - start));
+ System.out.println();
+ System.out.println("NPOI took: " + (System.currentTimeMillis() - start));
- System.out.println();
- System.out.println();
- }
+ System.out.println();
+ System.out.println();
+ }
- private static void copyAllEntries(DirectoryEntry srcDirectory, DirectoryEntry destDirectory) throws IOException {
- Iterator<Entry> iterator = srcDirectory.getEntries();
+ private static void copyAllEntries(DirectoryEntry srcDirectory, DirectoryEntry destDirectory) throws IOException {
+ Iterator<Entry> iterator = srcDirectory.getEntries();
- while (iterator.hasNext()) {
- Entry entry = iterator.next();
+ while (iterator.hasNext()) {
+ Entry entry = iterator.next();
- if (entry.isDirectoryEntry()) {
- DirectoryEntry childDest = destDirectory.createDirectory(entry.getName());
- copyAllEntries((DirectoryEntry) entry, childDest);
+ if (entry.isDirectoryEntry()) {
+ DirectoryEntry childDest = destDirectory.createDirectory(entry.getName());
+ copyAllEntries((DirectoryEntry) entry, childDest);
- } else {
- DocumentEntry srcEntry = (DocumentEntry) entry;
+ } else {
+ DocumentEntry srcEntry = (DocumentEntry) entry;
- try (InputStream inputStream = new DocumentInputStream(srcEntry)) {
- destDirectory.createDocument(entry.getName(), inputStream);
+ try (InputStream inputStream = new DocumentInputStream(srcEntry)) {
+ destDirectory.createDocument(entry.getName(), inputStream);
+ }
}
- }
- }
- }
+ }
+ }
}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java
index f9fb199f02..aa50517cbf 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java
@@ -17,9 +17,9 @@
package org.apache.poi.poifs.filesystem;
-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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -35,7 +35,7 @@ import java.util.stream.Stream;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.property.DirectoryProperty;
import org.apache.poi.poifs.property.Property;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Verify the order of entries <code>DirectoryProperty</code> .
diff --git a/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java b/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java
index caf1222359..9429961c61 100644
--- a/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java
+++ b/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java
@@ -21,13 +21,13 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.StringUtil;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import static org.apache.poi.POITestCase.assertContains;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+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 java.io.File;
import java.io.FileInputStream;
@@ -52,7 +52,7 @@ public class TestVBAMacroReader {
}
String testMacroContents = new String(bytes, StringUtil.UTF8);
-
+
if (! testMacroContents.startsWith("Sub ")) {
throw new IllegalArgumentException("Not a macro");
}
@@ -73,7 +73,7 @@ public class TestVBAMacroReader {
}
expectedMacroContents = Collections.unmodifiableMap(_expectedMacroContents);
}
-
+
//////////////////////////////// From Stream /////////////////////////////
@Test
public void HSSFFromStream() throws Exception {
@@ -83,7 +83,7 @@ public class TestVBAMacroReader {
public void XSSFFromStream() throws Exception {
fromStream(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xlsm");
}
- @Ignore("bug 59302: Found 0 macros; See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF()" +
+ @Disabled("bug 59302: Found 0 macros; See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF()" +
"for an example of how to get macros out of ppt. TODO: make integration across file formats more elegant")
@Test
public void HSLFFromStream() throws Exception {
@@ -101,7 +101,7 @@ public class TestVBAMacroReader {
public void XWPFFromStream() throws Exception {
fromStream(POIDataSamples.getDocumentInstance(), "SimpleMacro.docm");
}
- @Ignore("Found 0 macros")
+ @Disabled("Found 0 macros")
@Test
public void HDGFFromStream() throws Exception {
fromStream(POIDataSamples.getDiagramInstance(), "SimpleMacro.vsd");
@@ -120,7 +120,7 @@ public class TestVBAMacroReader {
public void XSSFFromFile() throws Exception {
fromFile(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xlsm");
}
- @Ignore("bug 59302: Found 0 macros; See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF()" +
+ @Disabled("bug 59302: Found 0 macros; See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF()" +
"for an example of how to get macros out of ppt. TODO: make integration across file formats more elegant")
@Test
public void HSLFFromFile() throws Exception {
@@ -138,7 +138,7 @@ public class TestVBAMacroReader {
public void XWPFFromFile() throws Exception {
fromFile(POIDataSamples.getDocumentInstance(), "SimpleMacro.docm");
}
- @Ignore("Found 0 macros")
+ @Disabled("Found 0 macros")
@Test
public void HDGFFromFile() throws Exception {
fromFile(POIDataSamples.getDiagramInstance(), "SimpleMacro.vsd");
@@ -153,7 +153,7 @@ public class TestVBAMacroReader {
public void HSSFFromPOIFS() throws Exception {
fromPOIFS(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xls");
}
- @Ignore("bug 59302: Found 0 macros")
+ @Disabled("bug 59302: Found 0 macros")
@Test
public void HSLFFromPOIFS() throws Exception {
fromPOIFS(POIDataSamples.getSlideShowInstance(), "SimpleMacro.ppt");
@@ -162,7 +162,7 @@ public class TestVBAMacroReader {
public void HWPFFromPOIFS() throws Exception {
fromPOIFS(POIDataSamples.getDocumentInstance(), "SimpleMacro.doc");
}
- @Ignore("Found 0 macros")
+ @Disabled("Found 0 macros")
@Test
public void HDGFFromPOIFS() throws Exception {
fromPOIFS(POIDataSamples.getDiagramInstance(), "SimpleMacro.vsd");
@@ -191,21 +191,21 @@ public class TestVBAMacroReader {
}
}
}
-
+
private void assertMacroContents(POIDataSamples samples, VBAMacroReader r) throws IOException {
assertNotNull(r);
Map<String,Module> contents = r.readMacroModules();
assertNotNull(contents);
- assertFalse("Found 0 macros", contents.isEmpty());
+ assertFalse(contents.isEmpty(), "Found 0 macros");
/*
assertEquals(5, contents.size());
-
+
// Check the ones without scripts
String[] noScripts = new String[] { "ThisWorkbook",
"Sheet1", "Sheet2", "Sheet3" };
for (String entry : noScripts) {
assertTrue(entry, contents.containsKey(entry));
-
+
String content = contents.get(entry);
assertContains(content, "Attribute VB_Exposed = True");
assertContains(content, "Attribute VB_Customizable = True");
@@ -214,7 +214,7 @@ public class TestVBAMacroReader {
assertContains(content, "Attribute VB_Exposed = True");
}
*/
-
+
// Check the script one
assertContains(contents, "Module1");
Module module = contents.get("Module1");
diff --git a/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java b/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java
index bb549f7a14..8373d8f795 100644
--- a/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java
+++ b/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java
@@ -19,10 +19,10 @@
package org.apache.poi.poifs.nio;
-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 java.io.File;
import java.io.FileOutputStream;
@@ -35,31 +35,25 @@ import java.nio.ByteBuffer;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.TempFile;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for the datasource implementations
*/
public class TestDataSource {
- private static POIDataSamples data = POIDataSamples.getPOIFSInstance();
+ private static final POIDataSamples data = POIDataSamples.getPOIFSInstance();
@Test
public void testFile() throws Exception {
File f = data.getFile("Notes.ole2");
- FileBackedDataSource ds = new FileBackedDataSource(f);
- try {
+ try (FileBackedDataSource ds = new FileBackedDataSource(f)) {
checkDataSource(ds, false);
- } finally {
- ds.close();
}
// try a second time
- ds = new FileBackedDataSource(f);
- try {
+ try (FileBackedDataSource ds = new FileBackedDataSource(f)) {
checkDataSource(ds, false);
- } finally {
- ds.close();
}
}
@@ -69,25 +63,19 @@ public class TestDataSource {
try {
writeDataToFile(temp);
- FileBackedDataSource ds = new FileBackedDataSource(temp, false);
- try {
+ try (FileBackedDataSource ds = new FileBackedDataSource(temp, false)) {
checkDataSource(ds, true);
- } finally {
- ds.close();
}
// try a second time
- ds = new FileBackedDataSource(temp, false);
- try {
+ try (FileBackedDataSource ds = new FileBackedDataSource(temp, false)) {
checkDataSource(ds, true);
- } finally {
- ds.close();
}
writeDataToFile(temp);
} finally {
assertTrue(temp.exists());
- assertTrue("Could not delete file " + temp, temp.delete());
+ assertTrue(temp.delete(), "Could not delete file " + temp);
}
}
@@ -98,25 +86,21 @@ public class TestDataSource {
try {
writeDataToFile(temp);
- FileBackedDataSource ds = new FileBackedDataSource(temp, true);
- try {
+ ;
+ try (FileBackedDataSource ds = new FileBackedDataSource(temp, true)) {
ByteBuffer buf = ds.read(0, 10);
assertNotNull(buf);
buf = ds.read(8, 0x400);
assertNotNull(buf);
- } finally {
- ds.close();
}
// try a second time
- ds = new FileBackedDataSource(temp, true);
- try {
+ ;
+ try (FileBackedDataSource ds = new FileBackedDataSource(temp, true)) {
ByteBuffer buf = ds.read(0, 10);
assertNotNull(buf);
buf = ds.read(8, 0x400);
assertNotNull(buf);
- } finally {
- ds.close();
}
writeDataToFile(temp);
@@ -140,7 +124,7 @@ public class TestDataSource {
// rewriting changes the size
if (writeable) {
- assertTrue("Had: " + ds.size(), ds.size() == 8192 || ds.size() == 8198);
+ assertTrue(ds.size() == 8192 || ds.size() == 8198, "Had: " + ds.size());
} else {
assertEquals(8192, ds.size());
}
@@ -174,21 +158,16 @@ public class TestDataSource {
// Can go to the end, but not past it
bs = ds.read(8, 8190);
- assertEquals(0, bs.position()); // TODO How best to warn of a short read?
+ // TODO How best to warn of a short read?
+ assertEquals(0, bs.position());
// Can't go off the end
- try {
- ds.read(4, 8192);
- if (!writeable) {
- fail("Shouldn't be able to read off the end of the file");
- }
- } catch (IndexOutOfBoundsException e) {
- // expected here
- }
+ assertThrows(IndexOutOfBoundsException.class, () -> ds.read(4, ds.size()),
+ "Shouldn't be able to read off the end of the file");
}
@Test
- public void testByteArray() throws Exception {
+ public void testByteArray() {
byte[] data = new byte[256];
byte b;
for (int i = 0; i < data.length; i++) {
@@ -226,20 +205,10 @@ public class TestDataSource {
bs = ds.read(4, 254);
assertEquals(-2, bs.get());
assertEquals(-1, bs.get());
- try {
- bs.get();
- fail("Shouldn't be able to read off the end");
- } catch (BufferUnderflowException e) {
- // expected here
- }
+ assertThrows(BufferUnderflowException.class, bs::get, "Shouldn't be able to read off the end");
// Past the end
- try {
- ds.read(4, 256);
- fail("Shouldn't be able to read off the end");
- } catch (IndexOutOfBoundsException e) {
- // expected here
- }
+ assertThrows(IndexOutOfBoundsException.class, () -> ds.read(4, 256), "Shouldn't be able to read off the end");
// Overwrite
diff --git a/src/testcases/org/apache/poi/poifs/property/AllPOIFSPropertyTests.java b/src/testcases/org/apache/poi/poifs/property/AllPOIFSPropertyTests.java
deleted file mode 100644
index 8df7314ee4..0000000000
--- a/src/testcases/org/apache/poi/poifs/property/AllPOIFSPropertyTests.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.poifs.property;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Tests for org.apache.poi.poifs.property<br>
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestDirectoryProperty.class,
- TestDocumentProperty.class,
- TestPropertyFactory.class,
- TestPropertyTable.class,
- TestRootProperty.class
-})
-public final class AllPOIFSPropertyTests {
-}
diff --git a/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java b/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java
index 0a11d83a57..f43d32d136 100644
--- a/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java
+++ b/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java
@@ -17,10 +17,10 @@
package org.apache.poi.poifs.property;
-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.ByteArrayOutputStream;
import java.io.IOException;
@@ -31,7 +31,7 @@ import java.util.List;
import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test DirectoryProperty functionality
@@ -154,7 +154,7 @@ public final class TestDirectoryProperty {
}
private void createBasicDirectoryProperty() {
- String name = "MyDirectory";
+ final String name = "MyDirectory";
_property = new DirectoryProperty(name);
_testblock = new byte[ 128 ];
@@ -164,7 +164,7 @@ public final class TestDirectoryProperty {
{
_testblock[ index ] = ( byte ) 0;
}
- int limit = Math.min(31, name.length());
+ int limit = name.length();
_testblock[ index++ ] = ( byte ) (2 * (limit + 1));
_testblock[ index++ ] = ( byte ) 0;
@@ -195,8 +195,7 @@ public final class TestDirectoryProperty {
assertEquals(_testblock.length, output.length);
for (int j = 0; j < _testblock.length; j++)
{
- assertEquals("mismatch at offset " + j, _testblock[ j ],
- output[ j ]);
+ assertEquals(_testblock[ j ], output[ j ], "mismatch at offset " + j);
}
}
@@ -205,26 +204,8 @@ public final class TestDirectoryProperty {
createBasicDirectoryProperty();
_property.addChild(new LocalProperty(1));
_property.addChild(new LocalProperty(2));
- try
- {
- _property.addChild(new LocalProperty(1));
- fail("should have caught IOException");
- }
- catch (IOException ignored)
- {
-
- // as expected
- }
- try
- {
- _property.addChild(new LocalProperty(2));
- fail("should have caught IOException");
- }
- catch (IOException ignored)
- {
-
- // as expected
- }
+ assertThrows(IOException.class, () -> _property.addChild(new LocalProperty(1)));
+ assertThrows(IOException.class, () -> _property.addChild(new LocalProperty(2)));
_property.addChild(new LocalProperty(3));
}
@@ -234,16 +215,7 @@ public final class TestDirectoryProperty {
Property p1 = new LocalProperty(1);
_property.addChild(p1);
- try
- {
- _property.addChild(new LocalProperty(1));
- fail("should have caught IOException");
- }
- catch (IOException ignored)
- {
-
- // as expected
- }
+ assertThrows(IOException.class, () -> _property.addChild(new LocalProperty(1)));
assertTrue(_property.deleteChild(p1));
assertFalse(_property.deleteChild(p1));
_property.addChild(new LocalProperty(1));
@@ -292,7 +264,7 @@ public final class TestDirectoryProperty {
assertEquals(128, output.length);
for (int j = 0; j < 128; j++) {
- assertEquals("mismatch at offset " + j, expected[j], output[j]);
+ assertEquals(expected[j], output[j], "mismatch at offset " + j);
}
assertEquals(index, property.getIndex());
assertEquals(name, property.getName());
diff --git a/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java b/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java
index 2ad3a7714a..ed10478d7b 100644
--- a/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java
+++ b/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java
@@ -17,9 +17,9 @@
package org.apache.poi.poifs.property;
-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.ByteArrayOutputStream;
import java.io.IOException;
@@ -29,7 +29,7 @@ import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test DocumentProperty functionality
@@ -88,10 +88,8 @@ public final class TestDocumentProperty {
byte[] output = stream.toByteArray();
assertEquals(128, output.length);
- for (int j = 0; j < 128; j++)
- {
- assertEquals("mismatch at offset " + j, expected[ j ],
- output[ j ]);
+ for (int j = 0; j < 128; j++) {
+ assertEquals(expected[ j ], output[ j ], "mismatch at offset " + j);
}
assertEquals(index, property.getIndex());
assertEquals(name, property.getName());
@@ -156,8 +154,7 @@ public final class TestDocumentProperty {
assertEquals(testblock.length, output.length);
for (int j = 0; j < testblock.length; j++)
{
- assertEquals("mismatch at offset " + j, testblock[ j ],
- output[ j ]);
+ assertEquals(testblock[ j ], output[ j ], "mismatch at offset " + j);
}
}
}
diff --git a/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java b/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java
index 27387ddf40..4c9f72817a 100644
--- a/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java
+++ b/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java
@@ -17,10 +17,10 @@
package org.apache.poi.poifs.property;
-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.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;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -29,7 +29,7 @@ import java.util.Arrays;
import java.util.List;
import org.apache.poi.poifs.storage.RawDataUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test PropertyFactory functionality
@@ -145,21 +145,19 @@ public final class TestPropertyFactory {
for (int j = 0; j < 64; j++) {
if (isNull[j]) {
- assertNull("Checking property " + j, properties.get(j));
+ assertNull(properties.get(j), "Checking property " + j);
} else {
- assertNotNull("Checking property " + j, properties.get(j));
+ assertNotNull(properties.get(j), "Checking property " + j);
if (isRoot[j]) {
- assertTrue("Checking property " + j, properties.get(j) instanceof RootProperty);
+ assertTrue(properties.get(j) instanceof RootProperty, "Checking property " + j);
}
if (isDirectory[j]) {
- assertTrue("Checking property " + j,
- properties.get(j) instanceof DirectoryProperty);
+ assertTrue(properties.get(j) instanceof DirectoryProperty, "Checking property " + j);
}
if (isDocument[j]) {
- assertTrue("Checking property " + j,
- properties.get(j) instanceof DocumentProperty);
+ assertTrue(properties.get(j) instanceof DocumentProperty, "Checking property " + j);
}
- assertEquals("Checking property " + j, names[j], properties.get(j).getName());
+ assertEquals(names[j], properties.get(j).getName(), "Checking property " + j);
}
}
}
diff --git a/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java b/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java
index dd9c507f0d..f8dc48df45 100644
--- a/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java
+++ b/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java
@@ -17,10 +17,10 @@
package org.apache.poi.poifs.property;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -37,7 +37,7 @@ import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.filesystem.POIFSStream;
import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.poifs.storage.RawDataUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test PropertyTable functionality
@@ -180,7 +180,7 @@ public final class TestPropertyTable {
}
}
-
+
// get property table from the document
PropertyTable table = new PropertyTable(header_block, data_blocks);
@@ -192,8 +192,8 @@ public final class TestPropertyTable {
lastChild = p;
++count;
}
-
- assertNotNull("no children found", lastChild);
+
+ assertNotNull(lastChild, "no children found");
assertEquals(1, count);
assertTrue(lastChild.isDirectory());
count = 0;
diff --git a/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java b/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java
index 9bbb612f3d..a2e992ed11 100644
--- a/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java
+++ b/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java
@@ -17,8 +17,8 @@
package org.apache.poi.poifs.property;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -27,7 +27,7 @@ import java.util.Arrays;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.util.LocaleUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test RootProperty functionality
@@ -53,7 +53,7 @@ public final class TestRootProperty {
_testblock[index] = (byte) 0;
}
String name = "Root Entry";
- int limit = Math.min(31, name.length());
+ int limit = name.length();
_testblock[index++] = (byte) (2 * (limit + 1));
_testblock[index++] = (byte) 0;
@@ -87,7 +87,7 @@ public final class TestRootProperty {
assertEquals(_testblock.length, output.length);
for (int j = 0; j < _testblock.length; j++) {
- assertEquals("mismatch at offset " + j, _testblock[j], output[j]);
+ assertEquals(_testblock[j], output[j], "mismatch at offset " + j);
}
}
@@ -96,7 +96,7 @@ public final class TestRootProperty {
for (int j = 0; j < 10; j++) {
createBasicRootProperty();
_property.setSize(j);
- assertEquals("trying block count of " + j, j * 64, _property.getSize());
+ assertEquals(j * 64, _property.getSize(), "trying block count of " + j);
}
}
@@ -126,7 +126,7 @@ public final class TestRootProperty {
assertEquals(128, output.length);
for (int j = 0; j < 128; j++) {
- assertEquals("mismatch at offset " + j, expected[j], output[j]);
+ assertEquals(expected[j], output[j], "mismatch at offset " + j);
}
assertEquals(index, property.getIndex());
assertEquals(name, property.getName());
diff --git a/src/testcases/org/apache/poi/poifs/storage/AllPOIFSStorageTests.java b/src/testcases/org/apache/poi/poifs/storage/AllPOIFSStorageTests.java
deleted file mode 100644
index 7b29d1b09e..0000000000
--- a/src/testcases/org/apache/poi/poifs/storage/AllPOIFSStorageTests.java
+++ /dev/null
@@ -1,31 +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.poifs.storage;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-/**
- * Tests for org.apache.poi.poifs.storage
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestBATBlock.class,
- TestHeaderBlockReading.class
-})
-public class AllPOIFSStorageTests {
-}
diff --git a/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java b/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java
index 10689b2e21..dac1ae1108 100644
--- a/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java
+++ b/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java
@@ -17,9 +17,9 @@
package org.apache.poi.poifs.storage;
-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.nio.ByteBuffer;
import java.util.ArrayList;
@@ -27,7 +27,7 @@ import java.util.List;
import org.apache.poi.poifs.common.POIFSBigBlockSize;
import org.apache.poi.poifs.common.POIFSConstants;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test BATBlock functionality
diff --git a/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java b/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java
index 3234676d17..40cb3bec52 100644
--- a/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java
+++ b/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java
@@ -17,14 +17,14 @@
package org.apache.poi.poifs.storage;
-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.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Arrays;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test HeaderBlockReader functionality
@@ -58,24 +58,13 @@ public final class TestHeaderBlockReading {
// verify we can't read a short block
byte[] shortblock = Arrays.copyOf(content, 511);
- try {
- new HeaderBlock(new ByteArrayInputStream(shortblock));
- fail("Should have caught IOException reading a short block");
- } catch (IOException ignored) {
-
- // as expected
- }
+ assertThrows(IOException.class, () -> new HeaderBlock(new ByteArrayInputStream(shortblock)));
// try various forms of corruption
for (int index = 0; index < 8; index++) {
content[index] = (byte) (content[index] - 1);
- try {
- new HeaderBlock(new ByteArrayInputStream(content));
- fail("Should have caught IOException corrupting byte " + index);
- } catch (IOException ignored) {
-
- // as expected
- }
+ assertThrows(IOException.class, () -> new HeaderBlock(new ByteArrayInputStream(content)),
+ "Should have caught IOException corrupting byte " + index);
// restore byte value
content[index] = (byte) (content[index] + 1);
diff --git a/src/testcases/org/apache/poi/sl/draw/geom/TestFormulaParser.java b/src/testcases/org/apache/poi/sl/draw/geom/TestFormulaParser.java
index 0d82c2ad3e..1fd8125749 100644
--- a/src/testcases/org/apache/poi/sl/draw/geom/TestFormulaParser.java
+++ b/src/testcases/org/apache/poi/sl/draw/geom/TestFormulaParser.java
@@ -18,9 +18,9 @@
*/
package org.apache.poi.sl.draw.geom;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Date: 10/24/11
diff --git a/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java b/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java
index fe57570c5d..f7f623bb67 100644
--- a/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java
+++ b/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java
@@ -18,17 +18,17 @@
*/
package org.apache.poi.sl.draw.geom;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
+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 java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.net.URL;
import java.util.Enumeration;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
public class TestPresetGeometries {
@Test
@@ -50,7 +50,7 @@ public class TestPresetGeometries {
assertSame(shapes, PresetGeometries.getInstance());
}
- @Ignore("problem solved? Turn back on if this debugging is still in process.")
+ @Disabled("problem solved? Turn back on if this debugging is still in process.")
@Test
public void testCheckXMLParser() throws Exception{
// Gump reports a strange error because of an unavailable XML Parser, let's try to find out where
diff --git a/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java b/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java
index 6158c9de63..500f4c922f 100644
--- a/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java
+++ b/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java
@@ -16,11 +16,11 @@
==================================================================== */
package org.apache.poi.sl.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.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 java.awt.Color;
import java.awt.geom.Rectangle2D;
@@ -34,7 +34,7 @@ import org.apache.poi.common.usermodel.fonts.FontInfo;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.TabStop.TabStopType;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public abstract class BaseTestSlideShow<
S extends Shape<S,P>,
@@ -44,7 +44,7 @@ public abstract class BaseTestSlideShow<
public abstract SlideShow<S,P> createSlideShow();
- public abstract SlideShow<S,P> reopen(SlideShow<S,P> show);
+ public abstract SlideShow<S,P> reopen(SlideShow<S,P> show) throws IOException;
@Test
public void addPicture_File() throws IOException {
diff --git a/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java b/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
index 345bb7906e..090aeb0aa8 100644
--- a/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
+++ b/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
@@ -17,9 +17,9 @@
package org.apache.poi.sl.usermodel;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -54,23 +54,21 @@ public abstract class BaseTestSlideShowFactory {
@SuppressWarnings("resource")
protected static void testFactoryFromNative(String file) throws Exception {
+ assertNotNull(file);
+ assertTrue(file.endsWith(".ppt") || file.endsWith(".pptx"), "Unexpected file extension: " + file);
+
SlideShow<?,?> ss;
- // from POIFS
if (file.endsWith(".ppt")) {
- POIFSFileSystem poifs = new POIFSFileSystem(fromFile(file));
- ss = SlideShowFactory.create(poifs);
- assertNotNull(ss);
- poifs.close();
+ // from POIFS
+ try (POIFSFileSystem poifs = new POIFSFileSystem(fromFile(file))) {
+ ss = SlideShowFactory.create(poifs);
+ assertNotNull(ss);
+ }
assertCloseDoesNotModifyFile(file, ss);
- }
- // from OPCPackage
- else if (file.endsWith(".pptx")) {
- // not implemented
+ } else {
+ // from OPCPackage ... not implemented
throw new UnsupportedOperationException("Test not implemented");
}
- else {
- fail("Unexpected file extension: " + file);
- }
}
@SuppressWarnings("resource")
@@ -91,21 +89,19 @@ public abstract class BaseTestSlideShowFactory {
@SuppressWarnings("resource")
protected static void testFactoryFromProtectedNative(String protectedFile, String password) throws Exception {
+ assertTrue(protectedFile.endsWith(".ppt") || protectedFile.endsWith(".pptx"),
+ "Unrecognized file extension: " + protectedFile);
+
SlideShow<?,?> ss;
// Encryption layer is a BIFF8 binary format that can be read by POIFSFileSystem,
// used for both HSLF and XSLF
// from protected POIFS
- if (protectedFile.endsWith(".ppt") || protectedFile.endsWith(".pptx")) {
- POIFSFileSystem poifs = new POIFSFileSystem(fromFile(protectedFile));
+ try (POIFSFileSystem poifs = new POIFSFileSystem(fromFile(protectedFile))) {
ss = SlideShowFactory.create(poifs.getRoot(), password);
assertNotNull(ss);
- poifs.close();
- assertCloseDoesNotModifyFile(protectedFile, ss);
- }
- else {
- fail("Unrecognized file extension: " + protectedFile);
}
+ assertCloseDoesNotModifyFile(protectedFile, ss);
}
@SuppressWarnings("SameParameterValue")
@@ -169,8 +165,7 @@ public abstract class BaseTestSlideShowFactory {
final byte[] after = readFile(filename);
try {
- assertArrayEquals(filename + " sample file was modified as a result of closing the slideshow",
- before, after);
+ assertArrayEquals(before, after, filename + " sample file was modified as a result of closing the slideshow");
} catch (AssertionError e) {
// if the file after closing is different, then re-set
// the file to the state before in order to not have a dirty SCM
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 {
diff --git a/src/testcases/org/apache/poi/util/AllPOIUtilTests.java b/src/testcases/org/apache/poi/util/AllPOIUtilTests.java
deleted file mode 100644
index 58155e6dca..0000000000
--- a/src/testcases/org/apache/poi/util/AllPOIUtilTests.java
+++ /dev/null
@@ -1,43 +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.util;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test suite for all sub-packages of org.apache.poi.util<br>
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestArrayUtil.class
- , TestBitField.class
- , TestByteField.class
- , TestHexDump.class
- , TestIntegerField.class
- , TestIntList.class
- , TestLittleEndian.class
- , TestLongField.class
- , TestPOILogFactory.class
- , TestPOILogger.class
- , TestShortField.class
- , TestStringUtil.class
- , TestTempFile.class
-})
-public final class AllPOIUtilTests {
-}
diff --git a/src/testcases/org/apache/poi/util/MemoryLeakVerifier.java b/src/testcases/org/apache/poi/util/MemoryLeakVerifier.java
index c69baa7900..138f2baccd 100644
--- a/src/testcases/org/apache/poi/util/MemoryLeakVerifier.java
+++ b/src/testcases/org/apache/poi/util/MemoryLeakVerifier.java
@@ -17,12 +17,12 @@
package org.apache.poi.util;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
-import static org.junit.Assert.assertNull;
-
/**
* A simple utility class that can verify that objects have been successfully garbage collected.
*
@@ -100,7 +100,6 @@ public class MemoryLeakVerifier {
Thread.sleep(GC_SLEEP_TIME);
}
- assertNull("Object should not exist after " + MAX_GC_ITERATIONS + " collections, but still had: " + ref.get(),
- ref.get());
+ assertNull(ref.get(), "Object should not exist after " + MAX_GC_ITERATIONS + " collections, but still had: " + ref.get());
}
}
diff --git a/src/testcases/org/apache/poi/util/TestArrayUtil.java b/src/testcases/org/apache/poi/util/TestArrayUtil.java
index 2718f7094d..001d5c0595 100644
--- a/src/testcases/org/apache/poi/util/TestArrayUtil.java
+++ b/src/testcases/org/apache/poi/util/TestArrayUtil.java
@@ -18,12 +18,12 @@
package org.apache.poi.util;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Arrays;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit test for ArrayUtil
@@ -83,19 +83,11 @@ public class TestArrayUtil {
}
// Check can't shift more than we have
- try {
- ArrayUtil.arrayMoveWithin(getIntsList(), 7, 3, 5);
- fail();
- } catch(IllegalArgumentException e) {
- // Good, we don't have 5 from 7 onwards
- }
+ assertThrows(IllegalArgumentException.class, () -> ArrayUtil.arrayMoveWithin(getIntsList(), 7, 3, 5));
+ // Good, we don't have 5 from 7 onwards
// Check can't shift where would overshoot
- try {
- ArrayUtil.arrayMoveWithin(getIntsList(), 2, 7, 5);
- fail();
- } catch(IllegalArgumentException e) {
- // Good, we can't fit 5 in starting at 7
- }
+ assertThrows(IllegalArgumentException.class, () -> ArrayUtil.arrayMoveWithin(getIntsList(), 2, 7, 5));
+ // Good, we can't fit 5 in starting at 7
}
}
diff --git a/src/testcases/org/apache/poi/util/TestBitField.java b/src/testcases/org/apache/poi/util/TestBitField.java
index c8c57ecaa2..d075c98fb0 100644
--- a/src/testcases/org/apache/poi/util/TestBitField.java
+++ b/src/testcases/org/apache/poi/util/TestBitField.java
@@ -17,11 +17,11 @@
package org.apache.poi.util;
-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.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test BitField functionality
diff --git a/src/testcases/org/apache/poi/util/TestByteField.java b/src/testcases/org/apache/poi/util/TestByteField.java
index 3c6bea78bf..53e9b95738 100644
--- a/src/testcases/org/apache/poi/util/TestByteField.java
+++ b/src/testcases/org/apache/poi/util/TestByteField.java
@@ -18,13 +18,13 @@
package org.apache.poi.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.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit test for ByteField class
@@ -86,11 +86,11 @@ public final class TestByteField {
for (int j = 0; j < _test_array.length; j++) {
field.set(_test_array[ j ]);
- assertEquals("testing _1 " + j, _test_array[ j ], field.get());
+ assertEquals(_test_array[ j ], field.get(), "testing _1 " + j);
field = new ByteField(0);
field.set(_test_array[ j ], array);
- assertEquals("testing _2 ", _test_array[ j ], field.get());
- assertEquals("testing _3 ", _test_array[ j ], array[ 0 ]);
+ assertEquals(_test_array[ j ], field.get(), "testing _2 ");
+ assertEquals(_test_array[ j ], array[ 0 ], "testing _3 ");
}
}
@@ -109,7 +109,7 @@ public final class TestByteField {
for (int j = 0; j < _test_array.length; j++) {
array[ 0 ] = _test_array[ j ];
field.readFromBytes(array);
- assertEquals("testing " + j, _test_array[ j ], field.get());
+ assertEquals(_test_array[ j ], field.get(), "testing " + j);
}
}
@@ -120,7 +120,7 @@ public final class TestByteField {
for (int j = 0; j < _test_array.length; j++) {
field.readFromStream(stream);
- assertEquals("Testing " + j, _test_array[ j ], field.get());
+ assertEquals(_test_array[ j ], field.get(), "Testing " + j);
}
}
@@ -132,7 +132,7 @@ public final class TestByteField {
for (byte b : _test_array) {
field.set(b);
field.writeToBytes(array);
- assertEquals("testing ", b, array[ 0 ]);
+ assertEquals(b, array[ 0 ], "testing ");
}
}
}
diff --git a/src/testcases/org/apache/poi/util/TestHexDump.java b/src/testcases/org/apache/poi/util/TestHexDump.java
index cf575c770b..d6a7d5d0e4 100644
--- a/src/testcases/org/apache/poi/util/TestHexDump.java
+++ b/src/testcases/org/apache/poi/util/TestHexDump.java
@@ -17,10 +17,10 @@
package org.apache.poi.util;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -28,21 +28,21 @@ import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
-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 TestHexDump {
private static PrintStream SYSTEM_OUT;
- @BeforeClass
+ @BeforeAll
public static void setUp() throws UnsupportedEncodingException {
SYSTEM_OUT = System.out;
System.setOut(new PrintStream(new OutputStream() {public void write(int b) {}}, false, "UTF-8"));
}
- @AfterClass
+ @AfterAll
public static void tearDown() {
System.setOut(SYSTEM_OUT);
}
@@ -55,8 +55,8 @@ public class TestHexDump {
byte[] bytesAct = streamAct.toByteArray();
byte[] bytesExp = toHexDump(0, 0);
- assertEquals("array size mismatch", bytesExp.length, bytesAct.length);
- assertArrayEquals("array mismatch", bytesExp, bytesAct);
+ assertEquals(bytesExp.length, bytesAct.length, "array size mismatch");
+ assertArrayEquals(bytesExp, bytesAct, "array mismatch");
// verify proper behavior with non-zero offset
streamAct.reset();
@@ -64,8 +64,8 @@ public class TestHexDump {
bytesAct = streamAct.toByteArray();
bytesExp = toHexDump(0x10000000L,0);
- assertEquals("array size mismatch", bytesExp.length, bytesAct.length);
- assertArrayEquals("array mismatch", bytesExp, bytesAct);
+ assertEquals(bytesExp.length, bytesAct.length, "array size mismatch");
+ assertArrayEquals(bytesExp, bytesAct, "array mismatch");
// verify proper behavior with negative offset
streamAct.reset();
@@ -73,8 +73,8 @@ public class TestHexDump {
bytesAct = streamAct.toByteArray();
bytesExp = toHexDump(0xFF000000L,0);
- assertEquals("array size mismatch", bytesExp.length, bytesAct.length);
- assertArrayEquals("array mismatch", bytesExp, bytesAct);
+ assertEquals(bytesExp.length, bytesAct.length, "array size mismatch");
+ assertArrayEquals(bytesExp, bytesAct, "array mismatch");
// verify proper behavior with non-zero index
streamAct.reset();
@@ -82,36 +82,20 @@ public class TestHexDump {
bytesAct = streamAct.toByteArray();
bytesExp = toHexDump(0xFF000000L,0x81);
- assertEquals("array size mismatch", bytesExp.length, bytesAct.length);
- assertArrayEquals("array mismatch", bytesExp, bytesAct);
+ assertEquals(bytesExp.length, bytesAct.length, "array size mismatch");
+ assertArrayEquals(bytesExp, bytesAct, "array mismatch");
// verify proper behavior with negative index
- try {
- streamAct.reset();
- HexDump.dump(testArray, 0x10000000L, streamAct, -1);
- fail("should have caught ArrayIndexOutOfBoundsException on negative index");
- } catch (ArrayIndexOutOfBoundsException ignored_exception) {
- // as expected
- }
+ streamAct.reset();
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> HexDump.dump(testArray, 0x10000000L, streamAct, -1));
// verify proper behavior with index that is too large
- try {
- streamAct.reset();
- HexDump.dump(testArray, 0x10000000L, streamAct, testArray.length);
- fail("should have caught ArrayIndexOutOfBoundsException on large index");
- } catch (ArrayIndexOutOfBoundsException ignored_exception) {
- // as expected
- }
+ streamAct.reset();
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> HexDump.dump(testArray, 0x10000000L, streamAct, testArray.length));
// verify proper behavior with null stream
- try {
- HexDump.dump(testArray, 0x10000000L, null, 0);
- fail("should have caught IllegalArgumentException on negative index");
- } catch (IllegalArgumentException ignored_exception) {
-
- // as expected
- }
+ assertThrows(IllegalArgumentException.class, () -> HexDump.dump(testArray, 0x10000000L, null, 0));
// verify proper behaviour with empty byte array
streamAct.reset();
@@ -178,28 +162,18 @@ public class TestHexDump {
byte[] testArray = testArray();
String dump = HexDump.dump(testArray, 0, 0);
//System.out.println("Hex: \n" + dump);
- assertTrue("Had: \n" + dump,
- dump.contains("0123456789:;<=>?"));
+ assertTrue(dump.contains("0123456789:;<=>?"), "Had: \n" + dump);
dump = HexDump.dump(testArray, 2, 1);
//System.out.println("Hex: \n" + dump);
- assertTrue("Had: \n" + dump,
- dump.contains("123456789:;<=>?@"));
+ assertTrue(dump.contains("123456789:;<=>?@"), "Had: \n" + dump);
}
- @Test(expected=ArrayIndexOutOfBoundsException.class)
+ @Test
public void testDumpToStringOutOfIndex1() {
- HexDump.dump(new byte[1], 0, -1);
- }
-
- @Test(expected=ArrayIndexOutOfBoundsException.class)
- public void testDumpToStringOutOfIndex2() {
- HexDump.dump(new byte[1], 0, 2);
- }
-
- @Test(expected=ArrayIndexOutOfBoundsException.class)
- public void testDumpToStringOutOfIndex3() {
- HexDump.dump(new byte[1], 0, 1);
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> HexDump.dump(new byte[1], 0, -1));
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> HexDump.dump(new byte[1], 0, 2));
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> HexDump.dump(new byte[1], 0, 1));
}
@Test
diff --git a/src/testcases/org/apache/poi/util/TestIOUtils.java b/src/testcases/org/apache/poi/util/TestIOUtils.java
index fbef102f17..6a7710484c 100644
--- a/src/testcases/org/apache/poi/util/TestIOUtils.java
+++ b/src/testcases/org/apache/poi/util/TestIOUtils.java
@@ -17,12 +17,12 @@
package org.apache.poi.util;
-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.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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -38,19 +38,19 @@ import java.nio.charset.StandardCharsets;
import java.util.Random;
import org.apache.poi.EmptyFileException;
-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;
/**
* Class to test IOUtils
*/
public final class TestIOUtils {
- static File TMP;
- static final long LENGTH = 300+new Random().nextInt(9000);
+ private static File TMP;
+ private static final long LENGTH = 300+new Random().nextInt(9000);
- @BeforeClass
+ @BeforeAll
public static void setUp() throws IOException {
TMP = File.createTempFile("poi-ioutils-", "");
OutputStream os = new FileOutputStream(TMP);
@@ -62,11 +62,15 @@ public final class TestIOUtils {
}
- @AfterClass
+ @AfterAll
public static void tearDown() {
if (TMP != null) assertTrue(TMP.delete());
}
+ private static InputStream data123() {
+ return new ByteArrayInputStream(new byte[]{1,2,3});
+ }
+
@Test
public void testPeekFirst8Bytes() throws Exception {
assertArrayEquals("01234567".getBytes(StandardCharsets.UTF_8),
@@ -81,43 +85,38 @@ public final class TestIOUtils {
@Test
public void testPeekFirst8BytesTooLessAvailable() throws Exception {
- assertArrayEquals(new byte[] { 1, 2, 3, 0, 0, 0, 0, 0},
- IOUtils.peekFirst8Bytes(new ByteArrayInputStream(new byte[] { 1, 2, 3})));
+ assertArrayEquals(new byte[] { 1, 2, 3, 0, 0, 0, 0, 0}, IOUtils.peekFirst8Bytes(data123()));
}
- @Test(expected = EmptyFileException.class)
- public void testPeekFirst8BytesEmpty() throws Exception {
- IOUtils.peekFirst8Bytes(new ByteArrayInputStream(new byte[] {}));
+ @Test
+ public void testPeekFirst8BytesEmpty() {
+ assertThrows(EmptyFileException.class, () ->
+ IOUtils.peekFirst8Bytes(new ByteArrayInputStream(new byte[0])));
}
@Test
public void testToByteArray() throws Exception {
- assertArrayEquals(new byte[] { 1, 2, 3},
- IOUtils.toByteArray(new ByteArrayInputStream(new byte[] { 1, 2, 3})));
+ assertArrayEquals(new byte[] { 1, 2, 3}, IOUtils.toByteArray(data123()));
}
- @Test(expected = IOException.class)
- public void testToByteArrayToSmall() throws Exception {
- assertArrayEquals(new byte[] { 1, 2, 3},
- IOUtils.toByteArray(new ByteArrayInputStream(new byte[] { 1, 2, 3}), 10));
+ @Test
+ public void testToByteArrayToSmall() {
+ assertThrows(IOException.class, () -> IOUtils.toByteArray(data123(), 10));
}
- @Test(expected = IOException.class)
- public void testToByteArrayMaxLengthToSmall() throws Exception {
- assertArrayEquals(new byte[] { 1, 2, 3},
- IOUtils.toByteArray(new ByteArrayInputStream(new byte[] { 1, 2, 3}), 10, 10));
+ @Test
+ public void testToByteArrayMaxLengthToSmall() {
+ assertThrows(IOException.class, () -> IOUtils.toByteArray(data123(), 10, 10));
}
- @Test(expected = RecordFormatException.class)
- public void testToByteArrayNegativeLength() throws Exception {
- assertArrayEquals(new byte[] { 1, 2, 3},
- IOUtils.toByteArray(new ByteArrayInputStream(new byte[] { 1, 2, 3}), -1));
+ @Test
+ public void testToByteArrayNegativeLength() {
+ assertThrows(RecordFormatException.class, () -> IOUtils.toByteArray(data123(), -1));
}
- @Test(expected = RecordFormatException.class)
- public void testToByteArrayNegativeMaxLength() throws Exception {
- assertArrayEquals(new byte[] { 1, 2, 3},
- IOUtils.toByteArray(new ByteArrayInputStream(new byte[] { 1, 2, 3}), 10, -1));
+ @Test
+ public void testToByteArrayNegativeMaxLength() {
+ assertThrows(RecordFormatException.class, () -> IOUtils.toByteArray(data123(), 10, -1));
}
@Test
@@ -148,7 +147,7 @@ public final class TestIOUtils {
public void testSkipFully() throws IOException {
try (InputStream is = new FileInputStream(TMP)) {
long skipped = IOUtils.skipFully(is, 20000L);
- assertEquals("length: " + LENGTH, LENGTH, skipped);
+ assertEquals(LENGTH, skipped);
}
}
@@ -156,7 +155,7 @@ public final class TestIOUtils {
public void testSkipFullyGtIntMax() throws IOException {
try (InputStream is = new FileInputStream(TMP)) {
long skipped = IOUtils.skipFully(is, Integer.MAX_VALUE + 20000L);
- assertEquals("length: " + LENGTH, LENGTH, skipped);
+ assertEquals(LENGTH, skipped);
}
}
@@ -166,7 +165,7 @@ public final class TestIOUtils {
try (InputStream is = new FileInputStream(TMP)) {
IOUtils.copy(is, bos);
long skipped = IOUtils.skipFully(new ByteArrayInputStream(bos.toByteArray()), 20000L);
- assertEquals("length: " + LENGTH, LENGTH, skipped);
+ assertEquals(LENGTH, skipped);
}
}
@@ -176,7 +175,7 @@ public final class TestIOUtils {
try (InputStream is = new FileInputStream(TMP)) {
IOUtils.copy(is, bos);
long skipped = IOUtils.skipFully(new ByteArrayInputStream(bos.toByteArray()), Integer.MAX_VALUE + 20000L);
- assertEquals("length: " + LENGTH, LENGTH, skipped);
+ assertEquals(LENGTH, skipped);
}
}
@@ -188,28 +187,28 @@ public final class TestIOUtils {
@Test
public void testZeroByte() throws IOException {
long skipped = IOUtils.skipFully((new ByteArrayInputStream(new byte[0])), 100);
- assertEquals("zero byte", -1L, skipped);
+ assertEquals(-1L, skipped);
}
@Test
public void testSkipZero() throws IOException {
try (InputStream is = new FileInputStream(TMP)) {
long skipped = IOUtils.skipFully(is, 0);
- assertEquals("zero length", 0, skipped);
+ assertEquals(0, skipped);
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSkipNegative() throws IOException {
try (InputStream is = new FileInputStream(TMP)) {
- IOUtils.skipFully(is, -1);
+ assertThrows(IllegalArgumentException.class, () -> IOUtils.skipFully(is, -1));
}
}
- @Test(expected = RecordFormatException.class)
+ @Test
public void testMaxLengthTooLong() throws IOException {
try (InputStream is = new FileInputStream(TMP)) {
- IOUtils.toByteArray(is, Integer.MAX_VALUE, 100);
+ assertThrows(RecordFormatException.class, () -> IOUtils.toByteArray(is, Integer.MAX_VALUE, 100));
}
}
@@ -222,17 +221,17 @@ public final class TestIOUtils {
}
}
- @Test(expected = RecordFormatException.class)
+ @Test
public void testMaxLengthInvalid() throws IOException {
try (InputStream is = new FileInputStream(TMP)) {
- IOUtils.toByteArray(is, 90, 80);
+ assertThrows(RecordFormatException.class, () -> IOUtils.toByteArray(is, 90, 80));
}
}
@Test
public void testWonkyInputStream() throws IOException {
long skipped = IOUtils.skipFully(new WonkyInputStream(), 10000);
- assertEquals("length: "+LENGTH, 10000, skipped);
+ assertEquals(10000, skipped);
}
@Test
@@ -257,16 +256,11 @@ public final class TestIOUtils {
}
@Test
- public void testSetMaxOverrideOverLimit() throws IOException {
+ public void testSetMaxOverrideOverLimit() {
IOUtils.setByteArrayMaxOverride(2);
try {
ByteArrayInputStream stream = new ByteArrayInputStream("abc".getBytes(StandardCharsets.UTF_8));
- try {
- IOUtils.toByteArray(stream);
- fail("Should have caught an Exception here");
- } catch (RecordFormatException e) {
- // expected
- }
+ assertThrows(RecordFormatException.class, () -> IOUtils.toByteArray(stream));
} finally {
IOUtils.setByteArrayMaxOverride(-1);
}
@@ -298,12 +292,7 @@ public final class TestIOUtils {
IOUtils.setByteArrayMaxOverride(2);
try {
ByteArrayInputStream stream = new ByteArrayInputStream("abc".getBytes(StandardCharsets.UTF_8));
- try {
- IOUtils.toByteArray(stream, 3, 100);
- fail("Should have caught an Exception here");
- } catch (RecordFormatException e) {
- // expected
- }
+ assertThrows(RecordFormatException.class, () -> IOUtils.toByteArray(stream, 3, 100));
} finally {
IOUtils.setByteArrayMaxOverride(-1);
}
diff --git a/src/testcases/org/apache/poi/util/TestIntList.java b/src/testcases/org/apache/poi/util/TestIntList.java
index 25d427d361..1efadc0c91 100644
--- a/src/testcases/org/apache/poi/util/TestIntList.java
+++ b/src/testcases/org/apache/poi/util/TestIntList.java
@@ -17,15 +17,15 @@
package org.apache.poi.util;
-import org.junit.Test;
+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.assertNotSame;
+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.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import org.junit.jupiter.api.Test;
/**
* Class to test IntList
@@ -50,18 +50,17 @@ public final class TestIntList {
@Test
public void testAdd() {
- IntList list = new IntList();
- int[] testArray =
- {
- 0, 1, 2, 3, 5
- };
+ IntList list = new IntList();
+ int[] testArray =
+ {
+ 0, 1, 2, 3, 5
+ };
for (int element : testArray) {
list.add(element);
}
- for (int j = 0; j < testArray.length; j++)
- {
- assertEquals(testArray[ j ], list.get(j));
+ for (int j = 0; j < testArray.length; j++) {
+ assertEquals(testArray[j], list.get(j));
}
assertEquals(testArray.length, list.size());
@@ -69,59 +68,44 @@ public final class TestIntList {
list.add(0, -1);
assertEquals(-1, list.get(0));
assertEquals(testArray.length + 1, list.size());
- for (int j = 0; j < testArray.length; j++)
- {
- assertEquals(testArray[ j ], list.get(j + 1));
+ for (int j = 0; j < testArray.length; j++) {
+ assertEquals(testArray[j], list.get(j + 1));
}
// add in the middle
list.add(5, 4);
assertEquals(4, list.get(5));
assertEquals(testArray.length + 2, list.size());
- for (int j = 0; j < list.size(); j++)
- {
+ for (int j = 0; j < list.size(); j++) {
assertEquals(j - 1, list.get(j));
}
// add at the end
list.add(list.size(), 6);
assertEquals(testArray.length + 3, list.size());
- for (int j = 0; j < list.size(); j++)
- {
+ for (int j = 0; j < list.size(); j++) {
assertEquals(j - 1, list.get(j));
}
// add past end
- try
- {
- list.add(list.size() + 1, 8);
- fail("should have thrown exception");
- }
- catch (IndexOutOfBoundsException e)
- {
-
- // as expected
- }
+ IntList list2 = list;
+ assertThrows(IndexOutOfBoundsException.class, () -> list2.add(list2.size() + 1, 8));
// test growth
list = new IntList(0);
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j);
}
assertEquals(1000, list.size());
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
assertEquals(j, list.get(j));
}
list = new IntList(0);
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(0, j);
}
assertEquals(1000, list.size());
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
assertEquals(j, list.get(999 - j));
}
}
@@ -130,8 +114,7 @@ public final class TestIntList {
public void testAddAll() {
IntList list = new IntList();
- for (int j = 0; j < 5; j++)
- {
+ for (int j = 0; j < 5; j++) {
list.add(j);
}
IntList list2 = new IntList(0);
@@ -139,29 +122,19 @@ public final class TestIntList {
list2.addAll(list);
list2.addAll(list);
assertEquals(2 * list.size(), list2.size());
- for (int j = 0; j < 5; j++)
- {
+ for (int j = 0; j < 5; j++) {
assertEquals(list2.get(j), j);
assertEquals(list2.get(j + list.size()), j);
}
IntList empty = new IntList();
- int limit = list.size();
+ int limit = list.size();
- for (int j = 0; j < limit; j++)
- {
+ for (int j = 0; j < limit; j++) {
assertTrue(list.addAll(j, empty));
assertEquals(limit, list.size());
}
- try
- {
- list.addAll(limit + 1, empty);
- fail("should have thrown an exception");
- }
- catch (IndexOutOfBoundsException e)
- {
- // as expected
- }
+ assertThrows(IndexOutOfBoundsException.class, () -> list.addAll(limit + 1, empty));
// try add at beginning
empty.addAll(0, list);
@@ -215,20 +188,17 @@ public final class TestIntList {
public void testClear() {
IntList list = new IntList();
- for (int j = 0; j < 500; j++)
- {
+ for (int j = 0; j < 500; j++) {
list.add(j);
}
assertEquals(500, list.size());
list.clear();
assertEquals(0, list.size());
- for (int j = 0; j < 500; j++)
- {
+ for (int j = 0; j < 500; j++) {
list.add(j + 1);
}
assertEquals(500, list.size());
- for (int j = 0; j < 500; j++)
- {
+ for (int j = 0; j < 500; j++) {
assertEquals(j + 1, list.get(j));
}
}
@@ -237,18 +207,13 @@ public final class TestIntList {
public void testContains() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j += 2)
- {
+ for (int j = 0; j < 1000; j += 2) {
list.add(j);
}
- for (int j = 0; j < 1000; j++)
- {
- if (j % 2 == 0)
- {
+ for (int j = 0; j < 1000; j++) {
+ if (j % 2 == 0) {
assertTrue(list.contains(j));
- }
- else
- {
+ } else {
assertFalse(list.contains(j));
}
}
@@ -259,8 +224,7 @@ public final class TestIntList {
IntList list = new IntList();
assertTrue(list.containsAll(list));
- for (int j = 0; j < 10; j++)
- {
+ for (int j = 0; j < 10; j++) {
list.add(j);
}
IntList list2 = new IntList(list);
@@ -306,46 +270,27 @@ public final class TestIntList {
public void testGet() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j);
}
- for (int j = 0; j < 1001; j++)
- {
- try
- {
- assertEquals(j, list.get(j));
- if (j == 1000)
- {
- fail("should have gotten exception");
- }
- }
- catch (IndexOutOfBoundsException e)
- {
- if (j != 1000)
- {
- fail("unexpected IndexOutOfBoundsException");
- }
- }
+ for (int j = 0; j < 1000; j++) {
+ assertEquals(j, list.get(j));
}
+
+ assertThrows(IndexOutOfBoundsException.class, () -> list.get(1000));
}
@Test
public void testIndexOf() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j / 2);
}
- for (int j = 0; j < 1000; j++)
- {
- if (j < 500)
- {
+ for (int j = 0; j < 1000; j++) {
+ if (j < 500) {
assertEquals(j * 2, list.indexOf(j));
- }
- else
- {
+ } else {
assertEquals(-1, list.indexOf(j));
}
}
@@ -378,18 +323,13 @@ public final class TestIntList {
public void testLastIndexOf() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j / 2);
}
- for (int j = 0; j < 1000; j++)
- {
- if (j < 500)
- {
+ for (int j = 0; j < 1000; j++) {
+ if (j < 500) {
assertEquals(1 + j * 2, list.lastIndexOf(j));
- }
- else
- {
+ } else {
assertEquals(-1, list.indexOf(j));
}
}
@@ -399,48 +339,33 @@ public final class TestIntList {
public void testRemove() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j);
}
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
assertEquals(j, list.remove(0));
assertEquals(999 - j, list.size());
}
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j);
}
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
assertEquals(999 - j, list.remove(999 - j));
assertEquals(999 - j, list.size());
}
- try
- {
- list.remove(0);
- fail("should have caught IndexOutOfBoundsException");
- }
- catch (IndexOutOfBoundsException e)
- {
- // as expected
- }
+ assertThrows(IndexOutOfBoundsException.class, () -> list.remove(0));
}
@Test
public void testRemoveValue() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j / 2);
}
- for (int j = 0; j < 1000; j++)
- {
- if (j < 500)
- {
+ for (int j = 0; j < 1000; j++) {
+ if (j < 500) {
assertTrue(list.removeValue(j));
assertTrue(list.removeValue(j));
}
@@ -452,22 +377,17 @@ public final class TestIntList {
public void testRemoveAll() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j);
}
IntList listCopy = new IntList(list);
- IntList listOdd = new IntList();
+ IntList listOdd = new IntList();
IntList listEven = new IntList();
- for (int j = 0; j < 1000; j++)
- {
- if (j % 2 == 0)
- {
+ for (int j = 0; j < 1000; j++) {
+ if (j % 2 == 0) {
listEven.add(j);
- }
- else
- {
+ } else {
listOdd.add(j);
}
}
@@ -494,22 +414,17 @@ public final class TestIntList {
public void testRetainAll() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j);
}
IntList listCopy = new IntList(list);
- IntList listOdd = new IntList();
+ IntList listOdd = new IntList();
IntList listEven = new IntList();
- for (int j = 0; j < 1000; j++)
- {
- if (j % 2 == 0)
- {
+ for (int j = 0; j < 1000; j++) {
+ if (j % 2 == 0) {
listEven.add(j);
- }
- else
- {
+ } else {
listOdd.add(j);
}
}
@@ -535,43 +450,26 @@ public final class TestIntList {
public void testSet() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j);
}
- for (int j = 0; j < 1001; j++)
- {
- try
- {
- list.set(j, j + 1);
- if (j == 1000)
- {
- fail("Should have gotten exception");
- }
- assertEquals(j + 1, list.get(j));
- }
- catch (IndexOutOfBoundsException e)
- {
- if (j != 1000)
- {
- fail("premature exception");
- }
- }
+ for (int j = 0; j < 1000; j++) {
+ list.set(j, j + 1);
+ assertEquals(j + 1, list.get(j));
}
+ assertThrows(IndexOutOfBoundsException.class, () -> list.set(1000, 1001));
}
@Test
public void testSize() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
assertEquals(j, list.size());
list.add(j);
assertEquals(j + 1, list.size());
}
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
assertEquals(1000 - j, list.size());
list.removeValue(j);
assertEquals(999 - j, list.size());
@@ -582,41 +480,36 @@ public final class TestIntList {
public void testToArray() {
IntList list = new IntList();
- for (int j = 0; j < 1000; j++)
- {
+ for (int j = 0; j < 1000; j++) {
list.add(j);
}
int[] a1 = list.toArray();
assertEquals(a1.length, list.size());
- for (int j = 0; j < 1000; j++)
- {
- assertEquals(a1[ j ], list.get(j));
+ for (int j = 0; j < 1000; j++) {
+ assertEquals(a1[j], list.get(j));
}
- int[] a2 = new int[ list.size() ];
+ int[] a2 = new int[list.size()];
int[] a3 = list.toArray(a2);
assertSame(a2, a3);
- for (int j = 0; j < 1000; j++)
- {
- assertEquals(a2[ j ], list.get(j));
+ for (int j = 0; j < 1000; j++) {
+ assertEquals(a2[j], list.get(j));
}
- int[] aShort = new int[ list.size() - 1 ];
- int[] aLong = new int[ list.size() + 1 ];
- int[] a4 = list.toArray(aShort);
- int[] a5 = list.toArray(aLong);
+ int[] aShort = new int[list.size() - 1];
+ int[] aLong = new int[list.size() + 1];
+ int[] a4 = list.toArray(aShort);
+ int[] a5 = list.toArray(aLong);
assertNotSame(a4, aShort);
assertNotSame(a5, aLong);
assertEquals(a4.length, list.size());
- for (int j = 0; j < 1000; j++)
- {
- assertEquals(a3[ j ], list.get(j));
+ for (int j = 0; j < 1000; j++) {
+ assertEquals(a3[j], list.get(j));
}
assertEquals(a5.length, list.size());
- for (int j = 0; j < 1000; j++)
- {
- assertEquals(a5[ j ], list.get(j));
+ for (int j = 0; j < 1000; j++) {
+ assertEquals(a5[j], list.get(j));
}
}
}
diff --git a/src/testcases/org/apache/poi/util/TestIntegerField.java b/src/testcases/org/apache/poi/util/TestIntegerField.java
index e9ca052944..517216dbf3 100644
--- a/src/testcases/org/apache/poi/util/TestIntegerField.java
+++ b/src/testcases/org/apache/poi/util/TestIntegerField.java
@@ -17,13 +17,13 @@
package org.apache.poi.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.io.ByteArrayInputStream;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test IntegerField code
@@ -34,48 +34,26 @@ public final class TestIntegerField {
@Test
public void testConstructors() {
- try
- {
- new IntegerField(-1);
- fail("Should have caught ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new IntegerField(-1));
IntegerField field = new IntegerField(2);
assertEquals(0, field.get());
- try
- {
- new IntegerField(-1, 1);
- fail("Should have caught ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new IntegerField(-1, 1));
field = new IntegerField(2, 0x12345678);
assertEquals(0x12345678, field.get());
- byte[] array = new byte[ 6 ];
- try
- {
- new IntegerField(-1, 1, array);
- fail("Should have caught ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new IntegerField(-1, 1, new byte[ 6 ]));
+
+ byte[] array = new byte[ 6 ];
field = new IntegerField(2, 0x12345678, array);
assertEquals(0x12345678, field.get());
assertEquals(( byte ) 0x78, array[ 2 ]);
assertEquals(( byte ) 0x56, array[ 3 ]);
assertEquals(( byte ) 0x34, array[ 4 ]);
assertEquals(( byte ) 0x12, array[ 5 ]);
- array = new byte[ 5 ];
- try
- {
- new IntegerField(2, 5, array);
- fail("should have gotten ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
+
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new IntegerField(2, 5, new byte[ 5 ]));
+
for (int element : _test_array) {
array = new byte[ 4 ];
new IntegerField(0, element, array);
@@ -90,43 +68,31 @@ public final class TestIntegerField {
for (int j = 0; j < _test_array.length; j++) {
field.set(_test_array[ j ]);
- assertEquals("testing _1 " + j, _test_array[ j ], field.get());
+ assertEquals(_test_array[ j ], field.get(), "testing _1 " + j);
field = new IntegerField(0);
field.set(_test_array[ j ], array);
- assertEquals("testing _2 ", _test_array[ j ], field.get());
- assertEquals("testing _3.0 " + _test_array[ j ],
- ( byte ) (_test_array[ j ] % 256), array[ 0 ]);
- assertEquals("testing _3.1 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 8) % 256),
- array[ 1 ]);
- assertEquals("testing _3.2 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 16) % 256),
- array[ 2 ]);
- assertEquals("testing _3.3 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 24) % 256),
- array[ 3 ]);
+ assertEquals(_test_array[ j ], field.get(), "testing _2 ");
+ assertEquals(( byte ) (_test_array[ j ] % 256), array[ 0 ], "testing _3.0 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 8) % 256), array[ 1 ], "testing _3.1 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 16) % 256), array[ 2 ], "testing _3.2 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 24) % 256), array[ 3 ], "testing _3.3 " + _test_array[ j ]);
}
}
@Test
public void testReadFromBytes() {
- IntegerField field = new IntegerField(1);
+ IntegerField field1 = new IntegerField(1);
byte[] array = new byte[ 4 ];
- try {
- field.readFromBytes(array);
- fail("should have caught ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
- field = new IntegerField(0);
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> field1.readFromBytes(array));
+ IntegerField field2 = new IntegerField(0);
for (int j = 0; j < _test_array.length; j++) {
array[ 0 ] = ( byte ) (_test_array[ j ] % 256);
array[ 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256);
array[ 2 ] = ( byte ) ((_test_array[ j ] >> 16) % 256);
array[ 3 ] = ( byte ) ((_test_array[ j ] >> 24) % 256);
- field.readFromBytes(array);
- assertEquals("testing " + j, _test_array[ j ], field.get());
+ field2.readFromBytes(array);
+ assertEquals(_test_array[ j ], field2.get(), "testing " + j);
}
}
@@ -145,7 +111,7 @@ public final class TestIntegerField {
for (int j = 0; j < buffer.length / 4; j++) {
field.readFromStream(stream);
- assertEquals("Testing " + j, _test_array[ j ], field.get());
+ assertEquals(_test_array[ j ], field.get(), "Testing " + j);
}
}
@@ -163,7 +129,7 @@ public final class TestIntegerField {
val += (array[ 2 ] << 16) & 0x00FF0000;
val += (array[ 1 ] << 8) & 0x0000FF00;
val += (array[ 0 ] & 0x000000FF);
- assertEquals("testing ", b, val);
+ assertEquals(b, val, "testing ");
}
}
}
diff --git a/src/testcases/org/apache/poi/util/TestLittleEndian.java b/src/testcases/org/apache/poi/util/TestLittleEndian.java
index 24072fa656..30d3a8e96e 100644
--- a/src/testcases/org/apache/poi/util/TestLittleEndian.java
+++ b/src/testcases/org/apache/poi/util/TestLittleEndian.java
@@ -17,16 +17,16 @@
package org.apache.poi.util;
-import static org.junit.Assert.assertEquals;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.util.LittleEndian.BufferUnderrunException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test LittleEndian functionality
@@ -81,7 +81,7 @@ public final class TestLittleEndian {
assertEquals(testdata3[2], (byte)0xFF);
assertEquals(expected2, LittleEndian.getUShort(testdata3));
assertEquals(expected3, LittleEndian.getUShort(testdata3, 1));
-
+
}
private static final byte[] _double_array =
@@ -239,13 +239,13 @@ public final class TestLittleEndian {
assertTrue(compareByteArrays(received, expected, 1, LittleEndianConsts.LONG_SIZE));
}
- private static byte[] _good_array = {
- 0x01, 0x02, 0x01, 0x02,
- 0x01, 0x02, 0x01, 0x02,
+ private static final byte[] _good_array = {
+ 0x01, 0x02, 0x01, 0x02,
+ 0x01, 0x02, 0x01, 0x02,
0x01, 0x02, 0x01, 0x02,
0x01, 0x02, 0x01, 0x02,
};
- private static byte[] _bad_array = {
+ private static final byte[] _bad_array = {
0x01
};
@@ -269,13 +269,8 @@ public final class TestLittleEndian {
}
assertEquals(count,
_good_array.length / LittleEndianConsts.SHORT_SIZE);
- stream = new ByteArrayInputStream(_bad_array);
- try {
- LittleEndian.readShort(stream);
- fail("Should have caught BufferUnderrunException");
- } catch (BufferUnderrunException ignored) {
- // as expected
- }
+ ByteArrayInputStream stream2 = new ByteArrayInputStream(_bad_array);
+ assertThrows(BufferUnderrunException.class, () -> LittleEndian.readShort(stream2));
}
/**
@@ -297,14 +292,8 @@ public final class TestLittleEndian {
}
}
assertEquals(count, _good_array.length / LittleEndianConsts.INT_SIZE);
- stream = new ByteArrayInputStream(_bad_array);
- try {
- LittleEndian.readInt(stream);
- fail("Should have caught BufferUnderrunException");
- } catch (BufferUnderrunException ignored) {
-
- // as expected
- }
+ ByteArrayInputStream stream2 = new ByteArrayInputStream(_bad_array);
+ assertThrows(BufferUnderrunException.class, () -> LittleEndian.readInt(stream2));
}
/**
@@ -325,18 +314,12 @@ public final class TestLittleEndian {
break;
}
}
- assertEquals(count,
- _good_array.length / LittleEndianConsts.LONG_SIZE);
- stream = new ByteArrayInputStream(_bad_array);
- try {
- LittleEndian.readLong(stream);
- fail("Should have caught BufferUnderrunException");
- } catch (BufferUnderrunException ignored) {
- // as expected
- }
+ assertEquals(count, _good_array.length / LittleEndianConsts.LONG_SIZE);
+ ByteArrayInputStream stream2 = new ByteArrayInputStream(_bad_array);
+ assertThrows(BufferUnderrunException.class, () -> LittleEndian.readLong(stream2));
}
- @Test(expected = BufferUnderrunException.class)
+ @Test
public void testReadFromStream() throws IOException {
int actual;
actual = LittleEndian.readUShort(new ByteArrayInputStream(new byte[] { 5, -128, }));
@@ -345,7 +328,8 @@ public final class TestLittleEndian {
actual = LittleEndian.readUShort(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, }));
assertEquals(513, actual);
- LittleEndian.readInt(new ByteArrayInputStream(new byte[] { 1, 2, 3, }));
+ assertThrows(BufferUnderrunException.class, () ->
+ LittleEndian.readInt(new ByteArrayInputStream(new byte[] { 1, 2, 3, })));
}
@Test
diff --git a/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java b/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
index 7e048dbc3a..36af4524e9 100644
--- a/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
+++ b/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
@@ -17,17 +17,17 @@
package org.apache.poi.util;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test {@link LittleEndianInputStream} and {@link LittleEndianOutputStream}
@@ -74,8 +74,8 @@ public final class TestLittleEndianStreams {
byte[] actBuf = new byte[4];
lei.readFully(actBuf);
- assertFalse("Identified bug in readFully() - source buffer was modified",
- actBuf[0] == 0x00 && srcBuf[0] == 0x77 && srcBuf[3] == 0x44);
+ assertFalse(actBuf[0] == 0x00 && srcBuf[0] == 0x77 && srcBuf[3] == 0x44,
+ "Identified bug in readFully() - source buffer was modified");
byte[] expBuf = HexRead.readFromString("77 66 55 44");
assertArrayEquals(actBuf, expBuf);
diff --git a/src/testcases/org/apache/poi/util/TestLocaleUtil.java b/src/testcases/org/apache/poi/util/TestLocaleUtil.java
index aeb79b973c..0b6b8d6642 100644
--- a/src/testcases/org/apache/poi/util/TestLocaleUtil.java
+++ b/src/testcases/org/apache/poi/util/TestLocaleUtil.java
@@ -17,17 +17,17 @@
package org.apache.poi.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assume.assumeFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
-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 TestLocaleUtil {
@@ -41,7 +41,7 @@ public class TestLocaleUtil {
* Reset the Locale to the user default before the test so that it isn't influenced
* by the LocaleUtil's state being changed by previous tests.
*/
- @Before
+ @BeforeEach
@SuppressForbidden("implementation around default locales in POI")
public void setUp() {
// reset the user locale and time zone so that tests do not interfere with each other
@@ -60,7 +60,7 @@ public class TestLocaleUtil {
* Reset the Locale to the user default after the test so that it doesn't influence
* other tests.
*/
- @After
+ @AfterEach
public void tearDown() {
LocaleUtil.resetUserLocale();
LocaleUtil.resetUserTimeZone();
@@ -118,10 +118,10 @@ public class TestLocaleUtil {
private static void assertCalendarNotEquals(Calendar expected, Calendar actual) {
// FIXME: add more tests to compare calendars, ignoring whether the dates are equal
- assertNotEquals("time zone", expected.getTimeZone(), actual.getTimeZone());
+ assertNotEquals(expected.getTimeZone(), actual.getTimeZone(), "time zone");
}
private static void assertCalendarEquals(Calendar expected, Calendar actual) {
// FIXME: add more tests to compare calendars, ignoring whether the set dates are equal
- assertEquals("time zone", expected.getTimeZone(), actual.getTimeZone());
+ assertEquals(expected.getTimeZone(), actual.getTimeZone(), "time zone");
}
}
diff --git a/src/testcases/org/apache/poi/util/TestLongField.java b/src/testcases/org/apache/poi/util/TestLongField.java
index 7f50bd97cd..952af51bb3 100644
--- a/src/testcases/org/apache/poi/util/TestLongField.java
+++ b/src/testcases/org/apache/poi/util/TestLongField.java
@@ -17,13 +17,14 @@
package org.apache.poi.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 static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test LongField code
@@ -37,33 +38,21 @@ public final class TestLongField {
@Test
public void testConstructors() {
- try {
- new LongField(-1);
- fail("Should have caught ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
- LongField field = new LongField(2);
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new LongField(-1));
- assertEquals(0L, field.get());
- try {
- new LongField(-1, 1L);
- fail("Should have caught ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
- field = new LongField(2, 0x123456789ABCDEF0L);
- assertEquals(0x123456789ABCDEF0L, field.get());
- byte[] array = new byte[ 10 ];
+ LongField field1 = new LongField(2);
+ assertEquals(0L, field1.get());
- try {
- new LongField(-1, 1L, array);
- fail("Should have caught ArrayIndexOutOfBoundsException");
- }
- catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
- field = new LongField(2, 0x123456789ABCDEF0L, array);
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new LongField(-1, 1L));
+
+ LongField field2 = new LongField(2, 0x123456789ABCDEF0L);
+ assertEquals(0x123456789ABCDEF0L, field2.get());
+
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new LongField(-1, 1L, new byte[ 10 ]));
+
+
+ byte[] array = new byte[ 10 ];
+ LongField field = new LongField(2, 0x123456789ABCDEF0L, array);
assertEquals(0x123456789ABCDEF0L, field.get());
assertEquals(( byte ) 0xF0, array[ 2 ]);
assertEquals(( byte ) 0xDE, array[ 3 ]);
@@ -73,13 +62,9 @@ public final class TestLongField {
assertEquals(( byte ) 0x56, array[ 7 ]);
assertEquals(( byte ) 0x34, array[ 8 ]);
assertEquals(( byte ) 0x12, array[ 9 ]);
- array = new byte[ 9 ];
- try {
- new LongField(2, 5L, array);
- fail("should have gotten ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
+
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new LongField(2, 5L, new byte[ 9 ]));
+
for (long element : _test_array) {
array = new byte[ 8 ];
new LongField(0, element, array);
@@ -94,33 +79,18 @@ public final class TestLongField {
for (int j = 0; j < _test_array.length; j++) {
field.set(_test_array[ j ]);
- assertEquals("testing _1 " + j, _test_array[ j ], field.get());
+ assertEquals(_test_array[ j ], field.get(), "testing _1 " + j);
field = new LongField(0);
field.set(_test_array[ j ], array);
- assertEquals("testing _2 ", _test_array[ j ], field.get());
- assertEquals("testing _3.0 " + _test_array[ j ],
- ( byte ) (_test_array[ j ] % 256), array[ 0 ]);
- assertEquals("testing _3.1 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 8) % 256),
- array[ 1 ]);
- assertEquals("testing _3.2 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 16) % 256),
- array[ 2 ]);
- assertEquals("testing _3.3 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 24) % 256),
- array[ 3 ]);
- assertEquals("testing _3.4 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 32) % 256),
- array[ 4 ]);
- assertEquals("testing _3.5 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 40) % 256),
- array[ 5 ]);
- assertEquals("testing _3.6 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 48) % 256),
- array[ 6 ]);
- assertEquals("testing _3.7 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 56) % 256),
- array[ 7 ]);
+ assertEquals(_test_array[ j ], field.get(), "testing _2 ");
+ assertEquals(( byte ) (_test_array[ j ] % 256), array[ 0 ], "testing _3.0 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 8) % 256), array[ 1 ], "testing _3.1 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 16) % 256), array[ 2 ], "testing _3.2 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 24) % 256), array[ 3 ], "testing _3.3 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 32) % 256), array[ 4 ], "testing _3.4 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 40) % 256), array[ 5 ], "testing _3.5 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 48) % 256), array[ 6 ], "testing _3.6 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 56) % 256), array[ 7 ], "testing _3.7 " + _test_array[ j ]);
}
}
@@ -146,7 +116,7 @@ public final class TestLongField {
array[ 6 ] = ( byte ) ((_test_array[ j ] >> 48) % 256);
array[ 7 ] = ( byte ) ((_test_array[ j ] >> 56) % 256);
field.readFromBytes(array);
- assertEquals("testing " + j, _test_array[ j ], field.get());
+ assertEquals(_test_array[ j ], field.get(), "testing " + j);
}
}
@@ -169,7 +139,7 @@ public final class TestLongField {
for (int j = 0; j < buffer.length / 8; j++) {
field.readFromStream(stream);
- assertEquals("Testing " + j, _test_array[ j ], field.get());
+ assertEquals(_test_array[ j ], field.get(), "Testing " + j);
}
}
@@ -191,7 +161,7 @@ public final class TestLongField {
val += ((( long ) array[ 2 ]) << 16) & 0x0000000000FF0000L;
val += ((( long ) array[ 1 ]) << 8) & 0x000000000000FF00L;
val += (array[ 0 ] & 0x00000000000000FFL);
- assertEquals("testing ", element, val);
+ assertEquals(element, val, "testing ");
}
}
}
diff --git a/src/testcases/org/apache/poi/util/TestPOILogFactory.java b/src/testcases/org/apache/poi/util/TestPOILogFactory.java
index 666d1d9b2f..a4580bb04a 100644
--- a/src/testcases/org/apache/poi/util/TestPOILogFactory.java
+++ b/src/testcases/org/apache/poi/util/TestPOILogFactory.java
@@ -17,7 +17,7 @@
package org.apache.poi.util;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestPOILogFactory {
diff --git a/src/testcases/org/apache/poi/util/TestPOILogger.java b/src/testcases/org/apache/poi/util/TestPOILogger.java
index 0c6765cf14..d40d475ac7 100644
--- a/src/testcases/org/apache/poi/util/TestPOILogger.java
+++ b/src/testcases/org/apache/poi/util/TestPOILogger.java
@@ -18,11 +18,11 @@
package org.apache.poi.util;
-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 org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the log class.
@@ -30,7 +30,7 @@ import org.junit.Test;
public final class TestPOILogger implements POILogger {
private String lastLog = "";
private Throwable lastEx;
-
+
/**
* Test different types of log output.
*/
@@ -41,23 +41,23 @@ public final class TestPOILogger implements POILogger {
POILogFactory._loggerClassName = TestPOILogger.class.getName();
POILogger log = POILogFactory.getLogger( "foo" );
assertTrue(log instanceof TestPOILogger);
-
+
TestPOILogger tLog = (TestPOILogger)log;
-
+
log.log(POILogger.WARN, "Test = ", 1);
assertEquals("Test = 1", tLog.lastLog);
-
+
log.log(POILogger.ERROR, "Test ", 1,2,new Exception("bla"));
assertEquals("Test 12", tLog.lastLog);
assertNotNull(tLog.lastEx);
-
+
log.log(POILogger.ERROR, "log\nforging", "\nevil","\nlog");
assertEquals("log forging evil log", tLog.lastLog);
} finally {
POILogFactory._loggerClassName = oldLCN;
}
}
-
+
// ---------- POI Logger methods implemented for testing ----------
@Override
diff --git a/src/testcases/org/apache/poi/util/TestRLEDecompressingInputStream.java b/src/testcases/org/apache/poi/util/TestRLEDecompressingInputStream.java
index b403fc53a0..ee43e08df1 100644
--- a/src/testcases/org/apache/poi/util/TestRLEDecompressingInputStream.java
+++ b/src/testcases/org/apache/poi/util/TestRLEDecompressingInputStream.java
@@ -17,8 +17,8 @@
package org.apache.poi.util;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -26,33 +26,33 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestRLEDecompressingInputStream {
-
+
/**
* Section 3.2.1 No Compression Example
- *
+ *
* The following string illustrates an ASCII text string with a set of characters that cannot be compressed
* by the compression algorithm specified in section 2.4.1.
- *
+ *
* abcdefghijklmnopqrstuv.
- *
+ *
* This example is provided to demonstrate the results of compressing and decompressing the string
* using an interoperable implementation of the algorithm specified in section 2.4.1.
- *
+ *
* The following hex array represents the compressed byte array of the example string as compressed by
* the compression algorithm.
- *
+ *
* 01 19 B0 00 61 62 63 64 65 66 67 68 00 69 6A 6B 6C
* 6D 6E 6F 70 00 71 72 73 74 75 76 2E
- *
+ *
* The following hex array represents the decompressed byte array of the example string as
* decompressed by the decompression algorithm.
- *
+ *
* 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71
* 72 73 74 75 76 2E
- *
+ *
*/
@Test
public void noCompressionExample() {
@@ -66,23 +66,23 @@ public class TestRLEDecompressingInputStream {
/**
* Section 3.2.2 Normal Compression Example
- *
+ *
* The following string illustrates an ASCII text string with a typical set of characters that can be
* compressed by the compression algorithm.
- *
+ *
* #aaabcdefaaaaghijaaaaaklaaamnopqaaaaaaaaaaaarstuvwxyzaaa
- *
+ *
* This example is provided to demonstrate the results of compressing and decompressing the example
* string using an interoperable implementation of the algorithm specified in section 2.4.1.
- *
+ *
* The following hex array represents the compressed byte array of the example string as compressed by
* the compression algorithm:
- *
+ *
* 01 2F B0 00 23 61 61 61 62 63 64 65 82 66 00 70
* 61 67 68 69 6A 01 38 08 61 6B 6C 00 30 6D 6E 6F
* 70 06 71 02 70 04 10 72 73 74 75 76 10 77 78 79
* 7A 00 3C
- *
+ *
* The following hex array represents the decompressed byte array of the example string as
* decompressed by the decompression algorithm:
*
@@ -102,23 +102,23 @@ public class TestRLEDecompressingInputStream {
final String expected = "#aaabcdefaaaaghijaaaaaklaaamnopqaaaaaaaaaaaarstuvwxyzaaa";
checkRLEDecompression(expected, compressed);
}
-
+
/**
* Section 3.2.3 Maximum Compression Example
- *
+ *
* The following string illustrates an ASCII text string with a typical set of characters that can be
* compressed by the compression algorithm.
- *
+ *
* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- *
+ *
* This example is provided to demonstrate the results of compressing and decompressing the example
* string using an interoperable implementation of the algorithm specified in section 2.4.1.
- *
+ *
* The following hex array represents the compressed byte array of the example string as compressed by
* the compression algorithm:
- *
+ *
* 01 03 B0 02 61 45 00
- *
+ *
* The following hex array represents the decompressed byte array of the example string as
* decompressed by the decompression algorithm:
*
@@ -136,7 +136,7 @@ public class TestRLEDecompressingInputStream {
final String expected = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
checkRLEDecompression(expected, compressed);
}
-
+
@Test
public void decompress() throws IOException {
final byte[] compressed = {
@@ -146,7 +146,7 @@ public class TestRLEDecompressingInputStream {
final byte[] expected = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".getBytes(StringUtil.UTF8);
assertArrayEquals(expected, expanded);
}
-
+
private static void checkRLEDecompression(String expected, byte[] runLengthEncodedData) {
InputStream compressedStream = new ByteArrayInputStream(runLengthEncodedData);
ByteArrayOutputStream out = new ByteArrayOutputStream();
diff --git a/src/testcases/org/apache/poi/util/TestShortField.java b/src/testcases/org/apache/poi/util/TestShortField.java
index c31202f2cc..2ae0cb6ef0 100644
--- a/src/testcases/org/apache/poi/util/TestShortField.java
+++ b/src/testcases/org/apache/poi/util/TestShortField.java
@@ -17,13 +17,14 @@
package org.apache.poi.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 static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test ShortField code
@@ -34,42 +35,24 @@ public final class TestShortField {
@Test
public void testConstructors() {
- try {
- new ShortField(-1);
- fail("Should have caught ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new ShortField(-1));
ShortField field = new ShortField(2);
assertEquals(0, field.get());
- try {
- new ShortField(-1, ( short ) 1);
- fail("Should have caught ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new ShortField(-1, ( short ) 1));
field = new ShortField(2, ( short ) 0x1234);
assertEquals(0x1234, field.get());
- byte[] array = new byte[ 4 ];
- try {
- new ShortField(-1, ( short ) 1, array);
- fail("Should have caught ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new ShortField(-1, ( short ) 1, new byte[ 4 ]));
+
+ byte[] array = new byte[ 4 ];
field = new ShortField(2, ( short ) 0x1234, array);
assertEquals(( short ) 0x1234, field.get());
assertEquals(( byte ) 0x34, array[ 2 ]);
assertEquals(( byte ) 0x12, array[ 3 ]);
- array = new byte[ 3 ];
- try {
- new ShortField(2, ( short ) 5, array);
- fail("should have gotten ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
+
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> new ShortField(2, ( short ) 5, new byte[ 3 ]));
+
for (short element : _test_array) {
array = new byte[ 2 ];
new ShortField(0, element, array);
@@ -84,36 +67,29 @@ public final class TestShortField {
for (int j = 0; j < _test_array.length; j++) {
field.set(_test_array[ j ]);
- assertEquals("testing _1 " + j, _test_array[ j ], field.get());
+ assertEquals(_test_array[ j ], field.get(), "testing _1 " + j);
field = new ShortField(0);
field.set(_test_array[ j ], array);
- assertEquals("testing _2 ", _test_array[ j ], field.get());
- assertEquals("testing _3.0 " + _test_array[ j ],
- ( byte ) (_test_array[ j ] % 256), array[ 0 ]);
- assertEquals("testing _3.1 " + _test_array[ j ],
- ( byte ) ((_test_array[ j ] >> 8) % 256),
- array[ 1 ]);
+ assertEquals(_test_array[ j ], field.get(), "testing _2 ");
+ assertEquals(( byte ) (_test_array[ j ] % 256), array[ 0 ], "testing _3.0 " + _test_array[ j ]);
+ assertEquals(( byte ) ((_test_array[ j ] >> 8) % 256), array[ 1 ], "testing _3.1 " + _test_array[ j ]);
}
}
@Test
public void testReadFromBytes() {
- ShortField field = new ShortField(1);
+ ShortField field1 = new ShortField(1);
byte[] array = new byte[ 2 ];
- try {
- field.readFromBytes(array);
- fail("should have caught ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException ignored_e) {
- // as expected
- }
- field = new ShortField(0);
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> field1.readFromBytes(array));
+
+ ShortField field2 = new ShortField(0);
for (int j = 0; j < _test_array.length; j++)
{
array[ 0 ] = ( byte ) (_test_array[ j ] % 256);
array[ 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256);
- field.readFromBytes(array);
- assertEquals("testing " + j, _test_array[ j ], field.get());
+ field2.readFromBytes(array);
+ assertEquals(_test_array[ j ], field2.get(), "testing " + j);
}
}
@@ -132,7 +108,7 @@ public final class TestShortField {
for (int j = 0; j < buffer.length / 2; j++)
{
field.readFromStream(stream);
- assertEquals("Testing " + j, _test_array[ j ], field.get());
+ assertEquals(_test_array[ j ], field.get(), "Testing " + j);
}
}
@@ -148,7 +124,7 @@ public final class TestShortField {
val &= ( short ) 0xFF00;
val += ( short ) (array[ 0 ] & 0x00FF);
- assertEquals("testing ", element, val);
+ assertEquals(element, val, "testing ");
}
}
}
diff --git a/src/testcases/org/apache/poi/util/TestStringCodepointsIterable.java b/src/testcases/org/apache/poi/util/TestStringCodepointsIterable.java
index e61aea653f..7152ec6cef 100644
--- a/src/testcases/org/apache/poi/util/TestStringCodepointsIterable.java
+++ b/src/testcases/org/apache/poi/util/TestStringCodepointsIterable.java
@@ -17,11 +17,12 @@
package org.apache.poi.util;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.util.ArrayList;
import java.util.List;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit test for StringCodepointsIterable
@@ -37,8 +38,8 @@ public class TestStringCodepointsIterable {
List<String> codePoints2 = new ArrayList<>();
sci.iterator().forEachRemaining(codePoints::add);
sci.iterator().forEachRemaining(codePoints2::add);
- Assert.assertEquals(17, codePoints.size());
- Assert.assertEquals(codePoints, codePoints2);
+ assertEquals(17, codePoints.size());
+ assertEquals(codePoints, codePoints2);
}
}
diff --git a/src/testcases/org/apache/poi/util/TestStringUtil.java b/src/testcases/org/apache/poi/util/TestStringUtil.java
index b70a7dbda1..a03ab6a127 100644
--- a/src/testcases/org/apache/poi/util/TestStringUtil.java
+++ b/src/testcases/org/apache/poi/util/TestStringUtil.java
@@ -17,14 +17,15 @@
package org.apache.poi.util;
-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 static org.junit.jupiter.api.Assertions.fail;
import java.nio.charset.Charset;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit test for StringUtil
@@ -66,82 +67,60 @@ public class TestStringUtil {
StringUtil.putCompressedUnicode( input, output, 0 );
for ( int j = 0; j < expected_output.length; j++ )
{
- assertEquals( "testing offset " + j, expected_output[j],
- output[j] );
+ assertEquals( expected_output[j], output[j], "testing offset " + j );
}
StringUtil.putCompressedUnicode( input, output,
100 - expected_output.length );
for ( int j = 0; j < expected_output.length; j++ )
{
- assertEquals( "testing offset " + j, expected_output[j],
- output[100 + j - expected_output.length] );
- }
- try
- {
- StringUtil.putCompressedUnicode( input, output,
- 101 - expected_output.length );
- fail( "Should have caught ArrayIndexOutOfBoundsException" );
- }
- catch ( ArrayIndexOutOfBoundsException ignored )
- {
- // as expected
+ assertEquals( expected_output[j], output[100 + j - expected_output.length], "testing offset " + j );
}
+
+ assertThrows(ArrayIndexOutOfBoundsException.class,
+ () -> StringUtil.putCompressedUnicode( input, output, 101 - expected_output.length ));
}
@Test
public void testPutUncompressedUnicode() {
byte[] output = new byte[100];
String input = "Hello World";
- byte[] expected_output =
- {
- (byte) 'H', (byte) 0, (byte) 'e', (byte) 0, (byte) 'l',
- (byte) 0, (byte) 'l', (byte) 0, (byte) 'o', (byte) 0,
- (byte) ' ', (byte) 0, (byte) 'W', (byte) 0, (byte) 'o',
- (byte) 0, (byte) 'r', (byte) 0, (byte) 'l', (byte) 0,
- (byte) 'd', (byte) 0
- };
+ byte[] expected_output = {
+ (byte) 'H', (byte) 0, (byte) 'e', (byte) 0, (byte) 'l',
+ (byte) 0, (byte) 'l', (byte) 0, (byte) 'o', (byte) 0,
+ (byte) ' ', (byte) 0, (byte) 'W', (byte) 0, (byte) 'o',
+ (byte) 0, (byte) 'r', (byte) 0, (byte) 'l', (byte) 0,
+ (byte) 'd', (byte) 0
+ };
StringUtil.putUnicodeLE( input, output, 0 );
- for ( int j = 0; j < expected_output.length; j++ )
- {
- assertEquals( "testing offset " + j, expected_output[j],
- output[j] );
+ for ( int j = 0; j < expected_output.length; j++ ) {
+ assertEquals( expected_output[j], output[j], "testing offset " + j );
}
- StringUtil.putUnicodeLE( input, output,
- 100 - expected_output.length );
- for ( int j = 0; j < expected_output.length; j++ )
- {
- assertEquals( "testing offset " + j, expected_output[j],
- output[100 + j - expected_output.length] );
- }
- try
- {
- StringUtil.putUnicodeLE( input, output,
- 101 - expected_output.length );
- fail( "Should have caught ArrayIndexOutOfBoundsException" );
- }
- catch ( ArrayIndexOutOfBoundsException ignored )
- {
- // as expected
+ StringUtil.putUnicodeLE( input, output, 100 - expected_output.length );
+ for ( int j = 0; j < expected_output.length; j++ ) {
+ assertEquals( expected_output[j], output[100 + j - expected_output.length], "testing offset " + j );
}
+
+ assertThrows(ArrayIndexOutOfBoundsException.class, () ->
+ StringUtil.putUnicodeLE( input, output, 101 - expected_output.length ));
}
@Test
public void startsWithIgnoreCase() {
- assertTrue("same string", StringUtil.startsWithIgnoreCase("Apache POI", "Apache POI"));
- assertTrue("longer string", StringUtil.startsWithIgnoreCase("Apache POI project", "Apache POI"));
- assertTrue("different case", StringUtil.startsWithIgnoreCase("APACHE POI", "Apache POI"));
- assertFalse("leading whitespace should not be ignored", StringUtil.startsWithIgnoreCase(" Apache POI project", "Apache POI"));
- assertFalse("shorter string", StringUtil.startsWithIgnoreCase("Apache", "Apache POI"));
+ assertTrue(StringUtil.startsWithIgnoreCase("Apache POI", "Apache POI"), "same string");
+ assertTrue(StringUtil.startsWithIgnoreCase("Apache POI project", "Apache POI"), "longer string");
+ assertTrue(StringUtil.startsWithIgnoreCase("APACHE POI", "Apache POI"), "different case");
+ assertFalse(StringUtil.startsWithIgnoreCase(" Apache POI project", "Apache POI"), "leading whitespace should not be ignored");
+ assertFalse(StringUtil.startsWithIgnoreCase("Apache", "Apache POI"), "shorter string");
}
@Test
public void endsWithIgnoreCase() {
- assertTrue("same string", StringUtil.endsWithIgnoreCase("Apache POI", "Apache POI"));
- assertTrue("longer string", StringUtil.endsWithIgnoreCase("Project Apache POI", "Apache POI"));
- assertTrue("different case", StringUtil.endsWithIgnoreCase("APACHE POI", "Apache POI"));
- assertFalse("trailing whitespace should not be ignored", StringUtil.endsWithIgnoreCase("Apache POI project ", "Apache POI"));
- assertFalse("shorter string", StringUtil.endsWithIgnoreCase("Apache", "Apache POI"));
+ assertTrue(StringUtil.endsWithIgnoreCase("Apache POI", "Apache POI"), "same string");
+ assertTrue(StringUtil.endsWithIgnoreCase("Project Apache POI", "Apache POI"), "longer string");
+ assertTrue(StringUtil.endsWithIgnoreCase("APACHE POI", "Apache POI"), "different case");
+ assertFalse(StringUtil.endsWithIgnoreCase("Apache POI project ", "Apache POI"), "trailing whitespace should not be ignored");
+ assertFalse(StringUtil.endsWithIgnoreCase("Apache", "Apache POI"), "shorter string");
}
@Test
@@ -152,27 +131,27 @@ public class TestStringUtil {
assertEquals("5|8.5|true|string", StringUtil.join("|", 5, 8.5, true, "string")); //assumes Locale prints number decimal point as a period rather than a comma
String[] arr = new String[] { "Apache", "POI", "project" };
- assertEquals("no separator", "ApachePOIproject", StringUtil.join(arr));
- assertEquals("separator", "Apache POI project", StringUtil.join(arr, " "));
+ assertEquals("ApachePOIproject", StringUtil.join(arr), "no separator");
+ assertEquals("Apache POI project", StringUtil.join(arr, " "), "separator");
}
@Test
public void count() {
String test = "Apache POI project\n\u00a9 Copyright 2016";
// supports search in null or empty string
- assertEquals("null", 0, StringUtil.countMatches(null, 'A'));
- assertEquals("empty string", 0, StringUtil.countMatches("", 'A'));
+ assertEquals(0, StringUtil.countMatches(null, 'A'), "null");
+ assertEquals(0, StringUtil.countMatches("", 'A'), "empty string");
- assertEquals("normal", 2, StringUtil.countMatches(test, 'e'));
- assertEquals("normal, should not find a in escaped copyright", 1, StringUtil.countMatches(test, 'a'));
+ assertEquals(2, StringUtil.countMatches(test, 'e'), "normal");
+ assertEquals(1, StringUtil.countMatches(test, 'a'), "normal, should not find a in escaped copyright");
// search for non-printable characters
- assertEquals("null character", 0, StringUtil.countMatches(test, '\0'));
- assertEquals("CR", 0, StringUtil.countMatches(test, '\r'));
- assertEquals("LF", 1, StringUtil.countMatches(test, '\n'));
+ assertEquals(0, StringUtil.countMatches(test, '\0'), "null character");
+ assertEquals(0, StringUtil.countMatches(test, '\r'), "CR");
+ assertEquals(1, StringUtil.countMatches(test, '\n'), "LF");
// search for unicode characters
- assertEquals("Unicode", 1, StringUtil.countMatches(test, '\u00a9'));
+ assertEquals(1, StringUtil.countMatches(test, '\u00a9'), "Unicode");
}
}
diff --git a/src/testcases/org/apache/poi/util/TestTempFile.java b/src/testcases/org/apache/poi/util/TestTempFile.java
index ac1904dabc..8ed0e837c1 100644
--- a/src/testcases/org/apache/poi/util/TestTempFile.java
+++ b/src/testcases/org/apache/poi/util/TestTempFile.java
@@ -16,11 +16,11 @@
==================================================================== */
package org.apache.poi.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-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.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 java.io.File;
import java.io.FileOutputStream;
@@ -28,20 +28,20 @@ import java.io.IOException;
import java.util.Arrays;
import org.apache.poi.poifs.dev.TestPOIFSDump;
-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 TestTempFile {
private String previousTempDir;
private File tempDir;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
previousTempDir = System.getProperty(TempFile.JAVA_IO_TMPDIR);
if(previousTempDir != null) {
- assertTrue("Failed to create directory " + previousTempDir,
- new File(previousTempDir).exists() || new File(previousTempDir).mkdirs());
+ assertTrue(new File(previousTempDir).exists() || new File(previousTempDir).mkdirs(),
+ "Failed to create directory " + previousTempDir);
}
// use a separate tempdir for the tests to be able to check for leftover files
@@ -51,19 +51,19 @@ public class TestTempFile {
System.setProperty(TempFile.JAVA_IO_TMPDIR, tempDir.getAbsolutePath());
}
- @After
+ @AfterEach
public void tearDown() throws IOException {
if(tempDir != null) {
String[] files = tempDir.list();
assertNotNull(files);
// can have the "poifiles" subdir
if (files.length == 1) {
- assertEquals("Had: " + Arrays.toString(files), DefaultTempFileCreationStrategy.POIFILES, files[0]);
+ assertEquals(DefaultTempFileCreationStrategy.POIFILES, files[0], "Had: " + Arrays.toString(files));
files = new File(tempDir, files[0]).list();
assertNotNull(files);
- assertEquals("Had: " + Arrays.toString(files), 0, files.length);
+ assertEquals(0, files.length, "Had: " + Arrays.toString(files));
} else {
- assertEquals("Had: " + Arrays.toString(files), 0, files.length);
+ assertEquals(0, files.length, "Had: " + Arrays.toString(files));
}
// remove the directory after the tests
@@ -92,41 +92,35 @@ public class TestTempFile {
FileOutputStream fos = new FileOutputStream(tempFile);
fos.write(1); //file can be written to
fos.close();
- assertTrue("temp file exists", tempFile.exists());
- assertTrue("temp file is a file", tempFile.isFile());
- assertTrue("temp file's name should start with test",
- tempFile.getName().startsWith("test"));
- assertTrue("temp file's name should end with .txt",
- tempFile.getName().endsWith(".txt"));
- assertEquals("temp file is saved in poifiles directory",
- DefaultTempFileCreationStrategy.POIFILES, tempFile.getParentFile().getName());
+ assertTrue(tempFile.exists());
+ assertTrue(tempFile.isFile());
+ assertTrue(tempFile.getName().startsWith("test"));
+ assertTrue(tempFile.getName().endsWith(".txt"));
+ assertEquals(DefaultTempFileCreationStrategy.POIFILES, tempFile.getParentFile().getName());
// Can't think of a good way to check whether a file is actually deleted since it would require the VM to stop.
// Solution: set TempFileCreationStrategy to something that the unit test can trigger a deletion"
- assertTrue("Unable to delete temp file", tempFile.delete());
+ assertTrue(tempFile.delete());
}
@Test
public void createTempFileWithDefaultSuffix() throws IOException {
File tempFile = TempFile.createTempFile("test", null);
- assertTrue("temp file's name should end with .tmp",
- tempFile.getName().endsWith(".tmp"));
+ assertTrue(tempFile.getName().endsWith(".tmp"));
}
@Test
public void testCreateTempDirectory() throws IOException
{
File tempDir = TempFile.createTempDirectory("testDir");
- assertTrue("testDir exists", tempDir.exists());
- assertTrue("testDir is a directory", tempDir.isDirectory());
- assertTrue("testDir's name starts with testDir",
- tempDir.getName().startsWith("testDir"));
- assertEquals("tempDir is saved in poifiles directory",
- DefaultTempFileCreationStrategy.POIFILES, tempDir.getParentFile().getName());
+ assertTrue(tempDir.exists());
+ assertTrue(tempDir.isDirectory());
+ assertTrue(tempDir.getName().startsWith("testDir"));
+ assertEquals(DefaultTempFileCreationStrategy.POIFILES, tempDir.getParentFile().getName());
// Can't think of a good way to check whether a directory is actually deleted since it would require the VM to stop.
// Solution: set TempFileCreationStrategy to something that the unit test can trigger a deletion"
- assertTrue("Unable to delete tempDir", tempDir.delete());
+ assertTrue(tempDir.delete());
}
@Test
diff --git a/src/testcases/org/apache/poi/util/TestXMLHelper.java b/src/testcases/org/apache/poi/util/TestXMLHelper.java
index 5536168545..478ba0dbe0 100644
--- a/src/testcases/org/apache/poi/util/TestXMLHelper.java
+++ b/src/testcases/org/apache/poi/util/TestXMLHelper.java
@@ -17,11 +17,11 @@
package org.apache.poi.util;
-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.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.assertTrue;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
@@ -36,7 +36,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.xml.sax.InputSource;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.XMLReader;
@@ -121,9 +121,9 @@ public class TestXMLHelper {
assertTrue(reader.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
} catch (SAXNotRecognizedException e) {
// can happen for older XML Parsers, e.g. we have a CI Job which runs with Xerces XML Parser
- assertTrue("Had Exception about not-recognized SAX feature: " + e + " which is only expected" +
- " for Xerces XML Parser, but had parser: " + reader,
- reader.getClass().getName().contains("org.apache.xerces"));
+ assertTrue(reader.getClass().getName().contains("org.apache.xerces"),
+ "Had Exception about not-recognized SAX feature: " + e + " which is only expected" +
+ " for Xerces XML Parser, but had parser: " + reader);
}
readers.add(reader);
}