From f0fe4008f89aca9c5f4af46cf3c20ae58fe34861 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Tue, 24 May 2016 14:48:57 +0000 Subject: [PATCH] Adjust two tests slightly git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1745370 13f79535-47bb-0310-9956-ffa450edef68 --- .../TestOPCComplianceCoreProperties.java | 19 +++++++------------ .../apache/poi/poifs/crypt/TestEncryptor.java | 5 ++--- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java index 5ee7b23972..319c3f38b3 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java @@ -111,7 +111,9 @@ public final class TestOPCComplianceCoreProperties extends TestCase { try { extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx"); fail("M4.1 should be being relaxed"); - } catch (AssertionFailedError e) {} + } catch (AssertionFailedError e) { + // expected here + } // We will use the first core properties, and ignore the others InputStream is = OpenXML4JTestDataSamples.openSampleStream("MultipleCoreProperties.docx"); @@ -167,23 +169,16 @@ public final class TestOPCComplianceCoreProperties extends TestCase { /** * Test M4.1 rule. */ - public void testOnlyOneCorePropertiesPart_AddPart() { + public void testOnlyOneCorePropertiesPart_AddPart() throws InvalidFormatException { String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"; - OPCPackage pkg = null; - try { - pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath()); - } catch (Exception e) { - throw new RuntimeException(e); - } - + 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 (InvalidFormatException e) { - throw new RuntimeException(e); } catch (InvalidOperationException e) { // expected during successful test assertEquals("OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !", e.getMessage()); @@ -318,6 +313,6 @@ public final class TestOPCComplianceCoreProperties extends TestCase { // Finish and tidy pkg.revert(); - tmp.delete(); + assertTrue(tmp.delete()); } } diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java index fd494ba267..02e021d7d8 100644 --- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java +++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java @@ -208,7 +208,6 @@ public class TestEncryptor { byte keySalt[] = infoExpected.getHeader().getKeySalt(); - POIFSFileSystem fs = new POIFSFileSystem(); EncryptionInfo infoActual = new EncryptionInfo( EncryptionMode.standard , infoExpected.getVerifier().getCipherAlgorithm() @@ -227,7 +226,6 @@ public class TestEncryptor { // now we use a newly generated salt/verifier and check // if the file content is still the same - fs = new POIFSFileSystem(); infoActual = new EncryptionInfo( EncryptionMode.standard , infoExpected.getVerifier().getCipherAlgorithm() @@ -239,7 +237,8 @@ public class TestEncryptor { e = Encryptor.getInstance(infoActual); e.confirmPassword(pass); - + + POIFSFileSystem fs = new POIFSFileSystem(); OutputStream os = e.getDataStream(fs); IOUtils.copy(new ByteArrayInputStream(payloadExpected), os); os.close(); -- 2.39.5