Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestAgileEncryptionParameters.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestAgileEncryptionParameters.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestAgileEncryptionParameters.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestAgileEncryptionParameters.java Thu Dec 24 18:42:29 2020 @@ -16,16 +16,17 @@ ==================================================================== */ package org.apache.poi.poifs.crypt.tests; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import javax.crypto.Cipher; @@ -39,55 +40,44 @@ import org.apache.poi.poifs.crypt.Encryp import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class TestAgileEncryptionParameters { static byte[] testData; - @Parameter(value = 0) - public CipherAlgorithm ca; - @Parameter(value = 1) - public HashAlgorithm ha; - @Parameter(value = 2) - public ChainingMode cm; - - @Parameters(name="{0} {1} {2}") - public static Collection<Object[]> data() { + public static Stream<Arguments> data() { CipherAlgorithm[] caList = {CipherAlgorithm.aes128, CipherAlgorithm.aes192, CipherAlgorithm.aes256, CipherAlgorithm.rc2, CipherAlgorithm.des, CipherAlgorithm.des3}; HashAlgorithm[] haList = {HashAlgorithm.sha1, HashAlgorithm.sha256, HashAlgorithm.sha384, HashAlgorithm.sha512, HashAlgorithm.md5}; ChainingMode[] cmList = {ChainingMode.cbc, ChainingMode.cfb}; - List<Object[]> data = new ArrayList<>(); + List<Arguments> data = new ArrayList<>(); for (CipherAlgorithm ca : caList) { for (HashAlgorithm ha : haList) { for (ChainingMode cm : cmList) { - data.add(new Object[]{ca,ha,cm}); + data.add(Arguments.of(ca,ha,cm)); } } } - return data; + return data.stream(); } - @BeforeClass + @BeforeAll public static void initTestData() throws Exception { InputStream testFile = POIDataSamples.getDocumentInstance().openResourceAsStream("SampleDoc.docx"); testData = IOUtils.toByteArray(testFile); testFile.close(); } - @Test - public void testAgileEncryptionModes() throws Exception { + @ParameterizedTest + @MethodSource("data") + public void testAgileEncryptionModes(CipherAlgorithm ca, HashAlgorithm ha, ChainingMode cm) throws Exception { int maxKeyLen = Cipher.getMaxAllowedKeyLength(ca.jceId); - Assume.assumeTrue("Please install JCE Unlimited Strength Jurisdiction Policy files", maxKeyLen >= ca.defaultKeySize); + assumeTrue(maxKeyLen >= ca.defaultKeySize, "Please install JCE Unlimited Strength Jurisdiction Policy files"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -111,6 +101,6 @@ public class TestAgileEncryptionParamete byte[] actualData = IOUtils.toByteArray(is); is.close(); fsDec.close(); - assertArrayEquals("Failed roundtrip - "+ca+"-"+ha+"-"+cm, testData, actualData); + assertArrayEquals(testData, actualData, "Failed roundtrip - "+ca+"-"+ha+"-"+cm); } }
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestDecryptor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestDecryptor.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestDecryptor.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestDecryptor.java Thu Dec 24 18:42:29 2020 @@ -16,10 +16,10 @@ ==================================================================== */ package org.apache.poi.poifs.crypt.tests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -27,7 +27,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.security.GeneralSecurityException; -import java.util.stream.IntStream; import javax.crypto.Cipher; @@ -39,8 +38,7 @@ import org.apache.poi.poifs.crypt.Encryp import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; -import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestDecryptor { private static final POIDataSamples samples = POIDataSamples.getPOIFSInstance(); @@ -94,7 +92,7 @@ public class TestDecryptor { byte[] buf = new byte[10]; int readBytes = zin.read(buf); // zin.available() doesn't work for entries - assertEquals("size failed for " + entry.getName(), 1, readBytes); + assertEquals(1, readBytes, "size failed for " + entry.getName()); } } } @@ -142,17 +140,14 @@ public class TestDecryptor { final ByteArrayOutputStream bos = new ByteArrayOutputStream(10000); try (final ZipArchiveInputStream zis = new ZipArchiveInputStream(d.getDataStream(fs))) { - IntStream.of(3711, 1155, 445, 9376, 450, 588, 1337, 2593, 304, 7910).forEach(size -> { - try { - final ZipArchiveEntry ze = zis.getNextZipEntry(); - assertNotNull(ze); - IOUtils.copy(zis, bos); - assertEquals(size, bos.size()); - bos.reset(); - } catch (IOException e) { - fail(e.getMessage()); - } - }); + int[] sizes = { 3711, 1155, 445, 9376, 450, 588, 1337, 2593, 304, 7910 }; + for (int size : sizes) { + final ZipArchiveEntry ze = zis.getNextZipEntry(); + assertNotNull(ze); + IOUtils.copy(zis, bos); + assertEquals(size, bos.size()); + bos.reset(); + } } } } @@ -170,7 +165,7 @@ public class TestDecryptor { @Test public void bug60320() throws IOException, GeneralSecurityException { 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"); try (InputStream is = samples.openResourceAsStream("60320-protected.xlsx"); POIFSFileSystem fs = new POIFSFileSystem(is)) { Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestEncryptionInfo.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestEncryptionInfo.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestEncryptionInfo.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestEncryptionInfo.java Thu Dec 24 18:42:29 2020 @@ -16,7 +16,7 @@ ==================================================================== */ package org.apache.poi.poifs.crypt.tests; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; @@ -26,8 +26,7 @@ import org.apache.poi.poifs.crypt.Cipher import org.apache.poi.poifs.crypt.EncryptionInfo; import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestEncryptionInfo { @Test @@ -39,11 +38,11 @@ public class TestEncryptionInfo { assertEquals(3, info.getVersionMajor()); assertEquals(2, info.getVersionMinor()); - Assert.assertEquals(CipherAlgorithm.aes128, info.getHeader().getCipherAlgorithm()); - Assert.assertEquals(HashAlgorithm.sha1, info.getHeader().getHashAlgorithm()); + assertEquals(CipherAlgorithm.aes128, info.getHeader().getCipherAlgorithm()); + assertEquals(HashAlgorithm.sha1, info.getHeader().getHashAlgorithm()); assertEquals(128, info.getHeader().getKeySize()); assertEquals(32, info.getVerifier().getEncryptedVerifierHash().length); - Assert.assertEquals(CipherProvider.aes, info.getHeader().getCipherProvider()); + assertEquals(CipherProvider.aes, info.getHeader().getCipherProvider()); assertEquals("Microsoft Enhanced RSA and AES Cryptographic Provider", info.getHeader().getCspName()); fs.close(); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestEncryptor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestEncryptor.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestEncryptor.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestEncryptor.java Thu Dec 24 18:42:29 2020 @@ -17,11 +17,12 @@ package org.apache.poi.poifs.crypt.tests; import static org.apache.poi.poifs.crypt.CryptoFunctions.getMessageDigest; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -62,9 +63,8 @@ import org.apache.poi.util.NullOutputStr import org.apache.poi.util.TempFile; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; -import org.junit.Assume; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class TestEncryptor { @Test @@ -146,7 +146,7 @@ public class TestEncryptor { @Test public void agileEncryption() 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 = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-pass.docx"); String pass = "pass"; @@ -162,7 +162,7 @@ public class TestEncryptor { infoExpected = new EncryptionInfo(nfs); decExpected = Decryptor.getInstance(infoExpected); boolean passed = decExpected.verifyPassword(pass); - assertTrue("Unable to process: document is encrypted", passed); + assertTrue(passed, "Unable to process: document is encrypted"); // extract the payload try (InputStream is = decExpected.getDataStream(nfs)) { @@ -217,7 +217,7 @@ public class TestEncryptor { infoActual2 = new EncryptionInfo(nfs.getRoot()); Decryptor decActual = Decryptor.getInstance(infoActual2); boolean passed = decActual.verifyPassword(pass); - assertTrue("Unable to process: document is encrypted", passed); + assertTrue(passed, "Unable to process: document is encrypted"); // extract the payload try (InputStream is = decActual.getDataStream(nfs)) { @@ -256,7 +256,7 @@ public class TestEncryptor { infoExpected = new EncryptionInfo(nfs); d = Decryptor.getInstance(infoExpected); boolean passed = d.verifyPassword(pass); - assertTrue("Unable to process: document is encrypted", passed); + assertTrue(passed, "Unable to process: document is encrypted"); // extract the payload try (InputStream is = d.getDataStream(nfs)) { @@ -317,7 +317,7 @@ public class TestEncryptor { try (POIFSFileSystem nfs = new POIFSFileSystem(new ByteArrayInputStream(encBytes))) { final EncryptionInfo ei = new EncryptionInfo(nfs); Decryptor d2 = Decryptor.getInstance(ei); - assertTrue("Unable to process: document is encrypted", d2.verifyPassword(pass)); + assertTrue(d2.verifyPassword(pass), "Unable to process: document is encrypted"); try (InputStream is = d2.getDataStream(nfs)) { payloadActual = IOUtils.toByteArray(is); @@ -383,7 +383,7 @@ public class TestEncryptor { } @Test - @Ignore + @Disabled public void inPlaceRewrite() throws Exception { File f = TempFile.createTempFile("protected_agile", ".docx"); @@ -462,7 +462,7 @@ public class TestEncryptor { @Test public void bug60320CustomEncrypt() 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"); // --- src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java (revision 1766745) // +++ src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java (working copy) Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java Thu Dec 24 18:42:29 2020 @@ -20,18 +20,17 @@ package org.apache.poi.poifs.crypt.tests import static org.apache.poi.POIDataSamples.getDocumentInstance; import static org.apache.poi.POIDataSamples.getSlideShowInstance; import static org.apache.poi.POIDataSamples.getSpreadSheetInstance; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collection; +import java.util.stream.Stream; import org.apache.poi.POIDataSamples; import org.apache.poi.POIDocument; @@ -41,28 +40,12 @@ import org.apache.poi.hssf.record.crypto import org.apache.poi.poifs.crypt.EncryptionInfo; import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader; import org.apache.poi.poifs.storage.RawDataUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class TestHxxFEncryption { - @Parameter - public POIDataSamples sampleDir; - - @Parameter(value = 1) - public String file; - - @Parameter(value = 2) - public String password; - - @Parameter(value = 3) - public String expected; - - @Parameters(name="{1}") - public static Collection<Object[]> data() throws IOException { + public static Stream<Arguments> data() throws IOException { final String base64 = "H4sIAAAAAAAAAF1Uu24bMRDs/RULVwkgCUhSpHaZwkDgpHJH8fZ0G/Nx4ZI6y13yG/mRfIb9R5mlZFlIpdPtcnZmdnjPf57/vvx6+f3h6obuv3"+ "ylbY5bEiVHe1fEpUp5pOgkrK0iabehm7FyoZi1ks8xcvHiQu8h5bLnorTlnUvkJ/YPOHKsLVInAqCs91KakuaxLq4w3g00SgCo9Xou1UnCmSBe"+ @@ -74,22 +57,23 @@ public class TestHxxFEncryption { "VZw8Pm6vn0afh4fvr0D5P/+cMuBAAA"; final String x = new String(RawDataUtil.decompress(base64), StandardCharsets.UTF_8); - return Arrays.asList( + return Stream.of( // binary rc4 - new Object[]{ getDocumentInstance(), "password_tika_binaryrc4.doc", "tika", "This is an encrypted Word 2007 File." }, + Arguments.of( getDocumentInstance(), "password_tika_binaryrc4.doc", "tika", "This is an encrypted Word 2007 File." ), // cryptoapi - new Object[]{ getDocumentInstance(), "password_password_cryptoapi.doc", "password", "This is a test" }, + Arguments.of( getDocumentInstance(), "password_password_cryptoapi.doc", "password", "This is a test" ), // binary rc4 - new Object[]{ getSpreadSheetInstance(), "password.xls", "password", x }, + Arguments.of( getSpreadSheetInstance(), "password.xls", "password", x ), // cryptoapi - new Object[]{ getSpreadSheetInstance(), "35897-type4.xls", "freedom", "Sheet1\nhello there!" }, + Arguments.of( getSpreadSheetInstance(), "35897-type4.xls", "freedom", "Sheet1\nhello there!" ), // cryptoapi (PPT only supports cryptoapi...) - new Object[]{ getSlideShowInstance(), "cryptoapi-proc2356.ppt", "crypto", "Dominic Salemno" } + Arguments.of( getSlideShowInstance(), "cryptoapi-proc2356.ppt", "crypto", "Dominic Salemno" ) ); } - @Test - public void extract() throws IOException { + @ParameterizedTest + @MethodSource("data") + public void extract(POIDataSamples sampleDir, String file, String password, String expected) throws IOException { File f = sampleDir.getFile(file); Biff8EncryptionKey.setCurrentUserPassword(password); try (POITextExtractor te = ExtractorFactory.createExtractor(f)) { @@ -100,17 +84,19 @@ public class TestHxxFEncryption { } } - @Test - public void changePassword() throws IOException { - newPassword("test"); + @ParameterizedTest + @MethodSource("data") + public void changePassword(POIDataSamples sampleDir, String file, String password, String expected) throws IOException { + newPassword("test", sampleDir, file, password, expected); } - @Test - public void removePassword() throws IOException { - newPassword(null); + @ParameterizedTest + @MethodSource("data") + public void removePassword(POIDataSamples sampleDir, String file, String password, String expected) throws IOException { + newPassword(null, sampleDir, file, password, expected); } - private void newPassword(String newPass) throws IOException { + private void newPassword(String newPass, POIDataSamples sampleDir, String file, String password, String expected) throws IOException { File f = sampleDir.getFile(file); Biff8EncryptionKey.setCurrentUserPassword(password); try (POITextExtractor te1 = ExtractorFactory.createExtractor(f)) { @@ -130,8 +116,9 @@ public class TestHxxFEncryption { } /** changing the encryption mode and key size in poor mans style - see comments below */ - @Test - public void changeEncryption() throws IOException { + @ParameterizedTest + @MethodSource("data") + public void changeEncryption(POIDataSamples sampleDir, String file, String password, String expected) throws IOException { File f = sampleDir.getFile(file); ByteArrayOutputStream bos = new ByteArrayOutputStream(); Biff8EncryptionKey.setCurrentUserPassword(password); @@ -156,11 +143,8 @@ public class TestHxxFEncryption { // need to cache data (i.e. read all data) before changing the key size Class<?> clazz = doc.getClass(); if ("HSLFSlideShow".equals(clazz.getSimpleName())) { - try { - clazz.getDeclaredMethod("getPictureData").invoke(doc); - } catch (ReflectiveOperationException e) { - fail("either scratchpad jar is included and this should work or the clazz should be != HSLFSlideShowImpl"); - } + assertDoesNotThrow(() -> clazz.getDeclaredMethod("getPictureData").invoke(doc), + "either scratchpad jar is included and this should work or the clazz should be != HSLFSlideShowImpl"); doc.getDocumentSummaryInformation(); } EncryptionInfo ei = doc.getEncryptionInfo(); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestSecureTempZip.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestSecureTempZip.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestSecureTempZip.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestSecureTempZip.java Thu Dec 24 18:42:29 2020 @@ -17,8 +17,9 @@ package org.apache.poi.poifs.crypt.tests; -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 static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.File; import java.io.FileInputStream; @@ -40,8 +41,7 @@ import org.apache.poi.xssf.extractor.XSS import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.xmlbeans.XmlException; -import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestSecureTempZip { @@ -95,8 +95,7 @@ public class TestSecureTempZip { //The test file requires that JCE unlimited be installed. //If it isn't installed, skip this test. 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 tikaProt = XSSFTestDataSamples.getSampleFile("protected_passtika.xlsb"); FileInputStream fis = new FileInputStream(tikaProt); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestFonts.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestFonts.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestFonts.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestFonts.java Thu Dec 24 18:42:29 2020 @@ -18,8 +18,8 @@ package org.apache.poi.sl.tests; import static org.apache.poi.sl.tests.SLCommonUtils.xslfOnly; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.awt.Color; import java.awt.Dimension; @@ -46,8 +46,8 @@ import org.apache.poi.sl.usermodel.TextB import org.apache.poi.sl.usermodel.TextParagraph; import org.apache.poi.sl.usermodel.TextRun; import org.apache.poi.xslf.usermodel.XMLSlideShow; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; /** @@ -69,7 +69,7 @@ public class TestFonts { private static final String[] INIT_FONTS = {"mona.ttf"}; - @BeforeClass + @BeforeAll public static void initGE() throws FontFormatException, IOException { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (String s : INIT_FONTS) { Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestHeadersFooters.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestHeadersFooters.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestHeadersFooters.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestHeadersFooters.java Thu Dec 24 18:42:29 2020 @@ -20,8 +20,8 @@ package org.apache.poi.sl.tests; import static org.apache.poi.sl.tests.SLCommonUtils.openSampleSlideshow; -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.List; @@ -31,7 +31,7 @@ import org.apache.poi.sl.usermodel.Slide import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.TextParagraph; import org.apache.poi.sl.usermodel.TextShape; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestHeadersFooters { @Test Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestOleShape.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestOleShape.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestOleShape.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestOleShape.java Thu Dec 24 18:42:29 2020 @@ -23,10 +23,10 @@ import static org.apache.poi.sl.usermode import static org.apache.poi.sl.usermodel.ObjectMetaData.Application.PDF; import static org.apache.poi.sl.usermodel.ObjectMetaData.Application.WORD_V12; import static org.apache.poi.sl.usermodel.ObjectMetaData.Application.WORD_V8; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeFalse; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.awt.geom.Rectangle2D; import java.io.ByteArrayInputStream; @@ -37,13 +37,11 @@ import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Collection; +import java.util.stream.Stream; import org.apache.poi.POIDataSamples; import org.apache.poi.POIDocument; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.sl.usermodel.ObjectMetaData; import org.apache.poi.sl.usermodel.ObjectShape; @@ -58,14 +56,11 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class TestOleShape { private static final String PDF_SAMPLE = "H4sIAAAAAAAAAJWUezRUWxzHe+o2FXncVtxLpxi3FPOeKYspjMdM5J1S4TTOaDIzxzpzJo9CUrnrSiUxIeT" + @@ -98,42 +93,35 @@ public class TestOleShape { enum Api { HSLF, XSLF } - @Parameter(value = 0) - public Api api; - @Parameter(value = 1) - public ObjectMetaData.Application app; - - private static File pictureFile; - @BeforeClass + @BeforeAll public static void initPicture() { pictureFile = POIDataSamples.getSlideShowInstance().getFile("wrench.emf"); } - - @Parameters(name="{0} {1}") - public static Collection<Object[]> data() { - return Arrays.asList(new Object[][] { - { Api.HSLF, EXCEL_V8 }, - { Api.HSLF, WORD_V8 }, - { Api.HSLF, PDF }, - { Api.XSLF, EXCEL_V12 }, - { Api.XSLF, WORD_V12 }, - { Api.XSLF, PDF }, - }); + public static Stream<Arguments> data() { + return Stream.of( + Arguments.of( Api.HSLF, EXCEL_V8 ), + Arguments.of( Api.HSLF, WORD_V8 ), + Arguments.of( Api.HSLF, PDF ), + Arguments.of( Api.XSLF, EXCEL_V12 ), + Arguments.of( Api.XSLF, WORD_V12 ), + Arguments.of( Api.XSLF, PDF ) + ); } - @Test - public void embedData() throws IOException, InvalidFormatException, ReflectiveOperationException { + @ParameterizedTest + @MethodSource("data") + public void embedData(Api api, ObjectMetaData.Application app) throws IOException, ReflectiveOperationException { final ByteArrayInputStream pptBytes; - try (SlideShow<?,?> ppt = createSlideShow()) { + try (SlideShow<?,?> ppt = createSlideShow(api)) { final PictureData picData = ppt.addPicture(pictureFile, PictureType.EMF); final Slide<?,?> slide = ppt.createSlide(); final ObjectShape<?,?> oleShape = slide.createOleShape(picData); oleShape.setAnchor(new Rectangle2D.Double(100,100,100,100)); try (OutputStream os = oleShape.updateObjectData(app, null)) { - fillOleData(os); + fillOleData(app, os); } final ByteArrayOutputStream bos = new ByteArrayOutputStream(50000); ppt.write(bos); @@ -142,12 +130,12 @@ public class TestOleShape { try (SlideShow<?,?> ppt = SlideShowFactory.create(pptBytes)) { final ObjectShape<?,?> oleShape = (ObjectShape<?,?>)ppt.getSlides().get(0).getShapes().get(0); try (InputStream bis = oleShape.readObjectData()) { - validateOleData(bis); + validateOleData(app, bis); } } } - private SlideShow<?,?> createSlideShow() throws IOException { + private SlideShow<?,?> createSlideShow(Api api) throws IOException { if (api == Api.XSLF) { return new XMLSlideShow(); } else { @@ -157,7 +145,7 @@ public class TestOleShape { } - private void fillOleData(final OutputStream out) throws IOException { + private void fillOleData(ObjectMetaData.Application app, final OutputStream out) throws IOException { switch (app) { case EXCEL_V8: case EXCEL_V12: @@ -187,7 +175,7 @@ public class TestOleShape { } } - private void validateOleData(final InputStream in) throws IOException, ReflectiveOperationException { + private void validateOleData(ObjectMetaData.Application app, final InputStream in) throws IOException, ReflectiveOperationException { switch (app) { case EXCEL_V8: case EXCEL_V12: Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestSlide.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestSlide.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestSlide.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestSlide.java Thu Dec 24 18:42:29 2020 @@ -20,9 +20,9 @@ package org.apache.poi.sl.tests; import static org.apache.poi.sl.tests.SLCommonUtils.xslfOnly; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -33,7 +33,7 @@ import org.apache.poi.sl.usermodel.Slide import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.SlideShowFactory; import org.apache.poi.xslf.usermodel.XMLSlideShow; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestSlide { Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestTable.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestTable.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestTable.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/TestTable.java Thu Dec 24 18:42:29 2020 @@ -21,12 +21,12 @@ package org.apache.poi.sl.tests; import static org.apache.poi.sl.tests.SLCommonUtils.openSampleSlideshow; import static org.apache.poi.sl.tests.SLCommonUtils.xslfOnly; -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.Assume.assumeFalse; +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.Assumptions.assumeFalse; import java.awt.geom.Rectangle2D; import java.io.ByteArrayInputStream; @@ -41,7 +41,7 @@ import org.apache.poi.sl.usermodel.Table import org.apache.poi.sl.usermodel.TableShape; import org.apache.poi.sl.usermodel.TextShape.TextDirection; import org.apache.poi.xslf.usermodel.XMLSlideShow; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestTable { @@ -80,17 +80,15 @@ public class TestTable { int colsx = tableB.getNumberOfColumns(); int rowsx = tableB.getNumberOfRows(); - assertEquals("tables should have same number of columns", cols, colsx); - assertEquals("tables should have same number of rows", rows, rowsx); + assertEquals(cols, colsx, "tables should have same number of columns"); + assertEquals(rows, rowsx, "tables should have same number of rows"); for (int i=0; i<cols; i++) { - assertEquals("Width of column " + i + " should be equal", - tableA.getColumnWidth(i), tableB.getColumnWidth(i), 0.2); + assertEquals(tableA.getColumnWidth(i), tableB.getColumnWidth(i), 0.2, "Width of column " + i + " should be equal"); } for (int i=0; i<rows; i++) { - assertEquals("Height of row " + i + " should be equal", - tableA.getRowHeight(i), tableB.getRowHeight(i), 0.3); + assertEquals(tableA.getRowHeight(i), tableB.getRowHeight(i), 0.3, "Height of row " + i + " should be equal"); } } @@ -164,29 +162,29 @@ public class TestTable { case 22: case 51: if (f.endsWith("ppt")) { - assertNull(msg, tc); + assertNull(tc, msg); } else { - assertNotNull(msg, tc); - assertTrue(msg, tc.isMerged()); + assertNotNull(tc, msg); + assertTrue(tc.isMerged(), msg); } break; case 21: - assertNotNull(msg, tc); - assertEquals(msg, 1, tc.getRowSpan()); - assertEquals(msg, 2, tc.getGridSpan()); - assertFalse(msg, tc.isMerged()); + assertNotNull(tc, msg); + assertEquals(1, tc.getRowSpan(), msg); + assertEquals(2, tc.getGridSpan(), msg); + assertFalse(tc.isMerged(), msg); break; case 41: - assertNotNull(msg, tc); - assertEquals(msg, 2, tc.getRowSpan()); - assertEquals(msg, 1, tc.getGridSpan()); - assertFalse(msg, tc.isMerged()); + assertNotNull(tc, msg); + assertEquals(2, tc.getRowSpan(), msg); + assertEquals(1, tc.getGridSpan(), msg); + assertFalse(tc.isMerged(), msg); break; default: - assertNotNull(msg, tc); - assertEquals(msg, 1, tc.getRowSpan()); - assertEquals(msg, 1, tc.getGridSpan()); - assertFalse(msg, tc.isMerged()); + assertNotNull(tc, msg); + assertEquals(1, tc.getRowSpan(), msg); + assertEquals(1, tc.getGridSpan(), msg); + assertFalse(tc.isMerged(), msg); break; } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/draw/TestDrawPictureShape.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/draw/TestDrawPictureShape.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/draw/TestDrawPictureShape.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/sl/tests/draw/TestDrawPictureShape.java Thu Dec 24 18:42:29 2020 @@ -18,9 +18,9 @@ */ package org.apache.poi.sl.tests.draw; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assume.assumeFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.awt.Dimension; import java.awt.geom.Rectangle2D; @@ -37,15 +37,15 @@ import org.apache.poi.sl.usermodel.Slide import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.SlideShowFactory; import org.apache.poi.util.Units; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TestDrawPictureShape { final static POIDataSamples ssSamples = POIDataSamples.getSlideShowInstance(); private static boolean xslfOnly; - @BeforeClass + @BeforeAll public static void checkHslf() { try { Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow"); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java Thu Dec 24 18:42:29 2020 @@ -17,11 +17,12 @@ package org.apache.poi.ss.tests; -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.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 static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.File; @@ -32,6 +33,7 @@ import java.util.ArrayList; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.stream.Stream; import org.apache.poi.EmptyFileException; import org.apache.poi.EncryptedDocumentException; @@ -43,18 +45,22 @@ import org.apache.poi.openxml4j.opc.Pack import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; +import org.apache.poi.util.IOUtils; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.util.SuppressForbidden; import org.apache.poi.util.TempFile; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbookFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; public final class TestWorkbookFactory { private static final String xls = "SampleSS.xls"; private static final String xlsx = "SampleSS.xlsx"; - private static final String[] xls_protected = new String[] {"password.xls", "password"}; + private static final String[] xls_protected = new String[]{"password.xls", "password"}; private static final String[] xlsx_protected = new String[]{"protected_passtika.xlsx", "tika"}; private static final String txt = "SampleSS.txt"; @@ -65,15 +71,14 @@ public final class TestWorkbookFactory { * Throws an exception if closing the workbook results in the file on disk getting modified. * * @param filename the sample workbook to read in - * @param wb the workbook to close + * @param wb the workbook to close */ private static void assertCloseDoesNotModifyFile(String filename, Workbook wb) throws IOException { final byte[] before = HSSFTestDataSamples.getTestDataFileContent(filename); // FIXME: replace with wb.close() when bug 58779 is resolved closeOrRevert(wb); final byte[] after = HSSFTestDataSamples.getTestDataFileContent(filename); - assertArrayEquals(filename + " sample file was modified as a result of closing the workbook", - before, after); + assertArrayEquals(before, after, filename + " sample file was modified as a result of closing the workbook"); } /** @@ -85,16 +90,14 @@ public final class TestWorkbookFactory { private static void closeOrRevert(Workbook wb) throws IOException { if (wb instanceof HSSFWorkbook) { wb.close(); - } - else if (wb instanceof XSSFWorkbook) { + } else if (wb instanceof XSSFWorkbook) { final XSSFWorkbook xwb = (XSSFWorkbook) wb; if (PackageAccess.READ == xwb.getPackage().getPackageAccess()) { xwb.close(); - } - else { + } else { // TODO: close() re-writes the sample-file?! Resort to revert() for now to close file handle... LOGGER.log(POILogger.WARN, - "reverting XSSFWorkbook rather than closing it to avoid close() modifying the file on disk. Refer to bug 58779."); + "reverting XSSFWorkbook rather than closing it to avoid close() modifying the file on disk. Refer to bug 58779."); xwb.getPackage().revert(); } } else { @@ -104,298 +107,174 @@ public final class TestWorkbookFactory { @Test public void testCreateNative() throws Exception { - Workbook wb; - // POIFS -> hssf - wb = WorkbookFactory.create( - new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls)) - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls, wb); + try (Workbook wb = WorkbookFactory.create( + new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls)) + )) { + assertNotNull(wb); + assertTrue(wb instanceof HSSFWorkbook); + } - wb = WorkbookFactory.create( - new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls)).getRoot() - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls, wb); + try (Workbook wb = WorkbookFactory.create( + new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls)).getRoot() + )) { + assertNotNull(wb); + assertTrue(wb instanceof HSSFWorkbook); + } // Package -> xssf - wb = XSSFWorkbookFactory.createWorkbook( - OPCPackage.open( - HSSFTestDataSamples.openSampleFileStream(xlsx)) - ); - assertNotNull(wb); - //noinspection ConstantConditions - assertTrue(wb instanceof XSSFWorkbook); - assertCloseDoesNotModifyFile(xlsx, wb); + try (Workbook wb = XSSFWorkbookFactory.createWorkbook( + OPCPackage.open(HSSFTestDataSamples.openSampleFileStream(xlsx)) + )) { + assertNotNull(wb); + //noinspection ConstantConditions + assertTrue(wb instanceof XSSFWorkbook); + } } @Test public void testCreateReadOnly() throws Exception { - Workbook wb; - // POIFS -> hssf - wb = WorkbookFactory.create(HSSFTestDataSamples.getSampleFile(xls), null, true); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls, wb); + try (Workbook wb = WorkbookFactory.create(HSSFTestDataSamples.getSampleFile(xls), null, true)) { + assertNotNull(wb); + assertTrue(wb instanceof HSSFWorkbook); + assertCloseDoesNotModifyFile(xls, wb); + } // Package -> xssf - wb = WorkbookFactory.create(HSSFTestDataSamples.getSampleFile(xlsx), null, true); - assertNotNull(wb); - assertTrue(wb instanceof XSSFWorkbook); - assertCloseDoesNotModifyFile(xlsx, wb); + try (Workbook wb = WorkbookFactory.create(HSSFTestDataSamples.getSampleFile(xlsx), null, true)) { + assertNotNull(wb); + assertTrue(wb instanceof XSSFWorkbook); + assertCloseDoesNotModifyFile(xlsx, wb); + } } /** * Creates the appropriate kind of Workbook, but - * checking the mime magic at the start of the - * InputStream, then creating what's required. + * checking the mime magic at the start of the + * InputStream, then creating what's required. */ @Test public void testCreateGeneric() throws Exception { - Workbook wb; - // InputStream -> either - wb = WorkbookFactory.create( - HSSFTestDataSamples.openSampleFileStream(xls) - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls, wb); + try (Workbook wb = WorkbookFactory.create(HSSFTestDataSamples.openSampleFileStream(xls))) { + assertNotNull(wb); + assertTrue(wb instanceof HSSFWorkbook); + } - wb = WorkbookFactory.create( - HSSFTestDataSamples.openSampleFileStream(xlsx) - ); - assertNotNull(wb); - assertTrue(wb instanceof XSSFWorkbook); - assertCloseDoesNotModifyFile(xlsx, wb); + try (Workbook wb = WorkbookFactory.create(HSSFTestDataSamples.openSampleFileStream(xlsx))) { + assertNotNull(wb); + assertTrue(wb instanceof XSSFWorkbook); + } // File -> either - wb = WorkbookFactory.create( - HSSFTestDataSamples.getSampleFile(xls) - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls, wb); + try (Workbook wb = WorkbookFactory.create(HSSFTestDataSamples.getSampleFile(xls))) { + assertNotNull(wb); + assertTrue(wb instanceof HSSFWorkbook); + assertCloseDoesNotModifyFile(xls, wb); + } - wb = WorkbookFactory.create( - HSSFTestDataSamples.getSampleFile(xlsx) - ); - assertNotNull(wb); - assertTrue(wb instanceof XSSFWorkbook); - assertCloseDoesNotModifyFile(xlsx, wb); + try (Workbook wb = WorkbookFactory.create(HSSFTestDataSamples.getSampleFile(xlsx))) { + assertNotNull(wb); + assertTrue(wb instanceof XSSFWorkbook); + assertCloseDoesNotModifyFile(xlsx, wb); + } // Invalid type -> exception final byte[] before = HSSFTestDataSamples.getTestDataFileContent(txt); - try { - try (InputStream stream = HSSFTestDataSamples.openSampleFileStream(txt)) { - wb = WorkbookFactory.create(stream); - assertNotNull(wb); - } - fail(); - } catch(IOException e) { - // Good - } + assertThrows(IOException.class, () -> WorkbookFactory.create(new File(txt))); final byte[] after = HSSFTestDataSamples.getTestDataFileContent(txt); - assertArrayEquals("Invalid type file was modified after trying to open the file as a spreadsheet", - before, after); + assertArrayEquals(before, after, "Invalid type file was modified after trying to open the file as a spreadsheet"); + } + + public static Stream<Arguments> workbookPass() { + return Stream.of( + // Unprotected, no password given, opens normally + Arguments.of(xls, null, false, HSSFWorkbook.class), + Arguments.of(xlsx, null, false, XSSFWorkbook.class), + // Unprotected, wrong password, opens normally + Arguments.of(xls, "wrong", false, HSSFWorkbook.class), + Arguments.of(xlsx, "wrong", false, XSSFWorkbook.class), + // Protected, correct password, opens fine + Arguments.of(xls_protected[0], xls_protected[1], false, HSSFWorkbook.class), + Arguments.of(xlsx_protected[0], xlsx_protected[1], false, XSSFWorkbook.class), + // Protected, wrong password, throws Exception + Arguments.of(xls_protected[0], "wrong", true, HSSFWorkbook.class), + Arguments.of(xlsx_protected[0], "wrong", true, XSSFWorkbook.class) + ); } /** * Check that the overloaded stream methods which take passwords work properly */ - @Test - public void testCreateWithPasswordFromStream() throws Exception { - Workbook wb; - - // Unprotected, no password given, opens normally - wb = WorkbookFactory.create( - HSSFTestDataSamples.openSampleFileStream(xls), null - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls, wb); - - wb = WorkbookFactory.create( - HSSFTestDataSamples.openSampleFileStream(xlsx), null - ); - assertNotNull(wb); - assertTrue(wb instanceof XSSFWorkbook); - assertCloseDoesNotModifyFile(xlsx, wb); - - - // Unprotected, wrong password, opens normally - wb = WorkbookFactory.create( - HSSFTestDataSamples.openSampleFileStream(xls), "wrong" - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls, wb); - - wb = WorkbookFactory.create( - HSSFTestDataSamples.openSampleFileStream(xlsx), "wrong" - ); - assertNotNull(wb); - assertTrue(wb instanceof XSSFWorkbook); - assertCloseDoesNotModifyFile(xlsx, wb); - - - // Protected, correct password, opens fine - wb = WorkbookFactory.create( - HSSFTestDataSamples.openSampleFileStream(xls_protected[0]), xls_protected[1] - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls_protected[0], wb); - - wb = WorkbookFactory.create( - HSSFTestDataSamples.openSampleFileStream(xlsx_protected[0]), xlsx_protected[1] - ); - assertNotNull(wb); - assertTrue(wb instanceof XSSFWorkbook); - assertCloseDoesNotModifyFile(xlsx_protected[0], wb); - - - // Protected, wrong password, throws Exception - try { - wb = WorkbookFactory.create( - HSSFTestDataSamples.openSampleFileStream(xls_protected[0]), "wrong" - ); - assertCloseDoesNotModifyFile(xls_protected[0], wb); - fail("Shouldn't be able to open with the wrong password"); - } catch (EncryptedDocumentException e) { - // expected here - } - - try { - wb = WorkbookFactory.create( - HSSFTestDataSamples.openSampleFileStream(xlsx_protected[0]), "wrong" - ); - assertCloseDoesNotModifyFile(xlsx_protected[0], wb); - fail("Shouldn't be able to open with the wrong password"); - } catch (EncryptedDocumentException e) { - // expected here + @ParameterizedTest + @MethodSource("workbookPass") + public void testCreateWithPasswordFromStream(String file, String pass, boolean fails, Class<? extends Workbook> clazz) throws Exception { + try (InputStream is = HSSFTestDataSamples.openSampleFileStream(file)) { + if (fails) { + assertThrows(EncryptedDocumentException.class, () -> WorkbookFactory.create(is, pass), + "Shouldn't be able to open with the wrong password"); + } else { + try (Workbook wb = WorkbookFactory.create(is, pass)) { + assertNotNull(wb); + assertTrue(clazz.isInstance(wb)); + } + } } } /** * Check that the overloaded file methods which take passwords work properly */ - @Test - public void testCreateWithPasswordFromFile() throws Exception { - Workbook wb; - - // Unprotected, no password given, opens normally - wb = WorkbookFactory.create( - HSSFTestDataSamples.getSampleFile(xls), null - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls, wb); - - wb = WorkbookFactory.create( - HSSFTestDataSamples.getSampleFile(xlsx), null - ); - assertNotNull(wb); - assertTrue(wb instanceof XSSFWorkbook); - assertCloseDoesNotModifyFile(xlsx, wb); - - // Unprotected, wrong password, opens normally - wb = WorkbookFactory.create( - HSSFTestDataSamples.getSampleFile(xls), "wrong" - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls, wb); - - wb = WorkbookFactory.create( - HSSFTestDataSamples.getSampleFile(xlsx), "wrong" - ); - assertNotNull(wb); - assertTrue(wb instanceof XSSFWorkbook); - assertCloseDoesNotModifyFile(xlsx, wb); - - // Protected, correct password, opens fine - wb = WorkbookFactory.create( - HSSFTestDataSamples.getSampleFile(xls_protected[0]), xls_protected[1] - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls_protected[0], wb); - - wb = WorkbookFactory.create( - HSSFTestDataSamples.getSampleFile(xlsx_protected[0]), xlsx_protected[1] - ); - assertNotNull(wb); - assertTrue(wb instanceof XSSFWorkbook); - assertTrue(wb.getNumberOfSheets() > 0); - assertNotNull(wb.getSheetAt(0)); - assertNotNull(wb.getSheetAt(0).getRow(0)); - assertCloseDoesNotModifyFile(xlsx_protected[0], wb); - - // Protected, wrong password, throws Exception - try { - wb = WorkbookFactory.create( - HSSFTestDataSamples.getSampleFile(xls_protected[0]), "wrong" - ); - assertCloseDoesNotModifyFile(xls_protected[0], wb); - fail("Shouldn't be able to open with the wrong password"); - } catch (EncryptedDocumentException e) { - // expected here - } finally { - wb.close(); - } - - try { - wb = WorkbookFactory.create( - HSSFTestDataSamples.getSampleFile(xlsx_protected[0]), "wrong" - ); - assertCloseDoesNotModifyFile(xlsx_protected[0], wb); - fail("Shouldn't be able to open with the wrong password"); - } catch (EncryptedDocumentException e) { - // expected here + @ParameterizedTest + @MethodSource("workbookPass") + public void testCreateWithPasswordFromFile(String fileName, String pass, boolean fails, Class<? extends Workbook> clazz) throws Exception { + File file = HSSFTestDataSamples.getSampleFile(fileName); + if (fails) { + assertThrows(EncryptedDocumentException.class, () -> WorkbookFactory.create(file, pass), + "Shouldn't be able to open with the wrong password"); + } else { + try (Workbook wb = WorkbookFactory.create(file, pass)) { + assertNotNull(wb); + assertTrue(clazz.isInstance(wb)); + assertCloseDoesNotModifyFile(fileName, wb); + } } } /** * Check that a helpful exception is given on an empty input stream */ - @Test(expected = EmptyFileException.class) - public void testEmptyInputStream() throws Exception { + @Test + public void testEmptyInputStream() { InputStream emptyStream = new ByteArrayInputStream(new byte[0]); - WorkbookFactory.create(emptyStream); + assertThrows(EmptyFileException.class, () -> WorkbookFactory.create(emptyStream)); } /** * Check that a helpful exception is given on an empty file */ - @Test(expected = EmptyFileException.class) + @Test public void testEmptyFile() throws Exception { File emptyFile = TempFile.createTempFile("empty", ".poi"); - try { - WorkbookFactory.create(emptyFile); - fail("Shouldn't be able to create for an empty file"); - } finally { - assertTrue(emptyFile.delete()); - } + assertThrows(EmptyFileException.class, () -> WorkbookFactory.create(emptyFile), + "Shouldn't be able to create for an empty file"); + assertTrue(emptyFile.delete()); } /** - * Check that a helpful exception is raised on a non-existing file - */ - @Test(expected = FileNotFoundException.class) - public void testNonExistingFile() throws Exception { + * Check that a helpful exception is raised on a non-existing file + */ + @Test + public void testNonExistingFile() { File nonExistingFile = new File("notExistingFile"); assertFalse(nonExistingFile.exists()); - WorkbookFactory.create(nonExistingFile, "password", true); + assertThrows(FileNotFoundException.class, () -> WorkbookFactory.create(nonExistingFile, "password", true)); } /** * See Bugzilla bug #62831 - #WorkbookFactory.create(File) needs - * to work for sub-classes of File too, eg JFileChooser + * to work for sub-classes of File too, eg JFileChooser */ @Test public void testFileSubclass() throws Exception { @@ -444,30 +323,32 @@ public final class TestWorkbookFactory { public void testOpenManyHSSF() throws Exception { final int size = 1000; ExecutorService executorService = Executors.newFixedThreadPool(10); - ArrayList<Future<Boolean>> futures = new ArrayList(size); + ArrayList<Future<Boolean>> futures = new ArrayList<>(size); for (int i = 0; i < size; i++) { - futures.add(executorService.submit(() -> openHSSFFile())); + futures.add(executorService.submit(this::openHSSFFile)); } - for (Future<Boolean> future: futures) { + for (Future<Boolean> future : futures) { assertTrue(future.get()); } } - @Test(expected = IOException.class) + @Test public void testInvalidFormatException() throws IOException { String filename = "OPCCompliance_DerivedPartNameFAIL.docx"; - WorkbookFactory.create(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename)); + try (InputStream is = POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename)) { + assertThrows(IOException.class, () -> WorkbookFactory.create(is)); + } } private boolean openHSSFFile() { try { // POIFS -> hssf - Workbook wb = WorkbookFactory.create( - new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls)) - ); - assertNotNull(wb); - assertTrue(wb instanceof HSSFWorkbook); - assertCloseDoesNotModifyFile(xls, wb); + try (InputStream is = HSSFTestDataSamples.openSampleFileStream(xls)) { + Workbook wb = WorkbookFactory.create(new POIFSFileSystem(is)); + assertNotNull(wb); + assertTrue(wb instanceof HSSFWorkbook); + assertCloseDoesNotModifyFile(xls, wb); + } return true; } catch (Exception e) { return false; Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/extractor/TestEmbeddedExtractor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/extractor/TestEmbeddedExtractor.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/extractor/TestEmbeddedExtractor.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/extractor/TestEmbeddedExtractor.java Thu Dec 24 18:42:29 2020 @@ -17,8 +17,8 @@ package org.apache.poi.ss.tests.extractor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import java.io.InputStream; @@ -38,7 +38,7 @@ import org.apache.poi.ss.extractor.Embed import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestEmbeddedExtractor { private static final POIDataSamples samples = POIDataSamples.getSpreadSheetInstance(); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/format/TestCellFormatPart.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/format/TestCellFormatPart.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/format/TestCellFormatPart.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/format/TestCellFormatPart.java Thu Dec 24 18:42:29 2020 @@ -17,8 +17,8 @@ package org.apache.poi.ss.tests.format; import static java.awt.Color.ORANGE; -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.awt.Color; import java.io.IOException; @@ -39,9 +39,9 @@ import org.apache.poi.ss.usermodel.Sheet import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.util.LocaleUtil; import org.apache.poi.xssf.XSSFITestDataProvider; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; /** * Class for spreadsheet-based tests, such as are used for cell formatting. @@ -63,13 +63,13 @@ public class TestCellFormatPart { - @BeforeClass + @BeforeAll public static void setLocale() { userLocale = LocaleUtil.getUserLocale(); LocaleUtil.setUserLocale(Locale.UK); } - @AfterClass + @AfterAll public static void unsetLocale() { LocaleUtil.setUserLocale(userLocale); } @@ -80,8 +80,7 @@ public class TestCellFormatPart { Object getValue(Cell cell); default void equivalent(String expected, String actual, CellFormatPart format) { - assertEquals("format \"" + format + "\"", '"' + expected + '"', - '"' + actual + '"'); + assertEquals('"' + expected + '"', '"' + actual + '"', "format \"" + format + "\""); } } @@ -120,8 +119,7 @@ public class TestCellFormatPart { double actualVal = extractNumber(actual); // equal within 1% double delta = expectedVal / 100; - assertEquals("format \"" + format + "\"," + expected + " ~= " + - actual, expectedVal, actualVal, delta); + assertEquals(expectedVal, actualVal, delta, "format \"" + format + "\"," + expected + " ~= " + actual); } }); } @@ -204,7 +202,7 @@ public class TestCellFormatPart { String actualText = label.getText(); Color actualColor = label.getForeground(); valueGetter.equivalent(expectedText, actualText, cellFormatPart); - assertEquals("no color", expectedColor, actualColor); + assertEquals(expectedColor, actualColor, "no color"); } } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/TestFormulaParser.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/TestFormulaParser.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/TestFormulaParser.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/TestFormulaParser.java Thu Dec 24 18:42:29 2020 @@ -18,10 +18,10 @@ */ package org.apache.poi.ss.tests.formula; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -38,7 +38,7 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test {@link FormulaParser}'s handling of row numbers at the edge of the @@ -51,13 +51,8 @@ public class TestFormulaParser { @Test public void testHSSFFailsForOver65536() { FormulaParsingWorkbook workbook = HSSFEvaluationWorkbook.create(new HSSFWorkbook()); - try { - FormulaParser.parse("Sheet1!1:65537", workbook, FormulaType.CELL, 0); - fail("Expected exception"); - } - catch (FormulaParseException expected) { - // expected here - } + assertThrows(FormulaParseException.class, () -> + FormulaParser.parse("Sheet1!1:65537", workbook, FormulaType.CELL, 0)); } private static void checkHSSFFormula(String formula) { @@ -90,13 +85,8 @@ public class TestFormulaParser { @Test public void testXSSFFailCase() { FormulaParsingWorkbook workbook = XSSFEvaluationWorkbook.create(new XSSFWorkbook()); - try { - FormulaParser.parse("Sheet1!1:1048577", workbook, FormulaType.CELL, 0); // one more than max rows. - fail("Expected exception"); - } - catch (FormulaParseException expected) { - // expected here - } + assertThrows(FormulaParseException.class, () -> + FormulaParser.parse("Sheet1!1:1048577", workbook, FormulaType.CELL, 0), "one more than max rows"); } // copied from org.apache.poi.hssf.model.TestFormulaParser @@ -175,13 +165,9 @@ public class TestFormulaParser { /** confirm formula has invalid syntax and parsing the formula results in FormulaParseException */ private static void parseExpectedException(String formula, FormulaParsingWorkbook wb) { - try { - FormulaParser.parse(formula, wb, FormulaType.CELL, -1); - fail("Expected FormulaParseException: " + formula); - } catch (final FormulaParseException e) { - // expected during successful test - assertNotNull(e.getMessage()); - } + FormulaParseException e = assertThrows(FormulaParseException.class, () -> + FormulaParser.parse(formula, wb, FormulaType.CELL, -1)); + assertNotNull(e.getMessage()); } // trivial case for bug 60219: FormulaParser can't parse external references when sheet name is quoted @@ -191,13 +177,13 @@ public class TestFormulaParser { XSSFEvaluationWorkbook fpwb = XSSFEvaluationWorkbook.create(wb); Ptg[] ptgs = FormulaParser.parse("[1]Sheet1!A1", fpwb, FormulaType.CELL, -1); // org.apache.poi.ss.formula.ptg.Ref3DPxg [ [workbook=1] sheet=Sheet 1 ! A1] - assertEquals("Ptgs length", 1, ptgs.length); - assertTrue("Ptg class", ptgs[0] instanceof Ref3DPxg); + assertEquals(1, ptgs.length, "Ptgs length"); + assertTrue(ptgs[0] instanceof Ref3DPxg, "Ptg class"); Ref3DPxg pxg = (Ref3DPxg) ptgs[0]; - assertEquals("External workbook number", 1, pxg.getExternalWorkbookNumber()); - assertEquals("Sheet name", "Sheet1", pxg.getSheetName()); - assertEquals("Row", 0, pxg.getRow()); - assertEquals("Column", 0, pxg.getColumn()); + assertEquals(1, pxg.getExternalWorkbookNumber(), "External workbook number"); + assertEquals("Sheet1", pxg.getSheetName(), "Sheet name"); + assertEquals(0, pxg.getRow(), "Row"); + assertEquals(0, pxg.getColumn(), "Column"); wb.close(); } @@ -208,13 +194,13 @@ public class TestFormulaParser { XSSFEvaluationWorkbook fpwb = XSSFEvaluationWorkbook.create(wb); Ptg[] ptgs = FormulaParser.parse("'[1]Sheet 1'!A1", fpwb, FormulaType.CELL, -1); // org.apache.poi.ss.formula.ptg.Ref3DPxg [ [workbook=1] sheet=Sheet 1 ! A1] - assertEquals("Ptgs length", 1, ptgs.length); - assertTrue("Ptg class", ptgs[0] instanceof Ref3DPxg); + assertEquals(1, ptgs.length, "Ptgs length"); + assertTrue(ptgs[0] instanceof Ref3DPxg, "Ptg class"); Ref3DPxg pxg = (Ref3DPxg) ptgs[0]; - assertEquals("External workbook number", 1, pxg.getExternalWorkbookNumber()); - assertEquals("Sheet name", "Sheet 1", pxg.getSheetName()); - assertEquals("Row", 0, pxg.getRow()); - assertEquals("Column", 0, pxg.getColumn()); + assertEquals(1, pxg.getExternalWorkbookNumber(), "External workbook number"); + assertEquals("Sheet 1", pxg.getSheetName(), "Sheet name"); + assertEquals(0, pxg.getRow(), "Row"); + assertEquals(0, pxg.getColumn(), "Column"); wb.close(); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/TestStructuredReferences.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/TestStructuredReferences.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/TestStructuredReferences.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/TestStructuredReferences.java Thu Dec 24 18:42:29 2020 @@ -17,10 +17,9 @@ package org.apache.poi.ss.tests.formula; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; @@ -35,7 +34,7 @@ import org.apache.poi.xssf.usermodel.XSS import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFTable; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests Excel Table expressions (structured references) @@ -50,16 +49,16 @@ public class TestStructuredReferences { */ @Test public void testTableExpressionSyntax() { - assertTrue("Valid structured reference syntax didn't match expression", Table.isStructuredReference.matcher("abc[col1]").matches()); - assertTrue("Valid structured reference syntax didn't match expression", Table.isStructuredReference.matcher("_abc[col1]").matches()); - assertTrue("Valid structured reference syntax didn't match expression", Table.isStructuredReference.matcher("_[col1]").matches()); - assertTrue("Valid structured reference syntax didn't match expression", Table.isStructuredReference.matcher("\\[col1]").matches()); - assertTrue("Valid structured reference syntax didn't match expression", Table.isStructuredReference.matcher("\\[col1]").matches()); - assertTrue("Valid structured reference syntax didn't match expression", Table.isStructuredReference.matcher("\\[#This Row]").matches()); - assertTrue("Valid structured reference syntax didn't match expression", Table.isStructuredReference.matcher("\\[ [col1], [col2] ]").matches()); + assertTrue(Table.isStructuredReference.matcher("abc[col1]").matches(), "Valid structured reference syntax didn't match expression"); + assertTrue(Table.isStructuredReference.matcher("_abc[col1]").matches(), "Valid structured reference syntax didn't match expression"); + assertTrue(Table.isStructuredReference.matcher("_[col1]").matches(), "Valid structured reference syntax didn't match expression"); + assertTrue(Table.isStructuredReference.matcher("\\[col1]").matches(), "Valid structured reference syntax didn't match expression"); + assertTrue(Table.isStructuredReference.matcher("\\[col1]").matches(), "Valid structured reference syntax didn't match expression"); + assertTrue(Table.isStructuredReference.matcher("\\[#This Row]").matches(), "Valid structured reference syntax didn't match expression"); + assertTrue(Table.isStructuredReference.matcher("\\[ [col1], [col2] ]").matches(), "Valid structured reference syntax didn't match expression"); // can't have a space between the table name and open bracket - assertFalse("Invalid structured reference syntax didn't fail expression", Table.isStructuredReference.matcher("\\abc [ [col1], [col2] ]").matches()); + assertFalse(Table.isStructuredReference.matcher("\\abc [ [col1], [col2] ]").matches(), "Invalid structured reference syntax didn't fail expression"); } @Test @@ -109,18 +108,14 @@ public class TestStructuredReferences { private static void confirm(FormulaEvaluator fe, Cell cell, double expectedResult) { fe.clearAllCachedResultValues(); CellValue cv = fe.evaluate(cell); - if (cv.getCellType() != CellType.NUMERIC) { - fail("expected numeric cell type but got " + cv.formatAsString()); - } + assertEquals(CellType.NUMERIC, cv.getCellType(), "expected numeric cell type but got " + cv.formatAsString()); assertEquals(expectedResult, cv.getNumberValue(), 0.0); } private static void confirm(FormulaEvaluator fe, Cell cell, String expectedResult) { fe.clearAllCachedResultValues(); CellValue cv = fe.evaluate(cell); - if (cv.getCellType() != CellType.STRING) { - fail("expected String cell type but got " + cv.formatAsString()); - } + assertEquals(CellType.STRING, cv.getCellType(), "expected String cell type but got " + cv.formatAsString()); assertEquals(expectedResult, cv.getStringValue()); } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/CountifsTests.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/CountifsTests.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/CountifsTests.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/CountifsTests.java Thu Dec 24 18:42:29 2020 @@ -18,8 +18,8 @@ package org.apache.poi.ss.tests.formula.functions; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; @@ -32,9 +32,9 @@ import org.apache.poi.ss.usermodel.Workb import org.apache.poi.ss.util.SheetUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.XSSFTestDataSamples; -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; /** * Test the COUNTIFS() function @@ -46,7 +46,7 @@ public class CountifsTests { /** * initialize a workbook */ - @Before + @BeforeEach public void before() { // not sure why we allow this, COUNTIFS() is only available // in OOXML, it was introduced with Office 2007 @@ -56,7 +56,7 @@ public class CountifsTests { /** * Close the workbook if needed */ - @After + @AfterEach public void after() { IOUtils.closeQuietly(workbook); } @@ -108,14 +108,13 @@ public class CountifsTests { /** * the bug returned the wrong count, this verifies the fix - * @throws Exception if the file can't be read */ @Test - public void testBug56822() throws Exception { + public void testBug56822() { workbook = XSSFTestDataSamples.openSampleWorkbook("56822-Countifs.xlsx"); FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); Cell cell = SheetUtil.getCell(workbook.getSheetAt(0), 0, 3); - assertNotNull("Test workbook missing cell D1", cell); + assertNotNull(cell, "Test workbook missing cell D1"); CellValue evaluate = evaluator.evaluate(cell); assertEquals(2.0d, evaluate.getNumberValue(), 0.00000000000001); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestProper.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestProper.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestProper.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestProper.java Thu Dec 24 18:42:29 2020 @@ -17,8 +17,8 @@ package org.apache.poi.ss.tests.formula.functions; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -33,7 +33,7 @@ import org.apache.poi.ss.usermodel.Sheet import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; public final class TestProper { private Cell cell11; @@ -93,7 +93,7 @@ public final class TestProper { cell11.setCellFormula(formulaText); evaluator.clearAllCachedResultValues(); CellValue cv = evaluator.evaluate(cell11); - assertEquals("Wrong result type", CellType.STRING, cv.getCellType()); + assertEquals(CellType.STRING, cv.getCellType(), "Wrong result type"); String actualValue = cv.getStringValue(); assertEquals(expectedResult, actualValue); } @@ -120,7 +120,7 @@ public final class TestProper { @Test public void testMicroBenchmark() { ValueEval strArg = new StringEval("some longer text that needs a number of replacements to check for runtime of different implementations"); - long start = System.currentTimeMillis(); + // long start = System.currentTimeMillis(); for(int i = 0;i < 300000;i++) { final ValueEval ret = TextFunction.PROPER.evaluate(new ValueEval[]{strArg}, 0, 0); assertEquals("Some Longer Text That Needs A Number Of Replacements To Check For Runtime Of Different Implementations", ((StringEval)ret).getStringValue()); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestSumifsXSSF.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestSumifsXSSF.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestSumifsXSSF.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestSumifsXSSF.java Thu Dec 24 18:42:29 2020 @@ -19,7 +19,7 @@ package org.apache.poi.ss.tests.formula.functions; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; @@ -28,7 +28,7 @@ import org.apache.poi.ss.usermodel.Formu import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestVlookup.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestVlookup.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestVlookup.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestVlookup.java Thu Dec 24 18:42:29 2020 @@ -17,8 +17,8 @@ package org.apache.poi.ss.tests.formula.functions; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; @@ -32,7 +32,7 @@ import org.apache.poi.ss.usermodel.Sheet import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test the VLOOKUP function @@ -44,10 +44,10 @@ public class TestVlookup { try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("VLookupFullColumn.xlsx")) { FormulaEvaluator feval = wb.getCreationHelper().createFormulaEvaluator(); feval.evaluateAll(); - assertEquals("Wrong lookup value", "Value1", - feval.evaluate(wb.getSheetAt(0).getRow(3).getCell(1)).getStringValue()); - assertEquals("Lookup should return #N/A", - CellType.ERROR, feval.evaluate(wb.getSheetAt(0).getRow(4).getCell(1)).getCellType()); + assertEquals("Value1", feval.evaluate(wb.getSheetAt(0).getRow(3).getCell(1)).getStringValue(), + "Wrong lookup value"); + assertEquals(CellType.ERROR, feval.evaluate(wb.getSheetAt(0).getRow(4).getCell(1)).getCellType(), + "Lookup should return #N/A"); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org