You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2020/12/24 18:42:38 UTC

svn commit: r1884783 [4/40] - in /poi: site/src/documentation/content/xdocs/ trunk/ trunk/sonar/ trunk/sonar/integration-test/ trunk/sonar/ooxml/ trunk/src/excelant/poi-ant-contrib/ trunk/src/excelant/testcases/org/apache/poi/ss/excelant/ trunk/src/exc...

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java Thu Dec 24 18:42:29 2020
@@ -22,13 +22,14 @@ import static org.apache.poi.openxml4j.O
 import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.getSampleFileName;
 import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.openSampleStream;
 import static org.apache.poi.openxml4j.opc.PackagingURIHelper.createPartName;
-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.assertThrows;
-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.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.BufferedInputStream;
 import java.io.ByteArrayInputStream;
@@ -70,12 +71,12 @@ import org.apache.poi.openxml4j.exceptio
 import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException;
 import org.apache.poi.openxml4j.exceptions.ODFNotOfficeXmlFileException;
 import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;
 import org.apache.poi.openxml4j.opc.internal.FileHelper;
 import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
 import org.apache.poi.openxml4j.opc.internal.ZipHelper;
 import org.apache.poi.openxml4j.util.ZipSecureFile;
+import org.apache.poi.sl.usermodel.SlideShow;
 import org.apache.poi.sl.usermodel.SlideShowFactory;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
@@ -88,10 +89,9 @@ import org.apache.poi.xssf.streaming.SXS
 import org.apache.poi.xssf.usermodel.XSSFRelation;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xwpf.usermodel.XWPFRelation;
-import org.apache.xmlbeans.XmlException;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.function.ThrowingRunnable;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.function.Executable;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -288,7 +288,7 @@ public final class TestPackage {
         for (int i = 0; i < nodeCount; i++) {
             Element element = (Element) nodeList.item(i);
             String value = element.getAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME);
-            assertTrue("Root target must not start with a leading slash ('/'): " + value, value.charAt(0) != '/');
+            assertTrue(value.charAt(0) != '/', "Root target must not start with a leading slash ('/'): " + value);
         }
 
     }
