diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2020-12-24 18:42:29 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2020-12-24 18:42:29 +0000 |
commit | a0fa9e19b1196bc10034f15474d27ce23bf5865a (patch) | |
tree | 499c1eb427ebff72f7e447d13dd1de1552df8146 /src/ooxml/testcases/org/apache/poi/xwpf | |
parent | fb012041e8dd788637e68737199bc313b3e90098 (diff) | |
download | poi-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/ooxml/testcases/org/apache/poi/xwpf')
32 files changed, 289 insertions, 364 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/AllXWPFTests.java b/src/ooxml/testcases/org/apache/poi/xwpf/AllXWPFTests.java deleted file mode 100644 index 00683b6ce1..0000000000 --- a/src/ooxml/testcases/org/apache/poi/xwpf/AllXWPFTests.java +++ /dev/null @@ -1,58 +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.xwpf; - -import org.apache.poi.xwpf.extractor.TestXWPFWordExtractor; -import org.apache.poi.xwpf.model.TestXWPFHeaderFooterPolicy; -import org.apache.poi.xwpf.usermodel.TestXWPFChart; -import org.apache.poi.xwpf.usermodel.TestXWPFDocument; -import org.apache.poi.xwpf.usermodel.TestXWPFHeader; -import org.apache.poi.xwpf.usermodel.TestXWPFHeadings; -import org.apache.poi.xwpf.usermodel.TestXWPFNumbering; -import org.apache.poi.xwpf.usermodel.TestXWPFParagraph; -import org.apache.poi.xwpf.usermodel.TestXWPFPictureData; -import org.apache.poi.xwpf.usermodel.TestXWPFRun; -import org.apache.poi.xwpf.usermodel.TestXWPFStyles; -import org.apache.poi.xwpf.usermodel.TestXWPFTable; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * Collects all tests for <tt>org.apache.poi.xwpf</tt> and sub-packages. - */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ - TestXWPFBugs.class, - org.apache.poi.xwpf.usermodel.TestXWPFBugs.class, - TestXWPFChart.class, - TestXWPFDocument.class, - TestXWPFWordExtractor.class, - TestXWPFHeaderFooterPolicy.class, - TestXWPFHeader.class, - TestXWPFHeadings.class, - TestXWPFParagraph.class, - TestXWPFRun.class, - TestXWPFTable.class, - TestXWPFStyles.class, - TestXWPFPictureData.class, - TestXWPFNumbering.class, - TestAllExtendedProperties.class, - TestPackageCorePropertiesGetKeywords.class -}) -public final class AllXWPFTests { -} diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestAllExtendedProperties.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestAllExtendedProperties.java index 6c2b7ae483..f243092bf5 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestAllExtendedProperties.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestAllExtendedProperties.java @@ -17,23 +17,23 @@ package org.apache.poi.xwpf; +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; + import org.apache.poi.ooxml.POIXMLProperties.CoreProperties; import org.apache.poi.openxml4j.opc.PackageProperties; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTDigSigBlob; import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties; import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTVectorLpstr; import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTVectorVariant; -import java.io.IOException; - -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; - /** * Tests if the {@link CoreProperties#getKeywords()} method. This test has been * submitted because even though the diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java index 550a0c18ca..082f398c71 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java @@ -16,9 +16,9 @@ ==================================================================== */ package org.apache.poi.xwpf; -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.File; import java.io.FileInputStream; @@ -31,7 +31,7 @@ import org.apache.poi.util.TempFile; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFRun; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestDocumentProtection { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestNecessaryOOXMLClasses.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestNecessaryOOXMLClasses.java index 15b47927f3..93db6ce94f 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestNecessaryOOXMLClasses.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestNecessaryOOXMLClasses.java @@ -17,8 +17,10 @@ package org.apache.poi.xwpf; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEm; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblLayoutType; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STEm; @@ -30,13 +32,13 @@ public class TestNecessaryOOXMLClasses { @Test public void testProblemClasses() { CTTblLayoutType ctTblLayoutType = CTTblLayoutType.Factory.newInstance(); - Assert.assertNotNull(ctTblLayoutType); + assertNotNull(ctTblLayoutType); STTblLayoutType stTblLayoutType = STTblLayoutType.Factory.newInstance(); - Assert.assertNotNull(stTblLayoutType); + assertNotNull(stTblLayoutType); CTEm ctEm = CTEm.Factory.newInstance(); - Assert.assertNotNull(ctEm); + assertNotNull(ctEm); STEm stEm = STEm.Factory.newInstance(); - Assert.assertNotNull(stEm); - Assert.assertEquals(STEm.CIRCLE, STEm.Enum.forString("circle")); + assertNotNull(stEm); + assertEquals(STEm.CIRCLE, STEm.Enum.forString("circle")); } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java index 2295e9a5f3..bd669c39ec 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java @@ -17,14 +17,14 @@ package org.apache.poi.xwpf; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import org.apache.poi.ooxml.POIXMLProperties.CoreProperties; import org.apache.poi.openxml4j.opc.PackageProperties; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests if the {@link CoreProperties#getKeywords()} method. This test has been diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFBugs.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFBugs.java index 3e293a6268..cc4ac55215 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFBugs.java @@ -16,9 +16,10 @@ ==================================================================== */ package org.apache.poi.xwpf; -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 static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.File; import java.io.IOException; @@ -38,8 +39,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.xmlbeans.XmlException; -import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument; public class TestXWPFBugs { @@ -71,7 +71,7 @@ public class TestXWPFBugs { // Check it can be decoded Decryptor d = Decryptor.getInstance(info); - assertTrue("Unable to process: document is encrypted", d.verifyPassword("solrcell")); + assertTrue(d.verifyPassword("solrcell"), "Unable to process: document is encrypted"); // Check we can read the word document in that InputStream dataStream = d.getDataStream(filesystem); @@ -93,7 +93,7 @@ public class TestXWPFBugs { @Test public void bug53475_aes256() throws Exception { int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES"); - Assume.assumeTrue("Please install JCE Unlimited Strength Jurisdiction Policy files for AES 256", maxKeyLen == 2147483647); + assumeTrue(maxKeyLen == 0x7FFFFFFF, "Please install JCE Unlimited Strength Jurisdiction Policy files for AES 256"); File file = samples.getFile("bug53475-password-is-pass.docx"); POIFSFileSystem filesystem = new POIFSFileSystem(file, true); @@ -107,7 +107,7 @@ public class TestXWPFBugs { // Check it can be decoded Decryptor d = Decryptor.getInstance(info); - assertTrue("Unable to process: document is encrypted", d.verifyPassword("pass")); + assertTrue(d.verifyPassword("pass"), "Unable to process: document is encrypted"); // Check we can read the word document in that InputStream dataStream = d.getDataStream(filesystem); @@ -123,7 +123,7 @@ public class TestXWPFBugs { filesystem.close(); } - + @Test public void bug59058() throws IOException, XmlException { String[] files = {"bug57031.docx", "bug59058.docx"}; diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestExternalEntities.java b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestExternalEntities.java index 6f74f01ed1..b0748455c4 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestExternalEntities.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestExternalEntities.java @@ -17,14 +17,14 @@ package org.apache.poi.xwpf.extractor; -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 org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestExternalEntities { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java index 2ba870aed7..7975271d9d 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java @@ -21,9 +21,9 @@ import static org.apache.poi.POITestCase.assertContains; import static org.apache.poi.POITestCase.assertEndsWith; import static org.apache.poi.POITestCase.assertNotContained; import static org.apache.poi.POITestCase.assertStartsWith; -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; import java.util.Locale; @@ -33,7 +33,7 @@ import java.util.regex.Pattern; import org.apache.poi.util.StringUtil; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for HXFWordExtractor @@ -342,9 +342,9 @@ public class TestXWPFWordExtractor { hit = true; hits++; } - assertTrue("controlled content loading-" + targ, hit); + assertTrue(hit, "controlled content loading-" + targ); } - assertEquals("controlled content loading hit count", targs.length, hits); + assertEquals(targs.length, hits, "controlled content loading hit count"); } try (XWPFDocument doc2 = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx"); @@ -365,7 +365,7 @@ public class TestXWPFWordExtractor { while (m.find()) { hit++; } - assertEquals("controlled content loading-" + targ, 1, hit); + assertEquals(1, hit, "controlled content loading-" + targ); } //"test\n" appears twice: once as the "title" and once in the text. //This also happens when you save this document as text from MSWord. @@ -374,7 +374,7 @@ public class TestXWPFWordExtractor { while (m.find()) { hit++; } - assertEquals("test<N>", 2, hit); + assertEquals(2, hit, "test<N>"); } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFDecorators.java b/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFDecorators.java index 012b906b07..04271b14d7 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFDecorators.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFDecorators.java @@ -23,13 +23,13 @@ import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFHyperlinkRun; import org.apache.poi.xwpf.usermodel.XWPFParagraph; -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 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; /** * Tests for the various XWPF decorators @@ -39,14 +39,14 @@ public class TestXWPFDecorators { private XWPFDocument hyperlink; private XWPFDocument comments; - @Before + @BeforeEach public void setUp() throws IOException { simple = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"); hyperlink = XWPFTestDataSamples.openSampleDocument("TestDocument.docx"); comments = XWPFTestDataSamples.openSampleDocument("WordWithAttachments.docx"); } - @After + @AfterEach public void tearDown() throws IOException { simple.close(); hyperlink.close(); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java b/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java index bd057008f2..21dc6751f0 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java @@ -21,15 +21,15 @@ import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFFooter; import org.apache.poi.xwpf.usermodel.XWPFHeader; -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; -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; /** * Tests for XWPF Header Footer Stuff @@ -42,7 +42,7 @@ public class TestXWPFHeaderFooterPolicy { private XWPFDocument oddEven; private XWPFDocument diffFirst; - @Before + @BeforeEach public void setUp() throws IOException { noHeader = XWPFTestDataSamples.openSampleDocument("NoHeadFoot.docx"); header = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx"); @@ -52,7 +52,7 @@ public class TestXWPFHeaderFooterPolicy { diffFirst = XWPFTestDataSamples.openSampleDocument("DiffFirstPageHeadFoot.docx"); } - @After + @AfterEach public void tearDown() throws IOException { noHeader.close(); header.close(); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java index b43b9e6914..8abe0299d3 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java @@ -16,14 +16,14 @@ ==================================================================== */ package org.apache.poi.xwpf.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.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestChangeTracking { @Test diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java index 309e9e9738..3976e61310 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java @@ -16,11 +16,11 @@ ==================================================================== */ package org.apache.poi.xwpf.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.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -30,7 +30,7 @@ import java.math.BigInteger; import org.apache.poi.util.Units; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum; public class TestXWPFBugs { @@ -202,9 +202,9 @@ public class TestXWPFBugs { // we removed id "2", so this one should be empty, all others not if (i == 2) { - assertNull("Failed for " + i, abstractNum); + assertNull(abstractNum, "Failed for " + i); } else { - assertNotNull("Failed for " + i, abstractNum); + assertNotNull(abstractNum, "Failed for " + i); assertEquals(i, abstractNum.getAbstractNum().getAbstractNumId().longValue()); } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFChart.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFChart.java index 62c9670479..be4c1af023 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFChart.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFChart.java @@ -24,7 +24,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.xddf.usermodel.chart.XDDFBarChartData; import org.apache.poi.xddf.usermodel.chart.XDDFChartData; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle; import org.openxmlformats.schemas.drawingml.x2006.chart.CTTx; @@ -32,8 +32,8 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph; -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; public class TestXWPFChart { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFComment.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFComment.java index 886d15c0a9..b720176a81 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFComment.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFComment.java @@ -17,11 +17,11 @@ package org.apache.poi.xwpf.usermodel; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestXWPFComment { @Test diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java index ed5c7ea32d..faf96df931 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java @@ -17,13 +17,14 @@ package org.apache.poi.xwpf.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.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.Assertions.fail; import java.io.IOException; import java.io.OutputStream; @@ -43,8 +44,8 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.xmlbeans.XmlCursor; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; public final class TestXWPFDocument { @@ -329,12 +330,7 @@ public final class TestXWPFDocument { assertTrue(allPackagePictures.contains(xwpfPictureData)); } - try { - allPictures.add(allPictures.get(0)); - fail("This list must be unmodifiable!"); - } catch (UnsupportedOperationException e) { - // all ok - } + assertThrows(UnsupportedOperationException.class, () -> allPictures.add(allPictures.get(0)), "This list must be unmodifiable!"); doc.getPackage().revert(); } @@ -348,12 +344,7 @@ public final class TestXWPFDocument { assertNotNull(allPackagePictures); assertEquals(5, allPackagePictures.size()); - try { - allPackagePictures.add(allPackagePictures.get(0)); - fail("This list must be unmodifiable!"); - } catch (UnsupportedOperationException e) { - // all ok - } + assertThrows(UnsupportedOperationException.class, () -> allPackagePictures.add(allPackagePictures.get(0)), "This list must be unmodifiable!"); doc.getPackage().revert(); } @@ -472,7 +463,7 @@ public final class TestXWPFDocument { } @Test - @Ignore("XWPF should be able to write to a new Stream when opened Read-Only") + @Disabled("XWPF should be able to write to a new Stream when opened Read-Only") public void testWriteFromReadOnlyOPC() throws Exception { OPCPackage opc = OPCPackage.open( POIDataSamples.getDocumentInstance().getFile("SampleDoc.docx"), diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnote.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnote.java index addfbcb6a9..e7f11fa3a1 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnote.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnote.java @@ -16,27 +16,27 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.math.BigInteger; import java.util.List; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; public class TestXWPFEndnote { - + private XWPFDocument docOut; private String p1Text; private String p2Text; private BigInteger endnoteId; private XWPFEndnote endnote; - @Before + @BeforeEach public void setUp() { docOut = new XWPFDocument(); p1Text = "First paragraph in footnote"; @@ -46,115 +46,112 @@ public class TestXWPFEndnote { // to XWPFEndnotes.createEndnote() so this tests // both creation of new XWPFEndnotes in document // and XWPFEndnotes.createEndnote(); - + // NOTE: Creating the endnote does not automatically // create a first paragraph. endnote = docOut.createEndnote(); endnoteId = endnote.getId(); - + } @Test public void testAddParagraphsToFootnote() throws IOException { - // Add a run to the first paragraph: - + // Add a run to the first paragraph: + XWPFParagraph p1 = endnote.createParagraph(); p1.createRun().setText(p1Text); - + // Create a second paragraph: - + XWPFParagraph p = endnote.createParagraph(); - assertNotNull("Paragraph is null", p); + assertNotNull(p, "Paragraph is null"); p.createRun().setText(p2Text); XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); - + XWPFEndnote testEndnote = docIn.getEndnoteByID(endnoteId.intValue()); assertNotNull(testEndnote); - + assertEquals(2, testEndnote.getParagraphs().size()); XWPFParagraph testP1 = testEndnote.getParagraphs().get(0); assertEquals(p1Text, testP1.getText()); XWPFParagraph testP2 = testEndnote.getParagraphs().get(1); - assertEquals(p2Text, testP2.getText()); - + assertEquals(p2Text, testP2.getText()); + // The first paragraph added using createParagraph() should // have the required footnote reference added to the first // run. - + // Verify that we have a footnote reference in the first paragraph and not // in the second paragraph. - + XWPFRun r1 = testP1.getRuns().get(0); assertNotNull(r1); - assertTrue("No endnote reference in testP1", r1.getCTR().getEndnoteRefList().size() > 0); - assertNotNull("No endnote reference in testP1", r1.getCTR().getEndnoteRefArray(0)); + assertTrue(r1.getCTR().getEndnoteRefList().size() > 0, "No endnote reference in testP1"); + assertNotNull(r1.getCTR().getEndnoteRefArray(0), "No endnote reference in testP1"); XWPFRun r2 = testP2.getRuns().get(0); - assertNotNull("Expected a run in testP2", r2); - assertEquals("Found an endnote reference in testP2", 0, r2.getCTR().getEndnoteRefList().size()); - + assertNotNull(r2, "Expected a run in testP2"); + assertEquals(0, r2.getCTR().getEndnoteRefList().size(), "Found an endnote reference in testP2"); + } - + @Test public void testAddTableToFootnote() throws IOException { XWPFTable table = endnote.createTable(); assertNotNull(table); - + XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); - + XWPFEndnote testFootnote = docIn.getEndnoteByID(endnoteId.intValue()); XWPFTable testTable = testFootnote.getTableArray(0); assertNotNull(testTable); - + table = endnote.createTable(2, 3); assertEquals(2, table.getNumberOfRows()); assertEquals(3, table.getRow(0).getTableCells().size()); - + // If the table is the first body element of the footnote then // a paragraph with the footnote reference should have been // added automatically. - - assertEquals("Expected 3 body elements", 3, endnote.getBodyElements().size()); + + assertEquals(3, endnote.getBodyElements().size(), "Expected 3 body elements"); IBodyElement testP1 = endnote.getBodyElements().get(0); - assertTrue("Expected a paragraph, got " + testP1.getClass().getSimpleName() , testP1 instanceof XWPFParagraph); + assertTrue(testP1 instanceof XWPFParagraph, "Expected a paragraph, got " + testP1.getClass().getSimpleName()); XWPFRun r1 = ((XWPFParagraph)testP1).getRuns().get(0); assertNotNull(r1); - assertTrue("No footnote reference in testP1", r1.getCTR().getEndnoteRefList().size() > 0); - assertNotNull("No footnote reference in testP1", r1.getCTR().getEndnoteRefArray(0)); + assertTrue(r1.getCTR().getEndnoteRefList().size() > 0, "No footnote reference in testP1"); + assertNotNull(r1.getCTR().getEndnoteRefArray(0), "No footnote reference in testP1"); } - + @Test public void testRemoveEndnote() { - // NOTE: XWPFDocument.removeEndnote() delegates directly to + // NOTE: XWPFDocument.removeEndnote() delegates directly to // XWPFEndnotes. docOut.createEndnote(); - assertEquals("Expected 2 endnotes", 2, docOut.getEndnotes().size()); - assertNotNull("Didn't get second endnote", docOut.getEndnotes().get(1)); + assertEquals(2, docOut.getEndnotes().size(), "Expected 2 endnotes"); + assertNotNull(docOut.getEndnotes().get(1), "Didn't get second endnote"); boolean result = docOut.removeEndnote(0); - assertTrue("Remove endnote did not return true", result); - assertEquals("Expected 1 endnote after removal", 1, docOut.getEndnotes().size()); + assertTrue(result, "Remove endnote did not return true"); + assertEquals(1, docOut.getEndnotes().size(), "Expected 1 endnote after removal"); } @Test public void testAddFootnoteRefToParagraph() { XWPFParagraph p = docOut.createParagraph(); List<XWPFRun> runs = p.getRuns(); - assertEquals("Expected no runs in new paragraph", 0, runs.size()); + assertEquals(0, runs.size(), "Expected no runs in new paragraph"); p.addFootnoteReference(endnote); XWPFRun run = p.getRuns().get(0); CTR ctr = run.getCTR(); - assertNotNull("Expected a run", run); + assertNotNull(run, "Expected a run"); List<CTFtnEdnRef> endnoteRefList = ctr.getEndnoteReferenceList(); assertNotNull(endnoteRefList); CTFtnEdnRef ref = endnoteRefList.get(0); assertNotNull(ref); - assertEquals("Endnote ID and reference ID did not match", endnote.getId(), ref.getId()); - - + assertEquals(endnote.getId(), ref.getId(), "Endnote ID and reference ID did not match"); } - } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnotes.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnotes.java index 2fda6ab44d..e0a17b0c6a 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnotes.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFEndnotes.java @@ -17,15 +17,15 @@ package org.apache.poi.xwpf.usermodel; -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.io.IOException; import java.math.BigInteger; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFtnEdn; public class TestXWPFEndnotes { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnote.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnote.java index 143a3ad2ad..23a6b22e82 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnote.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnote.java @@ -16,27 +16,27 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.math.BigInteger; import java.util.List; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; public class TestXWPFFootnote { - + private XWPFDocument docOut; private String p1Text; private String p2Text; private BigInteger footnoteId; private XWPFFootnote footnote; - @Before + @BeforeEach public void setUp() { docOut = new XWPFDocument(); p1Text = "First paragraph in footnote"; @@ -46,115 +46,114 @@ public class TestXWPFFootnote { // to XWPFFootnotes.createFootnote() so this tests // both creation of new XWPFFootnotes in document // and XWPFFootnotes.createFootnote(); - + // NOTE: Creating the footnote does not automatically // create a first paragraph. footnote = docOut.createFootnote(); footnoteId = footnote.getId(); - + } @Test public void testAddParagraphsToFootnote() throws IOException { - // Add a run to the first paragraph: - + // Add a run to the first paragraph: + XWPFParagraph p1 = footnote.createParagraph(); p1.createRun().setText(p1Text); - + // Create a second paragraph: - + XWPFParagraph p = footnote.createParagraph(); - assertNotNull("Paragraph is null", p); + assertNotNull(p, "Paragraph is null"); p.createRun().setText(p2Text); XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); - + XWPFFootnote testFootnote = docIn.getFootnoteByID(footnoteId.intValue()); assertNotNull(testFootnote); - + assertEquals(2, testFootnote.getParagraphs().size()); XWPFParagraph testP1 = testFootnote.getParagraphs().get(0); assertEquals(p1Text, testP1.getText()); XWPFParagraph testP2 = testFootnote.getParagraphs().get(1); - assertEquals(p2Text, testP2.getText()); - + assertEquals(p2Text, testP2.getText()); + // The first paragraph added using createParagraph() should // have the required footnote reference added to the first // run. - + // Verify that we have a footnote reference in the first paragraph and not // in the second paragraph. - + XWPFRun r1 = testP1.getRuns().get(0); assertNotNull(r1); - assertTrue("No footnote reference in testP1", r1.getCTR().getFootnoteRefList().size() > 0); - assertNotNull("No footnote reference in testP1", r1.getCTR().getFootnoteRefArray(0)); + assertTrue(r1.getCTR().getFootnoteRefList().size() > 0, "No footnote reference in testP1"); + assertNotNull(r1.getCTR().getFootnoteRefArray(0), "No footnote reference in testP1"); XWPFRun r2 = testP2.getRuns().get(0); - assertNotNull("Expected a run in testP2", r2); - assertEquals("Found a footnote reference in testP2", 0, r2.getCTR().getFootnoteRefList().size()); - + assertNotNull(r2, "Expected a run in testP2"); + assertEquals(0, r2.getCTR().getFootnoteRefList().size(), "Found a footnote reference in testP2"); + } - + @Test public void testAddTableToFootnote() throws IOException { XWPFTable table = footnote.createTable(); assertNotNull(table); - + XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); - + XWPFFootnote testFootnote = docIn.getFootnoteByID(footnoteId.intValue()); XWPFTable testTable = testFootnote.getTableArray(0); assertNotNull(testTable); - + table = footnote.createTable(2, 3); assertEquals(2, table.getNumberOfRows()); assertEquals(3, table.getRow(0).getTableCells().size()); - + // If the table is the first body element of the footnote then // a paragraph with the footnote reference should have been // added automatically. - - assertEquals("Expected 3 body elements", 3, footnote.getBodyElements().size()); + + assertEquals(3, footnote.getBodyElements().size(), "Expected 3 body elements"); IBodyElement testP1 = footnote.getBodyElements().get(0); - assertTrue("Expected a paragraph, got " + testP1.getClass().getSimpleName() , testP1 instanceof XWPFParagraph); + assertTrue(testP1 instanceof XWPFParagraph, "Expected a paragraph, got " + testP1.getClass().getSimpleName()); XWPFRun r1 = ((XWPFParagraph)testP1).getRuns().get(0); assertNotNull(r1); - assertTrue("No footnote reference in testP1", r1.getCTR().getFootnoteRefList().size() > 0); - assertNotNull("No footnote reference in testP1", r1.getCTR().getFootnoteRefArray(0)); - + assertTrue(r1.getCTR().getFootnoteRefList().size() > 0, "No footnote reference in testP1"); + assertNotNull(r1.getCTR().getFootnoteRefArray(0), "No footnote reference in testP1"); } - + @Test public void testRemoveFootnote() { - // NOTE: XWPFDocument.removeFootnote() delegates directly to + // NOTE: XWPFDocument.removeFootnote() delegates directly to // XWPFFootnotes. docOut.createFootnote(); - assertEquals("Expected 2 footnotes", 2, docOut.getFootnotes().size()); - assertNotNull("Didn't get second footnote", docOut.getFootnotes().get(1)); + assertEquals(2, docOut.getFootnotes().size(), "Expected 2 footnotes"); + assertNotNull(docOut.getFootnotes().get(1), "Didn't get second footnote"); boolean result = docOut.removeFootnote(0); - assertTrue("Remove footnote did not return true", result); - assertEquals("Expected 1 footnote after removal", 1, docOut.getFootnotes().size()); + assertTrue(result, "Remove footnote did not return true"); + assertEquals(1, docOut.getFootnotes().size(), "Expected 1 footnote after removal"); } @Test public void testAddFootnoteRefToParagraph() { XWPFParagraph p = docOut.createParagraph(); List<XWPFRun> runs = p.getRuns(); - assertEquals("Expected no runs in new paragraph", 0, runs.size()); + assertEquals(0, runs.size(), "Expected no runs in new paragraph"); p.addFootnoteReference(footnote); XWPFRun run = p.getRuns().get(0); CTR ctr = run.getCTR(); - assertNotNull("Expected a run", run); + assertNotNull(run, "Expected a run"); CTFtnEdnRef ref = ctr.getFootnoteReferenceList().get(0); assertNotNull(ref); // FIXME: Verify that the footnote reference is w:endnoteReference, not w:footnoteReference - assertEquals("Footnote ID and reference ID did not match", footnote.getId(), ref.getId()); - - - + assertEquals(footnote.getId(), ref.getId(), "Footnote ID and reference ID did not match"); + + + } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java index 1f496f2840..8a71e84d2b 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java @@ -22,12 +22,12 @@ import java.math.BigInteger; import java.util.List; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFtnEdn; -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; public class TestXWPFFootnotes { @Test @@ -81,7 +81,7 @@ public class TestXWPFFootnotes { } } } - assertEquals("Load footnotes once", 1, hits); + assertEquals(1, hits, "Load footnotes once"); } } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java index 29fa8ba142..6ec254f3ca 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java @@ -17,16 +17,16 @@ package org.apache.poi.xwpf.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; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; @@ -231,25 +231,25 @@ public final class TestXWPFHeader { } } - @Ignore + @Disabled @Test public void testAddPictureData() { // TODO } - @Ignore + @Disabled @Test public void testGetAllPictures() { // TODO } - @Ignore + @Disabled @Test public void testGetAllPackagePictures() { // TODO } - @Ignore + @Disabled @Test public void testGetPictureDataById() { // TODO diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java index b26360dc00..17e41b66cf 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java @@ -19,12 +19,12 @@ package org.apache.poi.xwpf.usermodel; import java.io.IOException; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock; -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; /** * @author Paolo Mottadelli diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java index 5b61a71cea..771c8fd80c 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java @@ -17,15 +17,15 @@ package org.apache.poi.xwpf.usermodel; -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.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.math.BigInteger; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl; diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java index d9985ab30f..a9f1c0a764 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java @@ -17,18 +17,18 @@ package org.apache.poi.xwpf.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.assertTrue; import java.io.IOException; import java.math.BigInteger; import java.util.List; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture; import org.openxmlformats.schemas.drawingml.x2006.picture.PicDocument; import org.openxmlformats.schemas.drawingml.x2006.picture.impl.PicDocumentImpl; @@ -771,7 +771,7 @@ public final class TestXWPFParagraph { str.append(par.getText()).append("\n"); } String s = str.toString(); - assertTrue("Having text: \n" + s + "\nTrimmed length: " + s.trim().length(), s.trim().length() > 0); + assertTrue(s.trim().length() > 0, "Having text: \n" + s + "\nTrimmed length: " + s.trim().length()); } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java index 570d153d88..02149a7e32 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java @@ -17,11 +17,12 @@ package org.apache.poi.xwpf.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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -32,8 +33,8 @@ import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.xssf.usermodel.XSSFRelation; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TestXWPFPictureData { @@ -127,9 +128,7 @@ public class TestXWPFPictureData { // Document shouldn't have any image relationships assertEquals(13, doc.getPackagePart().getRelationships().size()); for (PackageRelationship rel : doc.getPackagePart().getRelationships()) { - if (rel.getRelationshipType().equals(XSSFRelation.IMAGE_JPEG.getRelation())) { - fail("Shouldn't have JPEG yet"); - } + assertNotEquals(XSSFRelation.IMAGE_JPEG.getRelation(), rel.getRelationshipType(), "Shouldn't have JPEG yet"); } // Add the image @@ -145,12 +144,11 @@ public class TestXWPFPictureData { PackageRelationship jpegRel = null; for (PackageRelationship rel : doc.getPackagePart().getRelationships()) { if (rel.getRelationshipType().equals(XWPFRelation.IMAGE_JPEG.getRelation())) { - if (jpegRel != null) - fail("Found 2 jpegs!"); + assertNull(jpegRel, "Found 2 jpegs!"); jpegRel = rel; } } - assertNotNull("JPEG Relationship not found", jpegRel); + assertNotNull(jpegRel, "JPEG Relationship not found"); // Check the details assertNotNull(jpegRel); @@ -185,7 +183,7 @@ public class TestXWPFPictureData { .map(XWPFRun::getEmbeddedPictures) .flatMap(List::stream) .map(XWPFPicture::getPictureData) - .forEach(Assert::assertNull); + .forEach(Assertions::assertNull); } } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java index 3bb802e344..7ccc739613 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java @@ -16,11 +16,11 @@ ==================================================================== */ package org.apache.poi.xwpf.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.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -35,9 +35,9 @@ import org.apache.poi.util.Units; import org.apache.poi.wp.usermodel.HeaderFooterType; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; -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 org.openxmlformats.schemas.drawingml.x2006.main.CTBlip; import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties; import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture; @@ -64,7 +64,7 @@ public class TestXWPFRun { private IRunBody irb; private XWPFDocument doc; - @Before + @BeforeEach public void setUp() { doc = new XWPFDocument(); p = doc.createParagraph(); @@ -73,7 +73,7 @@ public class TestXWPFRun { this.ctRun = CTR.Factory.newInstance(); } - @After + @AfterEach public void tearDown() throws Exception { doc.close(); } @@ -788,7 +788,7 @@ public class TestXWPFRun { String styleId = "bolditalic"; run.setStyle(styleId); String candStyleId = run.getCTR().getRPr().getRStyleArray(0).getVal(); - assertNotNull("Expected to find a run style ID", candStyleId); + assertNotNull( candStyleId, "Expected to find a run style ID" ); assertEquals(styleId, candStyleId); assertEquals(styleId, run.getStyle()); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java index c1ca100be5..ed20affd16 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java @@ -18,15 +18,15 @@ package org.apache.poi.xwpf.usermodel; import static org.apache.poi.POITestCase.assertContains; -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.util.ArrayList; import java.util.List; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; public final class TestXWPFSDT { @@ -37,7 +37,7 @@ public final class TestXWPFSDT { public void testNestedSDTs() throws Exception { try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug64561.docx")) { XWPFAbstractSDT sdt = extractAllSDTs(doc).get(0); - assertEquals("extracted text", "Subject", sdt.getContent().getText()); + assertEquals("Subject", sdt.getContent().getText(), "extracted text"); } } @@ -58,10 +58,10 @@ public final class TestXWPFSDT { } } - assertEquals("controls size", 13, sdts.size()); + assertEquals(13, sdts.size(), "controls size"); - assertEquals("tag", "MyTag", tag); - assertEquals("title", "MyTitle", title); + assertEquals("MyTag", tag, "tag"); + assertEquals("MyTitle", title, "title"); } } @@ -86,11 +86,11 @@ public final class TestXWPFSDT { try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug54849.docx")) { List<XWPFAbstractSDT> sdts = extractAllSDTs(doc); - assertEquals("number of sdts", contents.length, sdts.size()); + assertEquals(contents.length, sdts.size(), "number of sdts"); for (int i = 0; i < contents.length; i++) { XWPFAbstractSDT sdt = sdts.get(i); - assertEquals(i + ": " + contents[i], contents[i], sdt.getContent().toString()); + assertEquals(contents[i], sdt.getContent().toString(), i + ": " + contents[i]); } } } @@ -100,7 +100,7 @@ public final class TestXWPFSDT { */ @Test public void testSDTAsCell() throws Exception { - //Bug54771a.docx and Bug54771b.docx test slightly + //Bug54771a.docx and Bug54771b.docx test slightly //different recursion patterns. Keep both! try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx")) { List<XWPFAbstractSDT> sdts = extractAllSDTs(doc); @@ -146,7 +146,7 @@ public final class TestXWPFSDT { for (int i = 0; i < sdts.size(); i++) { XWPFAbstractSDT sdt = sdts.get(i); - assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText()); + assertEquals(targs.get(i), sdt.getContent().getText()); } } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java index ba9eb30ed4..466cadae65 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java @@ -21,7 +21,7 @@ import static org.apache.poi.POITestCase.assertContains; import java.io.IOException; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for reading SmartTags from Word docx. diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java index 8794798802..49fb85ea2d 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java @@ -17,19 +17,19 @@ package org.apache.poi.xwpf.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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLatentStyles; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLsdException; @@ -214,18 +214,14 @@ public final class TestXWPFStyles { XWPFStyles styles = doc.getStyles(); // Styles exist in the test document in this order, EmptyCellLayoutStyle // is missing a StyleId - try { - assertNotNull(styles.getStyle("NoList")); - assertNull(styles.getStyle("EmptyCellLayoutStyle")); - assertNotNull(styles.getStyle("BalloonText")); - - // Bug 64600: styleExist throws NPE - assertTrue(styles.styleExist("NoList")); - assertFalse(styles.styleExist("EmptyCellLayoutStyle")); - assertTrue(styles.styleExist("BalloonText")); - } catch (NullPointerException e) { - fail(e.toString()); - } + assertNotNull(styles.getStyle("NoList")); + assertNull(styles.getStyle("EmptyCellLayoutStyle")); + assertNotNull(styles.getStyle("BalloonText")); + + // Bug 64600: styleExist throws NPE + assertTrue(styles.styleExist("NoList")); + assertFalse(styles.styleExist("EmptyCellLayoutStyle")); + assertTrue(styles.styleExist("BalloonText")); } } @@ -237,7 +233,7 @@ public final class TestXWPFStyles { String styleName = "Normal Table"; XWPFStyle style = styles.getStyleWithName(styleName); - assertNotNull("Expected to find style \"" + styleName + "\"", style); + assertNotNull(style, "Expected to find style \"" + styleName + "\""); assertEquals(styleName, style.getName()); } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java index 52f2404363..d057e120ae 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java @@ -16,9 +16,9 @@ ==================================================================== */ package org.apache.poi.xwpf.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; import java.math.BigInteger; @@ -26,7 +26,7 @@ import java.util.List; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; @@ -553,15 +553,15 @@ public class TestXWPFTable { // assert the table is empty List<XWPFTableRow> rows = table.getRows(); - assertEquals("Table has less rows than requested.", noRows, rows.size()); + assertEquals(noRows, rows.size(), "Table has less rows than requested."); for (XWPFTableRow xwpfRow : rows) { assertNotNull(xwpfRow); for (int i = 0; i < 7; i++) { XWPFTableCell xwpfCell = xwpfRow.getCell(i); assertNotNull(xwpfCell); - assertEquals("Empty cells should not have one paragraph.", 1, xwpfCell.getParagraphs().size()); + assertEquals(1, xwpfCell.getParagraphs().size(), "Empty cells should not have one paragraph."); xwpfCell = xwpfRow.getCell(i); - assertEquals("Calling 'getCell' must not modify cells content.", 1, xwpfCell.getParagraphs().size()); + assertEquals(1, xwpfCell.getParagraphs().size(), "Calling 'getCell' must not modify cells content."); } } doc.getPackage().revert(); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java index cc6434e841..93214b4759 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java @@ -19,12 +19,12 @@ package org.apache.poi.xwpf.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 org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFTableCell.XWPFVertAlign; @@ -132,7 +132,7 @@ public class TestXWPFTableCell { } // This is not a very useful test as written. It is not worth the execution time for a unit test - @Ignore + @Disabled @Test public void testCellVerticalAlignShouldNotThrowNPE() throws Exception { XWPFDocument docx = XWPFTestDataSamples.openSampleDocument("TestTableCellAlign.docx"); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java index 953a82e2fc..ee532e2631 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java @@ -17,15 +17,15 @@ package org.apache.poi.xwpf.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.xwpf.XWPFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHeightRule; public class TestXWPFTableRow { @@ -51,7 +51,7 @@ public class TestXWPFTableRow { // Assert the repeat header is false by default boolean isCantSplit = tr.isCantSplitRow(); assertFalse(isCantSplit); - + // Repeat the header tr.setCantSplitRow(true); isCantSplit = tr.isCantSplitRow(); @@ -61,7 +61,7 @@ public class TestXWPFTableRow { tr.setCantSplitRow(false); isCantSplit = tr.isCantSplitRow(); assertFalse(isCantSplit); - + doc.close(); } @@ -73,11 +73,11 @@ public class TestXWPFTableRow { // table has a single row by default; grab it XWPFTableRow tr = table.getRow(0); assertNotNull(tr); - + // Assert the repeat header is false by default boolean isRpt = tr.isRepeatHeader(); assertFalse(isRpt); - + // Repeat the header tr.setRepeatHeader(true); isRpt = tr.isRepeatHeader(); @@ -87,7 +87,7 @@ public class TestXWPFTableRow { tr.setRepeatHeader(false); isRpt = tr.isRepeatHeader(); assertFalse(isRpt); - + // If the third row is set to repeat, but not the second, // isRepeatHeader should report false because Word will // ignore it. @@ -95,10 +95,10 @@ public class TestXWPFTableRow { tr.setRepeatHeader(true); isRpt = tr.isRepeatHeader(); assertFalse(isRpt); - + doc.close(); } - + // Test that validates the table header value can be parsed from a document // generated in Word @Test @@ -119,8 +119,8 @@ public class TestXWPFTableRow { assertFalse(isRpt); } } - - + + // Test that validates the table header value can be parsed from a document // generated in Word @Test diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/XWPFAbstractNumTest.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/XWPFAbstractNumTest.java index c4d0aec45d..b2909782f0 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/XWPFAbstractNumTest.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/XWPFAbstractNumTest.java @@ -16,9 +16,9 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class XWPFAbstractNumTest { |