@@ -340,11 +340,7 @@ public final class TestPackage {
 		StreamHelper.saveXmlInStream(doc, corePart.getOutputStream());
 
 		// Save and close
-		try {
-			pkg.close();
-		} catch (IOException e) {
-			fail();
-		}
+		assertDoesNotThrow(pkg::close);
 
 		ZipFileAssert.assertEquals(expectedFile, targetFile);
 		assertTrue(targetFile.delete());
@@ -406,7 +402,7 @@ public final class TestPackage {
      * TODO: fix and enable
      */
     @Test
-	@Ignore
+	@Disabled
     public void removePartRecursive() throws IOException, InvalidFormatException, URISyntaxException {
 		String originalFile = getSampleFileName("TestPackageCommon.docx");
 		File targetFile = getOutputFile("TestPackageRemovePartRecursiveOUTPUT.docx");
@@ -519,12 +515,8 @@ public final class TestPackage {
         FileHelper.copyFile(origFile, tempFile);
 		try (OPCPackage p = OPCPackage.open(tempFile.toString(), PackageAccess.READ_WRITE)) {
 			// Save it to the same file - not allowed
-			try {
-				p.save(tempFile);
-				fail("You shouldn't be able to call save(File) to overwrite the current file");
-			} catch(InvalidOperationException e) {
-				// expected here
-			}
+			assertThrows(InvalidOperationException.class, () -> p.save(tempFile),
+				"You shouldn't be able to call save(File) to overwrite the current file");
 		}
         // Delete it
         assertTrue(tempFile.delete());
@@ -668,12 +660,12 @@ public final class TestPackage {
 
 	private void handleNonOOXML(String file, Class<? extends UnsupportedFileFormatException> exception, String... messageParts) throws IOException {
 		try (InputStream stream = xlsSamples.openResourceAsStream(file)) {
-			ThrowingRunnable[] trs = {
+			Executable[] trs = {
 				() -> OPCPackage.open(stream),
 				() -> OPCPackage.open(xlsSamples.getFile(file))
 			};
-			for (ThrowingRunnable tr : trs) {
-				Exception ex = assertThrows("Shouldn't be able to open "+file, exception, tr);
+			for (Executable tr : trs) {
+				Exception ex = assertThrows(exception, tr, "Shouldn't be able to open "+file);
 				Stream.of(messageParts).forEach(mp -> assertTrue(ex.getMessage().contains(mp)));
 			}
 		}
@@ -792,7 +784,7 @@ public final class TestPackage {
 		return false;
 	}
 
-	private void openXmlBombFile(String file) throws IOException, OpenXML4JException, XmlException {
+	private void openXmlBombFile(String file) throws IOException {
 		final double minInf = ZipSecureFile.getMinInflateRatio();
 		ZipSecureFile.setMinInflateRatio(0.002);
 		try (POITextExtractor extractor = ExtractorFactory.createExtractor(XSSFTestDataSamples.getSampleFile(file))) {
@@ -827,7 +819,7 @@ public final class TestPackage {
 	}
 
 	@Test
-	public void zipBombCheckSizesSizeTooBig() throws IOException, EncryptedDocumentException {
+	public void zipBombCheckSizesSizeTooBig() throws EncryptedDocumentException {
 		POIXMLException ex = assertThrows(
 			POIXMLException.class,
 			() -> getZipStatsAndConsume((max_size, min_ratio) -> {
@@ -896,10 +888,10 @@ public final class TestPackage {
     }
 
     // bug 60128
-    @Test(expected=NotOfficeXmlFileException.class)
-    public void testCorruptFile() throws InvalidFormatException {
+    @Test
+    public void testCorruptFile() {
         File file = getSampleFile("invalid.xlsx");
-        OPCPackage.open(file, PackageAccess.READ);
+        assertThrows(NotOfficeXmlFileException.class, () -> OPCPackage.open(file, PackageAccess.READ));
     }
 
 	private interface CountingStream {
@@ -944,16 +936,19 @@ public final class TestPackage {
 						break;
 				}
 			}
-			assertTrue("Core not found in " + p.getParts(), foundCoreProps);
-			assertFalse("Document should not be found in " + p.getParts(), foundDocument);
-			assertFalse("Theme1 should not found in " + p.getParts(), foundTheme1);
+			assertTrue(foundCoreProps, "Core not found in " + p.getParts());
+			assertFalse(foundDocument, "Document should not be found in " + p.getParts());
+			assertFalse(foundTheme1, "Theme1 should not found in " + p.getParts());
 		}
 	}
 
 	@Test
 	public void unparseableCentralDirectory() throws IOException {
 		File f = getSampleFile("at.pzp.www_uploads_media_PP_Scheinecker-jdk6error.pptx");
-		SlideShowFactory.create(f, null, true).close();
+		try (SlideShow<?,?> ppt = SlideShowFactory.create(f, null, true)) {
+			assertNotNull(ppt);
+			assertNotNull(ppt.getSlides().get(0));
+		}
 	}
 
 	@Test
@@ -967,15 +962,13 @@ public final class TestPackage {
 		}
 
 		// feed the corrupted zip file to OPCPackage
-		try {
-			OPCPackage.open(tmp, PackageAccess.READ);
-		} catch (Exception e) {
-			// expected: the zip file is invalid
-			// this test does not care if open() throws an exception or not.
-		}
+		// expected: the zip file is invalid
+		// this test does not care if open() throws an exception or not.
+		assertThrows(Exception.class, () -> OPCPackage.open(tmp, PackageAccess.READ));
+
 		// If the stream is not closed on exception, it will keep a file descriptor to tmp,
 		// and requests to the OS to delete the file will fail.
-		assertTrue("Can't delete tmp file", tmp.delete());
+		assertTrue(tmp.delete(), "Can't delete tmp file");
 	}
 
 	/**
@@ -984,30 +977,31 @@ public final class TestPackage {
 	 *  stream / file the broken file is being read from.
 	 * See bug #60128 for more
 	 */
-	@Test(expected = NotOfficeXmlFileException.class)
+	@Test
 	public void testTidyStreamOnInvalidFile1() throws Exception {
 		openInvalidFile("SampleSS.ods", false);
 	}
 
-	@Test(expected = NotOfficeXmlFileException.class)
+	@Test
 	public void testTidyStreamOnInvalidFile2() throws Exception {
 		openInvalidFile("SampleSS.ods", true);
 	}
 
-	@Test(expected = NotOfficeXmlFileException.class)
+	@Test
 	public void testTidyStreamOnInvalidFile3() throws Exception {
 		openInvalidFile("SampleSS.txt", false);
 	}
 
-	@Test(expected = NotOfficeXmlFileException.class)
+	@Test
 	public void testTidyStreamOnInvalidFile4() throws Exception {
 		openInvalidFile("SampleSS.txt", true);
 	}
 
-	@Test(expected = InvalidFormatException.class)
+	@Test
 	public void testBug62592() throws Exception {
-		InputStream is = openSampleStream("62592.thmx");
-		/*OPCPackage p =*/ OPCPackage.open(is);
+		try (InputStream is = openSampleStream("62592.thmx")) {
+			assertThrows(InvalidFormatException.class, () -> OPCPackage.open(is));
+		}
 	}
 
 	@Test
@@ -1049,20 +1043,23 @@ public final class TestPackage {
 
 
 
-	private static void openInvalidFile(final String name, final boolean useStream) throws IOException, InvalidFormatException {
-		ZipPackage pkgTest = null;
+	private static void openInvalidFile(final String name, final boolean useStream) throws IOException {
+		ZipPackage[] pkgTest = { null };
 		try (final InputStream is = (useStream) ? xlsSamples.openResourceAsStream(name) : null) {
-			try (final ZipPackage pkg = (useStream) ? new ZipPackage(is, PackageAccess.READ) : new ZipPackage(xlsSamples.getFile(name), PackageAccess.READ)) {
-				pkgTest = pkg;
-				assertNotNull(pkg.getZipArchive());
-				assertFalse(pkg.getZipArchive().isClosed());
-				pkg.getParts();
-				fail("Shouldn't work");
-			}
+			assertThrows(NotOfficeXmlFileException.class, () -> {
+				try (final ZipPackage pkg = (useStream)
+					? new ZipPackage(is, PackageAccess.READ)
+					: new ZipPackage(xlsSamples.getFile(name), PackageAccess.READ)) {
+					pkgTest[0] = pkg;
+					assertNotNull(pkg.getZipArchive());
+					assertFalse(pkg.getZipArchive().isClosed());
+					pkg.getParts();
+				}
+			});
 		} finally {
-			if (pkgTest != null) {
-				assertNotNull(pkgTest.getZipArchive());
-				assertTrue(pkgTest.getZipArchive().isClosed());
+			if (pkgTest[0] != null) {
+				assertNotNull(pkgTest[0].getZipArchive());
+				assertTrue(pkgTest[0].getZipArchive().isClosed());
 			}
 		}
 	}
@@ -1075,7 +1072,7 @@ public final class TestPackage {
 		Files.copy(testFile, tmpFile);
 
 		int numPartsBefore = 0;
-		String md5Before = Files.hash(tmpFile, Hashing.md5()).toString();
+		String md5Before = Files.asByteSource(tmpFile).hash(Hashing.sha256()).toString();
 
 		RuntimeException ex = null;
 		try(OPCPackage pkg = OPCPackage.open(tmpFile, PackageAccess.READ_WRITE))
@@ -1091,11 +1088,11 @@ public final class TestPackage {
 			ex = e;
 		}
 		// verify there was an exception while closing the file
-		assertNotNull("Fail to save: an error occurs while saving the package : Bugzilla 63029", ex);
+		assertNotNull(ex, "Fail to save: an error occurs while saving the package : Bugzilla 63029");
 		assertEquals("Fail to save: an error occurs while saving the package : Bugzilla 63029", ex.getMessage());
 
 		// assert that md5 after closing is the same, i.e. the source is left intact
-		String md5After = Files.hash(tmpFile, Hashing.md5()).toString();
+		String md5After = Files.asByteSource(tmpFile).hash(Hashing.sha256()).toString();
 		assertEquals(md5Before, md5After);
 
 		// try to read the source file once again

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java Thu Dec 24 18:42:29 2020
@@ -33,11 +33,11 @@ import org.apache.poi.openxml4j.exceptio
 import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty;
 
 import static org.apache.poi.openxml4j.opc.TestContentType.isOldXercesActive;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 public final class TestPackageCoreProperties {
 	/**
@@ -204,7 +204,7 @@ public final class TestPackageCoreProper
         props.setModifiedProperty(strDate);
         assertEquals(strDate, props.getModifiedPropertyString());
         assertEquals(date, props.getModifiedProperty().get());
-        
+
         // Tidy
         pkg.close();
     }
@@ -229,57 +229,55 @@ public final class TestPackageCoreProper
 
 	@Test
 	public void testEntitiesInCoreProps_56164() throws Exception {
-        InputStream is = OpenXML4JTestDataSamples.openSampleStream("CorePropertiesHasEntities.ooxml");
-        OPCPackage p = OPCPackage.open(is);
-        is.close();
+        try (InputStream is = OpenXML4JTestDataSamples.openSampleStream("CorePropertiesHasEntities.ooxml");
+        OPCPackage p = OPCPackage.open(is)) {
 
-        // Should have 3 root relationships
-        boolean foundDocRel = false, foundCorePropRel = false, foundExtPropRel = false;
-        for (PackageRelationship pr : p.getRelationships()) {
-            if (pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_DOCUMENT))
-                foundDocRel = true;
-            if (pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_PROPERTIES))
-                foundCorePropRel = true;
-            if (pr.getRelationshipType().equals(PackageRelationshipTypes.EXTENDED_PROPERTIES))
-                foundExtPropRel = true;
-        }
-        assertTrue("Core/Doc Relationship not found in " + p.getRelationships(), foundDocRel);
-        assertTrue("Core Props Relationship not found in " + p.getRelationships(), foundCorePropRel);
-        assertTrue("Ext Props Relationship not found in " + p.getRelationships(), foundExtPropRel);
-
-        // Get the Core Properties
-        PackagePropertiesPart props = (PackagePropertiesPart)p.getPackageProperties();
-        
-        // used to resolve a value but now we ignore DTD entities for security reasons
-        assertEquals(isOldXercesActive(), props.getCreatorProperty().isPresent());
+            // Should have 3 root relationships
+            boolean foundDocRel = false, foundCorePropRel = false, foundExtPropRel = false;
+            for (PackageRelationship pr : p.getRelationships()) {
+                if (pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_DOCUMENT))
+                    foundDocRel = true;
+                if (pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_PROPERTIES))
+                    foundCorePropRel = true;
+                if (pr.getRelationshipType().equals(PackageRelationshipTypes.EXTENDED_PROPERTIES))
+                    foundExtPropRel = true;
+            }
+            assertTrue(foundDocRel, "Core Doc Relationship not found in " + p.getRelationships());
+            assertTrue(foundCorePropRel, "Core Props Relationship not found in " + p.getRelationships());
+            assertTrue(foundExtPropRel, "Ext Props Relationship not found in " + p.getRelationships());
 
-        p.close();
+            // Get the Core Properties
+            PackagePropertiesPart props = (PackagePropertiesPart) p.getPackageProperties();
+
+            // used to resolve a value but now we ignore DTD entities for security reasons
+            assertEquals(isOldXercesActive(), props.getCreatorProperty().isPresent());
+        }
     }
-    
+
 	@Test
 	public void testListOfCustomProperties() throws Exception {
         File inp = POIDataSamples.getSpreadSheetInstance().getFile("ExcelWithAttachments.xlsm");
         OPCPackage pkg = OPCPackage.open(inp, PackageAccess.READ);
         XSSFWorkbook wb = new XSSFWorkbook(pkg);
-        
+
         assertNotNull(wb.getProperties());
         assertNotNull(wb.getProperties().getCustomProperties());
-        
+
         for (CTProperty prop : wb.getProperties().getCustomProperties().getUnderlyingProperties().getPropertyList()) {
             assertNotNull(prop);
         }
-        
+
         wb.close();
         pkg.close();
     }
-	
+
 	@Test
 	public void testAlternateCorePropertyTimezones() throws Exception {
         InputStream is = OpenXML4JTestDataSamples.openSampleStream("OPCCompliance_CoreProperties_AlternateTimezones.docx");
         OPCPackage pkg = OPCPackage.open(is);
         PackagePropertiesPart props = (PackagePropertiesPart)pkg.getPackageProperties();
         is.close();
-        
+
         // We need predictable dates for testing!
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ROOT);
         df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
@@ -287,37 +285,37 @@ public final class TestPackageCoreProper
         // Check text properties first
         assertEquals("Lorem Ipsum", props.getTitleProperty().get());
         assertEquals("Apache POI", props.getCreatorProperty().get());
-        
+
         // Created at has a +3 timezone and milliseconds
         //   2006-10-13T18:06:00.123+03:00
         // = 2006-10-13T15:06:00.123+00:00
         assertEquals("2006-10-13T15:06:00Z", props.getCreatedPropertyString());
         assertEquals("2006-10-13T15:06:00.123Z", df.format(props.getCreatedProperty().get()));
-        
+
         // Modified at has a -13 timezone but no milliseconds
         //   2007-06-20T07:59:00-13:00
         // = 2007-06-20T20:59:00-13:00
         assertEquals("2007-06-20T20:59:00Z", props.getModifiedPropertyString());
         assertEquals("2007-06-20T20:59:00.000Z", df.format(props.getModifiedProperty().get()));
-        
-        
+
+
         // Ensure we can change them with other timezones and still read back OK
         props.setCreatedProperty("2007-06-20T20:57:00+13:00");
         props.setModifiedProperty("2007-06-20T20:59:00.123-13:00");
-        
+
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         pkg.save(baos);
         pkg = OPCPackage.open(new ByteArrayInputStream(baos.toByteArray()));
-        
+
         // Check text properties first - should be unchanged
         assertEquals("Lorem Ipsum", props.getTitleProperty().get());
         assertEquals("Apache POI", props.getCreatorProperty().get());
-        
+
         // Check the updated times
         //   2007-06-20T20:57:00+13:00
         // = 2007-06-20T07:57:00Z
         assertEquals("2007-06-20T07:57:00.000Z", df.format(props.getCreatedProperty().get()));
-        
+
         //   2007-06-20T20:59:00.123-13:00
         // = 2007-06-21T09:59:00.123Z
         assertEquals("2007-06-21T09:59:00.123Z", df.format(props.getModifiedProperty().get()));

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagePartName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagePartName.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagePartName.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagePartName.java Thu Dec 24 18:42:29 2020
@@ -17,9 +17,9 @@
 
 package org.apache.poi.openxml4j.opc;
 
-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 TestPackagePartName {
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java Thu Dec 24 18:42:29 2020
@@ -17,13 +17,14 @@
 
 package org.apache.poi.openxml4j.opc;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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.io.File;
 
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 /**
  * Test the addition of thumbnail in a package.
@@ -42,25 +43,19 @@ public final class TestPackageThumbnail
 		File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageThumbnailOUTPUT.docx");
 
 		// Open package
-		OPCPackage p = OPCPackage.open(inputPath, PackageAccess.READ_WRITE);
-		try {
+		try (OPCPackage p = OPCPackage.open(inputPath, PackageAccess.READ_WRITE)) {
     		p.addThumbnail(imagePath);
     		// Save the package in the output directory
     		p.save(outputFile);
 
     		// Open the newly created file to check core properties saved values.
-    		OPCPackage p2 = OPCPackage.open(outputFile.getAbsolutePath(), PackageAccess.READ);
-    		try {
-        		if (p2.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL)
-        				.size() == 0)
-        			fail("Thumbnail not added to the package !");
-    		} finally {
-    		    p2.revert();
-    		    p2.close();
+    		try (OPCPackage p2 = OPCPackage.open(outputFile.getAbsolutePath(), PackageAccess.READ)) {
+    			assertNotEquals(0, p2.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL).size(),
+					"Thumbnail not added to the package !");
+				p2.revert();
     		}
-		} finally {
-		    p.revert();
-		    assertTrue(outputFile.delete());
+			p.revert();
 		}
+		assertTrue(outputFile.delete());
 	}
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java Thu Dec 24 18:42:29 2020
@@ -16,13 +16,13 @@
 ==================================================================== */
 package org.apache.poi.openxml4j.opc;
 
-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.net.URI;
 
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class TestPackagingURIHelper {
 
@@ -92,8 +92,7 @@ public class TestPackagingURIHelper {
         // Relative part name
         PackagePartName relativeName = PackagingURIHelper.createPartName(
                 "media/image1.gif", partBase);
-        assertEquals("The part name must be equal to "
-                + partNameToValid.getName(), partNameToValid, relativeName);
+        assertEquals(partNameToValid, relativeName, "The part name must be equal to " + partNameToValid.getName());
         pkg.revert();
     }
 
@@ -113,8 +112,7 @@ public class TestPackagingURIHelper {
         // Relative part name
         PackagePartName relativeName = PackagingURIHelper.createPartName(
                 new URI("media/image1.gif"), partBase);
-        assertEquals("The part name must be equal to "
-                + partNameToValid.getName(), partNameToValid, relativeName);
+        assertEquals(partNameToValid, relativeName, "The part name must be equal to " + partNameToValid.getName());
         pkg.revert();
     }
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java Thu Dec 24 18:42:29 2020
@@ -19,10 +19,10 @@ package org.apache.poi.openxml4j.opc;
 
 import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.openSampleStream;
 import static org.apache.poi.openxml4j.opc.TestContentType.isOldXercesActive;
-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.ByteArrayOutputStream;
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 
 public class TestRelationships {
@@ -66,7 +66,7 @@ public class TestRelationships {
                 assertNotNull(rel);
                 PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
                 PackagePart sheetPart = pkg.getPart(relName);
-                assertEquals("Number of relationships1 for " + sheetPart.getPartName(), 1, sheetPart.getRelationships().size());
+                assertEquals(1, sheetPart.getRelationships().size(), "Number of relationships1 for " + sheetPart.getPartName());
             }
         }
     }
@@ -430,16 +430,13 @@ public class TestRelationships {
             // Should have 3 root relationships
             boolean foundDocRel = false, foundCorePropRel = false, foundExtPropRel = false;
             for (PackageRelationship pr : p.getRelationships()) {
-                if (pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_DOCUMENT))
-                    foundDocRel = true;
-                if (pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_PROPERTIES))
-                    foundCorePropRel = true;
-                if (pr.getRelationshipType().equals(PackageRelationshipTypes.EXTENDED_PROPERTIES))
-                    foundExtPropRel = true;
+                foundDocRel |= pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_DOCUMENT);
+                foundCorePropRel |= pr.getRelationshipType().equals(PackageRelationshipTypes.CORE_PROPERTIES);
+                foundExtPropRel |= pr.getRelationshipType().equals(PackageRelationshipTypes.EXTENDED_PROPERTIES);
             }
-            assertEquals("Core/Doc Relationship not found in " + p.getRelationships(), isOldXercesActive(), foundDocRel);
-            assertEquals("Core Props Relationship not found in " + p.getRelationships(), isOldXercesActive(), foundCorePropRel);
-            assertEquals("Ext Props Relationship not found in " + p.getRelationships(), isOldXercesActive(), foundExtPropRel);
+            assertEquals(isOldXercesActive(), foundDocRel, "Core Doc Relationship not found in " + p.getRelationships());
+            assertEquals(isOldXercesActive(), foundCorePropRel, "Core Props Relationship not found in " + p.getRelationships());
+            assertEquals(isOldXercesActive(), foundExtPropRel, "Ext Props Relationship not found in " + p.getRelationships());
         }
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/ZipFileAssert.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/ZipFileAssert.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/ZipFileAssert.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/ZipFileAssert.java Thu Dec 24 18:42:29 2020
@@ -17,11 +17,12 @@
 
 package org.apache.poi.openxml4j.opc;
 
-import static org.junit.Assert.assertArrayEquals;
-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.assertDoesNotThrow;
+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.BufferedInputStream;
 import java.io.ByteArrayOutputStream;
@@ -34,7 +35,7 @@ import java.util.TreeMap;
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.poi.util.IOUtils;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
 import org.xmlunit.builder.DiffBuilder;
 import org.xmlunit.builder.Input;
 import org.xmlunit.diff.Comparison;
@@ -55,14 +56,14 @@ public final class ZipFileAssert {
             TreeMap<String, ByteArrayOutputStream> file1,
             TreeMap<String, ByteArrayOutputStream> file2) {
         Set<String> listFile1 = file1.keySet();
-        Assert.assertEquals("not the same number of files in zip:", listFile1.size(), file2.keySet().size());
+        Assertions.assertEquals(listFile1.size(), file2.keySet().size(), "not the same number of files in zip:");
 
         for (String fileName : listFile1) {
             // extract the contents for both
             ByteArrayOutputStream contain1 = file1.get(fileName);
             ByteArrayOutputStream contain2 = file2.get(fileName);
 
-            assertNotNull(fileName + " not found in 2nd zip", contain2);
+            assertNotNull(contain2, fileName + " not found in 2nd zip");
             // no need to check for contain1. The key come from it
 
             if (fileName.matches(".*\\.(xml|rels)$")) {
@@ -75,11 +76,11 @@ public final class ZipFileAssert {
                         withDifferenceEvaluator(new IgnoreXMLDeclEvaluator()).
                         withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndAllAttributes, ElementSelectors.byNameAndText)).
                         build();
-                assertFalse(fileName+": "+diff.toString(), diff.hasDifferences());
+                assertFalse(diff.hasDifferences(), fileName+": "+diff.toString());
             } else {
                 // not xml, may be an image or other binary format
-                Assert.assertEquals(fileName + " does not have the same size in both zip:", contain1.size(), contain2.size());
-                assertArrayEquals("contents differ", contain1.toByteArray(), contain2.toByteArray());
+                Assertions.assertEquals(contain1.size(), contain2.size(), fileName + " does not have the same size in both zip:");
+                assertArrayEquals(contain1.toByteArray(), contain2.toByteArray(), "contents differ");
             }
         }
     }
@@ -126,21 +127,12 @@ public final class ZipFileAssert {
         assertNotNull(expected);
         assertNotNull(actual);
 
-        assertTrue("File does not exist [" + expected.getAbsolutePath()
-                + "]", expected.exists());
-        assertTrue("File does not exist [" + actual.getAbsolutePath()
-                + "]", actual.exists());
-
-        assertTrue("Expected file not readable", expected.canRead());
-        assertTrue("Actual file not readable", actual.canRead());
-
-        try {
-            TreeMap<String, ByteArrayOutputStream> file1 = decompress(expected);
-            TreeMap<String, ByteArrayOutputStream> file2 = decompress(actual);
-            equals(file1, file2);
-        } catch (IOException e) {
-            fail(e.toString());
-        }
+        assertTrue(expected.exists(), "File does not exist [" + expected.getAbsolutePath() + "]");
+        assertTrue(actual.exists(), "File does not exist [" + actual.getAbsolutePath() + "]");
+        assertTrue(expected.canRead(), "Expected file not readable");
+        assertTrue(actual.canRead(), "Actual file not readable");
+
+        assertDoesNotThrow(() -> equals(decompress(expected), decompress(actual)));
     }
 
     private static class IgnoreXMLDeclEvaluator implements DifferenceEvaluator {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java Thu Dec 24 18:42:29 2020
@@ -19,11 +19,12 @@ package org.apache.poi.openxml4j.opc.com
 
 import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.openComplianceSampleStream;
 import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.openSampleStream;
-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.assertDoesNotThrow;
+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;
@@ -44,7 +45,7 @@ import org.apache.poi.openxml4j.opc.Pack
 import org.apache.poi.openxml4j.opc.TargetMode;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.TempFile;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 /**
  * Test core properties Open Packaging Convention compliance.
@@ -90,20 +91,12 @@ public final class TestOPCComplianceCore
         pkg.revert();
     }
 
-    private static String extractInvalidFormatMessage(String sampleNameSuffix) {
-        InputStream is = openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
-        OPCPackage pkg;
-        try {
-            pkg = OPCPackage.open(is);
-        } catch (InvalidFormatException e) {
-            // no longer required for successful test
+    private static String extractInvalidFormatMessage(String sampleNameSuffix) throws IOException {
+        try (InputStream is = openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix)) {
+            InvalidFormatException e = assertThrows(InvalidFormatException.class,
+                () -> OPCPackage.open(is).revert(), "expected OPC compliance exception was not thrown");
             return e.getMessage();
-        } catch (IOException e) {
-            throw new RuntimeException(e);
         }
-        pkg.revert();
-        fail("expected OPC compliance exception was not thrown");
-        return null;
     }
 
     /**
@@ -112,12 +105,12 @@ public final class TestOPCComplianceCore
     @Test
     public void testOnlyOneCorePropertiesPart() throws Exception {
        // We have relaxed this check, so we can read the file anyway
-        try (InputStream is = openSampleStream("OPCCompliance_CoreProperties_" + "OnlyOneCorePropertiesPartFAIL.docx");
-             OPCPackage pkg = OPCPackage.open(is)) {
-            assertNotNull(pkg);
-        } catch (Exception e) {
-            fail("M4.1 should be being relaxed");
-        }
+        assertDoesNotThrow(() -> {
+            try (InputStream is = openSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPartFAIL.docx");
+                 OPCPackage pkg = OPCPackage.open(is)) {
+                assertNotNull(pkg);
+            }
+        }, "M4.1 should be being relaxed");
 
        // We will use the first core properties, and ignore the others
 
@@ -148,55 +141,41 @@ public final class TestOPCComplianceCore
      * Test M4.1 rule.
      */
     @Test
-    public void testOnlyOneCorePropertiesPart_AddRelationship() {
-        InputStream is = openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
-        OPCPackage pkg;
-        try {
-            pkg = OPCPackage.open(is);
-        } catch (InvalidFormatException | IOException e) {
-            throw new RuntimeException(e);
-        }
-        URI partUri = createURI("/docProps/core2.xml");
-        try {
-            pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL,
-                    PackageRelationshipTypes.CORE_PROPERTIES);
-            // no longer fail on compliance error
-            //fail("expected OPC compliance exception was not thrown");
-        } catch (InvalidFormatException e) {
-            throw new RuntimeException(e);
-        } catch (InvalidOperationException e) {
-            // expected during successful test
+    public void testOnlyOneCorePropertiesPart_AddRelationship() throws IOException, InvalidFormatException {
+        try (InputStream is = openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx")) {
+            OPCPackage pkg = OPCPackage.open(is);
+            URI partUri = createURI("/docProps/core2.xml");
+            InvalidOperationException e = assertThrows(InvalidOperationException.class, () ->
+                    pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL, PackageRelationshipTypes.CORE_PROPERTIES),
+                "expected OPC compliance exception was not thrown"
+            );
             assertEquals("OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.", e.getMessage());
+            pkg.revert();
         }
-        pkg.revert();
     }
 
     /**
      * Test M4.1 rule.
      */
     @Test
-    public void testOnlyOneCorePropertiesPart_AddPart() throws InvalidFormatException {
+    public void testOnlyOneCorePropertiesPart_AddPart() throws InvalidFormatException, IOException {
         String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx";
-        OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
+        try (OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath())) {
 
-        URI partUri = createURI("/docProps/core2.xml");
-        try {
-            pkg.createPart(PackagingURIHelper.createPartName(partUri),
-                    ContentTypes.CORE_PROPERTIES_PART);
-            // no longer fail on compliance error
-            //fail("expected OPC compliance exception was not thrown");
-        } catch (InvalidOperationException e) {
-            // expected during successful test
+            URI partUri = createURI("/docProps/core2.xml");
+            InvalidOperationException e = assertThrows(InvalidOperationException.class, () ->
+                    pkg.createPart(PackagingURIHelper.createPartName(partUri), ContentTypes.CORE_PROPERTIES_PART),
+                "expected OPC compliance exception was not thrown");
             assertEquals("OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !", e.getMessage());
+            pkg.revert();
         }
-        pkg.revert();
     }
 
     /**
      * Test M4.2 rule.
      */
     @Test
-    public void testDoNotUseCompatibilityMarkup() {
+    public void testDoNotUseCompatibilityMarkup() throws IOException {
         String msg = extractInvalidFormatMessage("DoNotUseCompatibilityMarkupFAIL.docx");
         assertEquals("OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.", msg);
     }
@@ -205,7 +184,7 @@ public final class TestOPCComplianceCore
      * Test M4.3 rule.
      */
     @Test
-    public void testDCTermsNamespaceLimitedUse() {
+    public void testDCTermsNamespaceLimitedUse() throws IOException {
         String msg = extractInvalidFormatMessage("DCTermsNamespaceLimitedUseFAIL.docx");
         assertEquals("OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.", msg);
     }
@@ -214,7 +193,7 @@ public final class TestOPCComplianceCore
      * Test M4.4 rule.
      */
     @Test
-    public void testUnauthorizedXMLLangAttribute() {
+    public void testUnauthorizedXMLLangAttribute() throws IOException {
         String msg = extractInvalidFormatMessage("UnauthorizedXMLLangAttributeFAIL.docx");
         assertEquals("OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.", msg);
     }
@@ -223,7 +202,7 @@ public final class TestOPCComplianceCore
      * Test M4.5 rule.
      */
     @Test
-    public void testLimitedXSITypeAttribute_NotPresent() {
+    public void testLimitedXSITypeAttribute_NotPresent() throws IOException {
         String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_NotPresentFAIL.docx");
         assertEquals("The element 'created' must have the 'xsi:type' attribute present !", msg);
     }
@@ -232,7 +211,7 @@ public final class TestOPCComplianceCore
      * Test M4.5 rule.
      */
     @Test
-    public void testLimitedXSITypeAttribute_PresentWithUnauthorizedValue() {
+    public void testLimitedXSITypeAttribute_PresentWithUnauthorizedValue() throws IOException {
         String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_PresentWithUnauthorizedValueFAIL.docx");
         assertEquals("The element 'modified' must have the 'xsi:type' attribute with the value 'dcterms:W3CDTF', but had 'W3CDTF' !", msg);
     }
@@ -244,45 +223,43 @@ public final class TestOPCComplianceCore
     @Test
     public void testNoCoreProperties_saveNew() throws Exception {
         String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx";
-        OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
-
-        // Verify it has empty properties
-        assertEquals(0, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
-        assertNotNull(pkg.getPackageProperties());
-        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
-        assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent());
-
-        // Save and re-load
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        pkg.save(baos);
-        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-        pkg.revert();
 
-        pkg = OPCPackage.open(bais);
+        try (OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath())) {
+            // Verify it has empty properties
+            assertEquals(0, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+            assertNotNull(pkg.getPackageProperties());
+            assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+            assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent());
+
+            // Save and re-load
+            pkg.save(baos);
+            pkg.revert();
+        }
 
-        // An Empty Properties part has been added in the save/load
-        assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
-        assertNotNull(pkg.getPackageProperties());
-        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
-        assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent());
-        pkg.close();
+        try (OPCPackage pkg = OPCPackage.open(new ByteArrayInputStream(baos.toByteArray()))) {
+            // An Empty Properties part has been added in the save/load
+            assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+            assertNotNull(pkg.getPackageProperties());
+            assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+            assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent());
+        }
 
         // Open a new copy of it
-        pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
-
-        // Save and re-load, without having touched the properties yet
-        baos = new ByteArrayOutputStream();
-        pkg.save(baos);
-        pkg.revert();
-
-        bais = new ByteArrayInputStream(baos.toByteArray());
-        pkg = OPCPackage.open(bais);
+        try (OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath())) {
+            // Save and re-load, without having touched the properties yet
+            baos.reset();
+            pkg.save(baos);
+            pkg.revert();
+        }
 
-        // Check that this too added empty properties without error
-        assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
-        assertNotNull(pkg.getPackageProperties());
-        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
-        assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent());
+        try (OPCPackage pkg = OPCPackage.open(new ByteArrayInputStream(baos.toByteArray()))) {
+            // Check that this too added empty properties without error
+            assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+            assertNotNull(pkg.getPackageProperties());
+            assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+            assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent());
+        }
     }
 
     /**
@@ -295,37 +272,34 @@ public final class TestOPCComplianceCore
 
         // Copy this into a temp file, so we can play with it
         File tmp = TempFile.createTempFile("poi-test", ".opc");
-        FileOutputStream out = new FileOutputStream(tmp);
-        InputStream in = POIDataSamples.getOpenXML4JInstance().openResourceAsStream(sampleFileName);
-        IOUtils.copy(
-                in,
-                out);
-        out.close();
-        in.close();
+        try (FileOutputStream out = new FileOutputStream(tmp);
+            InputStream in = POIDataSamples.getOpenXML4JInstance().openResourceAsStream(sampleFileName)) {
+            IOUtils.copy(in, out);
+        }
 
         // Open it from that temp file
-        OPCPackage pkg = OPCPackage.open(tmp);
+        try (OPCPackage pkg = OPCPackage.open(tmp)) {
 
-        // Empty properties
-        assertEquals(0, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
-        assertNotNull(pkg.getPackageProperties());
-        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
-        assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent());
+            // Empty properties
+            assertEquals(0, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+            assertNotNull(pkg.getPackageProperties());
+            assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+            assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent());
 
-        // Save and close
-        pkg.close();
+            // Save and close
+        }
 
         // Re-open and check
-        pkg = OPCPackage.open(tmp);
-
-        // An Empty Properties part has been added in the save/load
-        assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
-        assertNotNull(pkg.getPackageProperties());
-        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
-        assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent());
+        try (OPCPackage pkg = OPCPackage.open(tmp)) {
+            // An Empty Properties part has been added in the save/load
+            assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+            assertNotNull(pkg.getPackageProperties());
+            assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+            assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent());
 
-        // Finish and tidy
-        pkg.revert();
+            // Finish and tidy
+            pkg.revert();
+        }
         assertTrue(tmp.delete());
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java Thu Dec 24 18:42:29 2020
@@ -17,8 +17,10 @@
 
 package org.apache.poi.openxml4j.opc.compliance;
 
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import java.io.File;
 import java.io.IOException;
 
 import org.apache.poi.POIDataSamples;
@@ -31,42 +33,50 @@ import org.apache.poi.openxml4j.opc.Pack
 import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
 import org.apache.poi.openxml4j.opc.TargetMode;
-import org.junit.Test;
+import org.apache.poi.util.TempFile;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 /**
  * Test Open Packaging Convention package model compliance.
  *
  * M1.11 : A package implementer shall neither create nor recognize a part with
  * a part name derived from another part name by appending segments to it.
- *
- * @author Julien Chable
  */
 public class TestOPCCompliancePackageModel {
 
+    private static File TESTFILE;
+
+    @BeforeAll
+    public static void setup() throws IOException {
+        TESTFILE = TempFile.createTempFile("TODELETEIFEXIST", ".docx");
+    }
+
+    @BeforeEach
+    public void tearDown() {
+        if (TESTFILE.exists()) {
+            assertTrue(TESTFILE.delete());
+        }
+    }
+
     /**
      * A package implementer shall neither create nor recognize a part with a
      * part name derived from another part name by appending segments to it.
      * [M1.11]
      */
     @Test
-    public void testPartNameDerivationAdditionFailure() {
-        OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx");
-        try {
-            PackagePartName name = PackagingURIHelper
-                    .createPartName("/word/document.xml");
-            PackagePartName nameDerived = PackagingURIHelper
-                    .createPartName("/word/document.xml/image1.gif");
+    public void testPartNameDerivationAdditionFailure() throws InvalidFormatException, IOException {
+        try (OPCPackage pkg = OPCPackage.create(TESTFILE)) {
+            PackagePartName name = PackagingURIHelper.createPartName("/word/document.xml");
+            PackagePartName nameDerived = PackagingURIHelper.createPartName("/word/document.xml/image1.gif");
             pkg.createPart(name, ContentTypes.XML);
-            pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF);
-        } catch (InvalidOperationException e) {
+
+            assertThrows(InvalidOperationException.class, () -> pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF),
+                "A package implementer shall neither create nor recognize a part with a part name derived from another " +
+                "part name by appending segments to it. [M1.11]");
             pkg.revert();
-            return;
-        } catch (InvalidFormatException e) {
-            fail(e.getMessage());
         }
-        fail("A package implementer shall neither create nor recognize a part with a"
-                + " part name derived from another part name by appending segments to it."
-                + " [M1.11]");
     }
 
     /**
@@ -75,16 +85,13 @@ public class TestOPCCompliancePackageMod
      * [M1.11]
      */
     @Test
-    public void testPartNameDerivationReadingFailure() throws IOException {
+    public void testPartNameDerivationReadingFailure() {
         String filename = "OPCCompliance_DerivedPartNameFAIL.docx";
-        try {
-            OPCPackage.open(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename));
-        } catch (InvalidFormatException e) {
-            return;
-        }
-        fail("A package implementer shall neither create nor recognize a part with a"
-                + " part name derived from another part name by appending segments to it."
-                + " [M1.11]");
+        assertThrows(InvalidFormatException.class, () ->
+            OPCPackage.open(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename)),
+            "A package implementer shall neither create nor recognize a part with a part name derived from another" +
+            " part name by appending segments to it. [M1.11]"
+        );
     }
 
     /**
@@ -94,22 +101,17 @@ public class TestOPCCompliancePackageMod
      */
     @Test
     public void testAddPackageAlreadyAddFailure() throws Exception {
-        OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
-        PackagePartName name1 = null;
-        PackagePartName name2 = null;
-        try {
-            name1 = PackagingURIHelper.createPartName("/word/document.xml");
-            name2 = PackagingURIHelper.createPartName("/word/document.xml");
-        } catch (InvalidFormatException e) {
-            throw new Exception(e.getMessage());
-        }
-        pkg.createPart(name1, ContentTypes.XML);
-        try {
-            pkg.createPart(name2, ContentTypes.XML);
-        } catch (PartAlreadyExistsException e) {
-            return;
+        try (OPCPackage pkg = OPCPackage.create(TESTFILE)) {
+            PackagePartName name1 = PackagingURIHelper.createPartName("/word/document.xml");
+            PackagePartName name2 = PackagingURIHelper.createPartName("/word/document.xml");
+
+            pkg.createPart(name1, ContentTypes.XML);
+            assertThrows(PartAlreadyExistsException.class, () -> pkg.createPart(name2, ContentTypes.XML),
+                "Packages shall not contain equivalent part names and package implementers shall neither create nor " +
+                    "recognize packages with equivalent part names. [M1.12]"
+            );
+            pkg.revert();
         }
-        fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
     }
 
     /**
@@ -119,20 +121,15 @@ public class TestOPCCompliancePackageMod
      */
     @Test
     public void testAddPackageAlreadyAddFailure2() throws Exception {
-        OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
-        PackagePartName partName = null;
-        try {
-            partName = PackagingURIHelper.createPartName("/word/document.xml");
-        } catch (InvalidFormatException e) {
-            throw new Exception(e.getMessage());
-        }
-        pkg.createPart(partName, ContentTypes.XML);
-        try {
+        try (OPCPackage pkg = OPCPackage.create(TESTFILE)) {
+            PackagePartName partName = PackagingURIHelper.createPartName("/word/document.xml");
             pkg.createPart(partName, ContentTypes.XML);
-        } catch (InvalidOperationException e) {
-            return;
+            assertThrows(InvalidOperationException.class, () -> pkg.createPart(partName, ContentTypes.XML),
+                "Packages shall not contain equivalent part names and package implementers shall neither create nor " +
+                    "recognize packages with equivalent part names. [M1.12]"
+            );
+            pkg.revert();
         }
-        fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
     }
 
     /**
@@ -144,22 +141,15 @@ public class TestOPCCompliancePackageMod
      * relationship as invalid.
      */
     @Test
-    public void testAddRelationshipRelationshipsPartFailure() {
-        OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
-        PackagePartName name1 = null;
-        try {
-            name1 = PackagingURIHelper
-                    .createPartName("/test/_rels/document.xml.rels");
-        } catch (InvalidFormatException e) {
-            fail("This exception should never happen !");
-        }
-
-        try {
-            pkg.addRelationship(name1, TargetMode.INTERNAL,
-                    PackageRelationshipTypes.CORE_DOCUMENT);
-        } catch (InvalidOperationException e) {
-            return;
+    public void testAddRelationshipRelationshipsPartFailure() throws IOException, InvalidFormatException {
+        try (OPCPackage pkg = OPCPackage.create(TESTFILE)) {
+            PackagePartName name1 = PackagingURIHelper.createPartName("/test/_rels/document.xml.rels");
+
+            assertThrows(InvalidOperationException.class,
+                () -> pkg.addRelationship(name1, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT),
+                "The Relationships part shall not have relationships to any other part [M1.25]"
+            );
+            pkg.revert();
         }
-        fail("Fail test -> M1.25: The Relationships part shall not have relationships to any other part");
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java Thu Dec 24 18:42:29 2020
@@ -17,19 +17,20 @@
 
 package org.apache.poi.openxml4j.opc.compliance;
 
-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.Assert.fail;
+import static org.apache.poi.openxml4j.opc.PackagingURIHelper.createPartName;
+import static org.apache.poi.openxml4j.opc.PackagingURIHelper.isValidPartName;
+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.net.URI;
 import java.net.URISyntaxException;
 
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.opc.PackagePartName;
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 /**
  * Test part name Open Packaging Convention compliance.
@@ -100,8 +101,7 @@ public final class TestOPCCompliancePart
                 assertEquals("[Content_Types].xml", s);
                 continue;
             }
-            assertFalse("This part name SHOULD NOT be valid: " + s,
-                    PackagingURIHelper.isValidPartName(uri));
+            assertFalse(isValidPartName(uri), "This part name SHOULD NOT be valid: " + s);
         }
     }
 
@@ -110,24 +110,19 @@ public final class TestOPCCompliancePart
      */
     @Test
     public void testValidPartNames() throws URISyntaxException {
-        String[] validNames = { "/xml/item1.xml", "/document.xml",
-                "/a/%D1%86.xml" };
-        for (String s : validNames)
-            assertTrue("This part name SHOULD be valid: " + s,
-                    PackagingURIHelper.isValidPartName(new URI(s)));
+        String[] validNames = { "/xml/item1.xml", "/document.xml", "/a/%D1%86.xml" };
+        for (String s : validNames) {
+            assertTrue(isValidPartName(new URI(s)), "This part name SHOULD be valid: " + s);
+        }
     }
 
     /**
      * A part name shall not be empty. [M1.1]
      */
     @Test
-    public void testEmptyPartNameFailure() throws URISyntaxException {
-        try {
-            PackagingURIHelper.createPartName(new URI(""));
-            fail("A part name shall not be empty. [M1.1]");
-        } catch (InvalidFormatException e) {
-            // Normal behaviour
-        }
+    public void testEmptyPartNameFailure() {
+        assertThrows(InvalidFormatException.class, () -> createPartName(new URI("")),
+            "A part name shall not be empty. [M1.1]");
     }
 
     /**
@@ -138,18 +133,13 @@ public final class TestOPCCompliancePart
      * A segment shall include at least one non-dot character. [M1.10]
      */
     @Test
-    public void testPartNameWithInvalidSegmentsFailure() {
+    public void testPartNameWithInvalidSegmentsFailure() throws URISyntaxException {
         String[] invalidNames = { "//document.xml", "//word/document.xml",
                 "/word//document.rels", "/word//rels//document.rels",
                 "/xml./doc.xml", "/document.", "/./document.xml",
                 "/word/./doc.rels", "/%2F/document.xml" };
-        try {
-            for (String s : invalidNames)
-                assertFalse(
-                        "A part name shall not have empty segments. [M1.3]",
-                        PackagingURIHelper.isValidPartName(new URI(s)));
-        } catch (URISyntaxException e) {
-            fail();
+        for (String s : invalidNames) {
+            assertFalse(isValidPartName(new URI(s)), "A part name shall not have empty segments. [M1.3]");
         }
     }
 
@@ -158,16 +148,11 @@ public final class TestOPCCompliancePart
      * [M1.6].
      */
     @Test
-    public void testPartNameWithNonPCharCharacters() {
+    public void testPartNameWithNonPCharCharacters() throws URISyntaxException {
         String[] validNames = { "/doc&.xml" };
-        try {
-            for (String s : validNames)
-                assertTrue(
-                        "A segment shall not contain non pchar characters [M1.6] : "
-                                + s, PackagingURIHelper
-                                .isValidPartName(new URI(s)));
-        } catch (URISyntaxException e) {
-            fail();
+        for (String s : validNames) {
+            assertTrue(isValidPartName(new URI(s)),
+                "A segment shall not contain non pchar characters [M1.6] : " + s);
         }
     }
 
@@ -175,16 +160,10 @@ public final class TestOPCCompliancePart
      * A segment shall not contain percent-encoded unreserved characters [M1.8].
      */
     @Test
-    public void testPartNameWithUnreservedEncodedCharactersFailure() {
+    public void testPartNameWithUnreservedEncodedCharactersFailure() throws URISyntaxException {
         String[] invalidNames = { "/a/docum%65nt.xml" };
-        try {
-            for (String s : invalidNames)
-                assertFalse(
-                        "A segment shall not contain percent-encoded unreserved characters [M1.8] : "
-                                + s, PackagingURIHelper
-                                .isValidPartName(new URI(s)));
-        } catch (URISyntaxException e) {
-            fail();
+        for (String s : invalidNames) {
+            assertFalse(isValidPartName(new URI(s)), "A segment shall not contain percent-encoded unreserved characters [M1.8] : " + s);
         }
     }
 
@@ -192,28 +171,18 @@ public final class TestOPCCompliancePart
      * A part name shall start with a forward slash ('/') character. [M1.4]
      */
     @Test
-    public void testPartNameStartsWithAForwardSlashFailure()
-            throws URISyntaxException {
-        try {
-            PackagingURIHelper.createPartName(new URI("document.xml"));
-            fail("A part name shall start with a forward slash ('/') character. [M1.4]");
-        } catch (InvalidFormatException e) {
-            // Normal behaviour
-        }
+    public void testPartNameStartsWithAForwardSlashFailure() {
+        assertThrows(InvalidFormatException.class, () -> createPartName(new URI("document.xml")),
+            "A part name shall start with a forward slash ('/') character. [M1.4]");
     }
 
     /**
      * A part name shall not have a forward slash as the last character. [M1.5]
      */
     @Test
-    public void testPartNameEndsWithAForwardSlashFailure()
-            throws URISyntaxException {
-        try {
-            PackagingURIHelper.createPartName(new URI("/document.xml/"));
-            fail("A part name shall not have a forward slash as the last character. [M1.5]");
-        } catch (InvalidFormatException e) {
-            // Normal behaviour
-        }
+    public void testPartNameEndsWithAForwardSlashFailure() {
+        assertThrows(InvalidFormatException.class, () -> createPartName(new URI("/document.xml/")),
+            "A part name shall not have a forward slash as the last character. [M1.5]");
     }
 
     /**
@@ -225,8 +194,8 @@ public final class TestOPCCompliancePart
         String[] partName1 = { "/word/document.xml", "/docProps/core.xml", "/rels/.rels" };
         String[] partName2 = { "/WORD/DocUment.XML", "/docProps/core.xml", "/rels/.rels" };
         for (int i = 0; i < partName1.length || i < partName2.length; ++i) {
-            PackagePartName p1 = PackagingURIHelper.createPartName(partName1[i]);
-            PackagePartName p2 = PackagingURIHelper.createPartName(partName2[i]);
+            PackagePartName p1 = createPartName(partName1[i]);
+            PackagePartName p2 = createPartName(partName2[i]);
             assertEquals(p1, p2);
             assertEquals(0, p1.compareTo(p2));
             assertEquals(p1.hashCode(), p2.hashCode());
@@ -244,8 +213,8 @@ public final class TestOPCCompliancePart
         String[] partName1 = { "/word/document.xml", "/docProps/core.xml", "/rels/.rels" };
         String[] partName2 = { "/WORD/DocUment.XML2", "/docProp/core.xml", "/rels/rels" };
         for (int i = 0; i < partName1.length || i < partName2.length; ++i) {
-            PackagePartName p1 = PackagingURIHelper.createPartName(partName1[i]);
-            PackagePartName p2 = PackagingURIHelper.createPartName(partName2[i]);
+            PackagePartName p1 = createPartName(partName1[i]);
+            PackagePartName p2 = createPartName(partName2[i]);
             assertNotEquals(p1, p2);
             assertNotEquals(0, p1.compareTo(p2));
             assertNotEquals(p1.hashCode(), p2.hashCode());

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java Thu Dec 24 18:42:29 2020
@@ -17,9 +17,8 @@
 
 package org.apache.poi.openxml4j.opc.internal;
 
-import static org.junit.Assert.assertEquals;
-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.assertNull;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -47,8 +46,8 @@ import org.apache.poi.xssf.usermodel.XSS
 import org.apache.poi.xssf.usermodel.XSSFShape;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
 
@@ -127,11 +126,10 @@ public final class TestContentTypeManage
     /**
      * Test the addition then removal of content types in a package.
      */
-    @Ignore
+    @Disabled
     @Test
     public void testContentTypeRemovalPackage() {
         // TODO
-        fail("test not written");
     }
 
     protected byte[] toByteArray(Workbook wb) {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/marshallers/TestZipPackagePropertiesMarshaller.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/marshallers/TestZipPackagePropertiesMarshaller.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/marshallers/TestZipPackagePropertiesMarshaller.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/marshallers/TestZipPackagePropertiesMarshaller.java Thu Dec 24 18:42:29 2020
@@ -18,7 +18,8 @@
 package org.apache.poi.openxml4j.opc.internal.marshallers;
 
 import static org.apache.poi.openxml4j.opc.PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_URI;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -27,40 +28,45 @@ import java.io.OutputStream;
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackagePartName;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
 import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
 import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class TestZipPackagePropertiesMarshaller {
-    private PartMarshaller marshaller = new ZipPackagePropertiesMarshaller();
+    private final PartMarshaller marshaller = new ZipPackagePropertiesMarshaller();
 
-    @Test(expected=IllegalArgumentException.class)
-    public void nonZipOutputStream() throws OpenXML4JException {
-        OutputStream notAZipOutputStream = new ByteArrayOutputStream(0);
-        marshaller.marshall(null, notAZipOutputStream);
+    private boolean marshall() throws OpenXML4JException {
+        return marshall(new ZipArchiveOutputStream(new ByteArrayOutputStream()));
+    }
+
+    private boolean marshall(OutputStream zos) throws OpenXML4JException {
+        PackagePartName rootUri = PackagingURIHelper.createPartName(PACKAGE_RELATIONSHIPS_ROOT_URI);
+        PackagePropertiesPart part = new PackagePropertiesPart(null, rootUri);
+        return marshaller.marshall(part, zos);
     }
 
+
     @Test
-    public void withZipOutputStream() throws Exception {
-        assertTrue(marshaller.marshall(new PackagePropertiesPart(null, PackagingURIHelper.createPartName(PACKAGE_RELATIONSHIPS_ROOT_URI)),
-                new ZipArchiveOutputStream(new ByteArrayOutputStream())));
+    public void nonZipOutputStream() {
+        OutputStream notAZipOutputStream = new ByteArrayOutputStream(0);
+        assertThrows(IllegalArgumentException.class, () -> marshall(notAZipOutputStream));
     }
 
     @Test
-    public void writingFails() throws Exception {
-        assertTrue(marshaller.marshall(new PackagePropertiesPart(null, PackagingURIHelper.createPartName(PACKAGE_RELATIONSHIPS_ROOT_URI)),
-                new ZipArchiveOutputStream(new ByteArrayOutputStream())));
+    public void withZipOutputStream() throws Exception {
+        assertTrue(marshall());
     }
 
-    @Test(expected=OpenXML4JException.class)
+    @Test
     public void ioException() throws Exception {
-        marshaller.marshall(new PackagePropertiesPart(null, PackagingURIHelper.createPartName(PACKAGE_RELATIONSHIPS_ROOT_URI)),
-                new ZipArchiveOutputStream(new ByteArrayOutputStream()) {
-                    @Override
-                    public void putArchiveEntry(final ArchiveEntry archiveEntry) throws IOException {
-                        throw new IOException("TestException");
-                    }
-                });
+        ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new ByteArrayOutputStream()) {
+            @Override
+            public void putArchiveEntry(final ArchiveEntry archiveEntry) throws IOException {
+                throw new IOException("TestException");
+            }
+        };
+        assertThrows(OpenXML4JException.class, () -> marshall(zos));
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/util/TestZipSecureFile.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/util/TestZipSecureFile.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/util/TestZipSecureFile.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/util/TestZipSecureFile.java Thu Dec 24 18:42:29 2020
@@ -20,12 +20,12 @@ import org.apache.commons.compress.archi
 import org.apache.commons.compress.archivers.zip.ZipFile;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.io.InputStream;
 import java.util.Enumeration;
 
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class TestZipSecureFile {
     @Test

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureConfig.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureConfig.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureConfig.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureConfig.java Thu Dec 24 18:42:29 2020
@@ -16,26 +16,26 @@
 ==================================================================== */
 package org.apache.poi.poifs.crypt.dsig;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.io.IOException;
 import java.util.Base64;
 
 import org.apache.poi.poifs.crypt.HashAlgorithm;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 
 public class TestSignatureConfig {
-    
+
     @Test
-    @Ignore("failing in automated builds, due to issues loading security classes")
+    @Disabled("failing in automated builds, due to issues loading security classes")
     public void testDigestAlgo() throws Exception {
         SignatureConfig sc = new SignatureConfig();
         assertEquals(HashAlgorithm.sha256, sc.getDigestAlgo());
         sc.setDigestAlgo(HashAlgorithm.sha1);
         assertEquals(HashAlgorithm.sha1, sc.getDigestAlgo());
     }
-    
+
     @Test
     public void testHashOids() throws IOException {
         final String[][] checks = {
@@ -53,7 +53,7 @@ public class TestSignatureConfig {
             final HashAlgorithm ha = HashAlgorithm.valueOf(check[0]);
             try (final DigestOutputStream dos = new DigestOutputStream(ha, null)) {
                 final String magic = Base64.getEncoder().encodeToString(dos.getHashMagic());
-                assertEquals("hash digest magic mismatches", check[1], magic);
+                assertEquals(check[1], magic, "hash digest magic mismatches");
             }
         }
     }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java Thu Dec 24 18:42:29 2020
@@ -23,11 +23,12 @@
    ================================================================= */
 package org.apache.poi.poifs.crypt.dsig;
 
-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.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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
@@ -152,11 +153,10 @@ import org.bouncycastle.operator.jcajce.
 import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
 import org.etsi.uri.x01903.v13.DigestAlgAndValueType;
 import org.etsi.uri.x01903.v13.QualifyingPropertiesType;
-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.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 import org.w3.x2000.x09.xmldsig.ReferenceType;
 import org.w3.x2000.x09.xmldsig.SignatureDocument;
 import org.w3c.dom.Document;
@@ -169,12 +169,12 @@ public class TestSignatureInfo {
     private KeyPair keyPair;
     private X509Certificate x509;
 
-    @AfterClass
+    @AfterAll
     public static void removeUserLocale() {
         LocaleUtil.resetUserLocale();
     }
 
-    @BeforeClass
+    @BeforeAll
     public static void initBouncy() {
         CryptoFunctions.registerBouncyCastle();
 
@@ -189,8 +189,8 @@ public class TestSignatureInfo {
         // in the xmlsec jar file
         String additionalJar = System.getProperty("additionaljar");
         //System.out.println("Having: " + additionalJar);
-        Assume.assumeTrue("Not running TestSignatureInfo because we are testing with additionaljar set to " + additionalJar,
-                          additionalJar == null || additionalJar.trim().length() == 0);
+        assumeTrue(additionalJar == null || additionalJar.trim().length() == 0,
+            "Not running TestSignatureInfo because we are testing with additionaljar set to " + additionalJar);
 
         System.setProperty("org.apache.xml.security.ignoreLineBreaks", "true");
 
@@ -198,7 +198,7 @@ public class TestSignatureInfo {
         // System.setProperty("line.separator", "\n");
     }
 
-    @Ignore("This test is very sensitive, it breaks with every little change to the produced XML")
+    @Disabled("This test is very sensitive, it breaks with every little change to the produced XML")
     @Test
     public void bug61182() throws Exception {
         final String pfxInput =
@@ -277,7 +277,7 @@ public class TestSignatureInfo {
             // separator set to the various system configurations
             String sep = SystemProperties.getProperty("line.separator");
             String signExp;
-            assumeTrue("Hashes only known for Windows/Unix/Mac", sep == null || "\n".equals(sep) || "\r\n".equals(sep) || "\r".equals(sep));
+            assumeTrue(sep == null || "\n".equals(sep) || "\r\n".equals(sep) || "\r".equals(sep), "Hashes only known for Windows/Unix/Mac");
             signExp = (sep == null || "\n".equals(sep)) ? unixSignExp : ("\r\n".equals(sep)) ? winSignExp : macSignExp;
 
             String signAct = si.getSignatureParts().iterator().next().
@@ -355,12 +355,12 @@ public class TestSignatureInfo {
                 }
 
                 assertNotNull(result);
-                assertEquals("test-file: " + testFile, 1, result.size());
+                assertEquals(1, result.size(), "test-file: " + testFile);
                 X509Certificate signer = result.get(0);
                 LOG.log(POILogger.DEBUG, "signer: ", signer.getSubjectX500Principal());
 
                 boolean b = si.verifySignature();
-                assertTrue("test-file: " + testFile, b);
+                assertTrue(b, "test-file: " + testFile);
                 pkg.revert();
             }
         }
@@ -382,14 +382,14 @@ public class TestSignatureInfo {
             }
 
             assertNotNull(result);
-            assertEquals("test-file: " + testFile, 2, result.size());
+            assertEquals(2, result.size(), "test-file: " + testFile);
             X509Certificate signer1 = result.get(0);
             X509Certificate signer2 = result.get(1);
             LOG.log(POILogger.DEBUG, "signer 1: ", signer1.getSubjectX500Principal());
             LOG.log(POILogger.DEBUG, "signer 2: ", signer2.getSubjectX500Principal());
 
             boolean b = si.verifySignature();
-            assertTrue("test-file: " + testFile, b);
+            assertTrue(b, "test-file: " + testFile);
             pkg.revert();
         }
     }
@@ -433,7 +433,7 @@ public class TestSignatureInfo {
                 si.setOpcPackage(pkg);
                 si.setSignatureConfig(sic);
                 boolean b = si.verifySignature();
-                assertFalse("signature should be broken", b);
+                assertFalse(b, "signature should be broken");
             }
         }
     }
@@ -555,21 +555,21 @@ public class TestSignatureInfo {
                     throw e;
                 }
                 if ((e.getCause() instanceof ConnectException) || (e.getCause() instanceof SocketTimeoutException)) {
-                    Assume.assumeFalse("Only allowing ConnectException with 'timed out' as message here, but had: " + e,
-                                       e.getCause().getMessage().contains("timed out"));
+                    assumeFalse(e.getCause().getMessage().contains("timed out"),
+                        "Only allowing ConnectException with 'timed out' as message here, but had: " + e);
                 } else if (e.getCause() instanceof IOException) {
-                    Assume.assumeFalse("Only allowing IOException with 'Error contacting TSP server' as message here, but had: " + e,
-                                       e.getCause().getMessage().contains("Error contacting TSP server"));
+                    assumeFalse(e.getCause().getMessage().contains("Error contacting TSP server"),
+                        "Only allowing IOException with 'Error contacting TSP server' as message here, but had: " + e);
                 } else if (e.getCause() instanceof RuntimeException) {
-                    Assume.assumeFalse("Only allowing RuntimeException with 'This site is cur' as message here, but had: " + e,
-                                       e.getCause().getMessage().contains("This site is cur"));
+                    assumeFalse(e.getCause().getMessage().contains("This site is cur"),
+                        "Only allowing RuntimeException with 'This site is cur' as message here, but had: " + e);
                 }
                 throw e;
             }
 
             // verify
             Iterator<SignaturePart> spIter = si.getSignatureParts().iterator();
-            assertTrue("Had: " + pkg.getRelationshipsByType(PackageRelationshipTypes.DIGITAL_SIGNATURE_ORIGIN), spIter.hasNext());
+            assertTrue(spIter.hasNext(), "Had: " + pkg.getRelationshipsByType(PackageRelationshipTypes.DIGITAL_SIGNATURE_ORIGIN));
             SignaturePart sp = spIter.next();
             boolean valid = sp.validate();
             assertTrue(valid);
@@ -697,9 +697,9 @@ public class TestSignatureInfo {
             si.confirmSignature();
 
             for (SignaturePart sp : si.getSignatureParts()) {
-                assertTrue("Could not validate", sp.validate());
+                assertTrue(sp.validate(), "Could not validate");
                 X509Certificate signer = sp.getSigner();
-                assertNotNull("signer undefined?!", signer);
+                assertNotNull(signer, "signer undefined?!");
                 List<X509Certificate> certChainRes = sp.getCertChain();
 
                 // IBM JDK is still buggy, even after fix for APAR IJ21985
@@ -731,9 +731,9 @@ public class TestSignatureInfo {
 
                 si.confirmSignature();
                 boolean b = si.verifySignature();
-                assertTrue("Signature not correctly calculated for " + ha, b);
+                assertTrue(b, "Signature not correctly calculated for " + ha);
             } catch (EncryptedDocumentException e) {
-                Assume.assumeTrue(e.getMessage().startsWith("Export Restrictions"));
+                assumeTrue(e.getMessage().startsWith("Export Restrictions"));
             }
         }
     }
@@ -758,7 +758,7 @@ public class TestSignatureInfo {
                 si.setOpcPackage(pkg);
                 si.setSignatureConfig(signatureConfig);
                 si.confirmSignature();
-                assertTrue("invalid signature", si.verifySignature());
+                assertTrue(si.verifySignature(), "invalid signature");
             }
         }
     }
@@ -1087,7 +1087,7 @@ public class TestSignatureInfo {
         // in the Sonar Maven runs where we are at a different source directory
         File buildDir = new File("build");
         if(!buildDir.exists()) {
-            assertTrue("Failed to create " + buildDir.getAbsolutePath(), buildDir.mkdirs());
+            assertTrue(buildDir.mkdirs(), "Failed to create " + buildDir.getAbsolutePath());
         }
         File tmpFile = new File(buildDir, "sigtest"+extension);
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org