]> source.dussan.org Git - poi.git/commitdiff
Adjust two tests slightly
authorDominik Stadler <centic@apache.org>
Tue, 24 May 2016 14:48:57 +0000 (14:48 +0000)
committerDominik Stadler <centic@apache.org>
Tue, 24 May 2016 14:48:57 +0000 (14:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1745370 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java

index 5ee7b2397248daaa9d44377d4667310dce5a412e..319c3f38b3346f708e51463cbcdf3e88ff8d9f81 100644 (file)
@@ -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());
     }
 }
index fd494ba2679e33ed705f06fa050bc4f4897fbf59..02e021d7d86b7c765abad137ba182e0cea3accb9 100644 (file)
@@ -208,7 +208,6 @@ public class TestEncryptor {
         byte keySalt[] = infoExpected.getHeader().getKeySalt();\r
         \r
         \r
-        POIFSFileSystem fs = new POIFSFileSystem();\r
         EncryptionInfo infoActual = new EncryptionInfo(\r
               EncryptionMode.standard\r
             , infoExpected.getVerifier().getCipherAlgorithm()\r
@@ -227,7 +226,6 @@ public class TestEncryptor {
         // now we use a newly generated salt/verifier and check\r
         // if the file content is still the same \r
 \r
-        fs = new POIFSFileSystem();\r
         infoActual = new EncryptionInfo(\r
               EncryptionMode.standard\r
             , infoExpected.getVerifier().getCipherAlgorithm()\r
@@ -239,7 +237,8 @@ public class TestEncryptor {
         \r
         e = Encryptor.getInstance(infoActual);\r
         e.confirmPassword(pass);\r
-        \r
+\r
+        POIFSFileSystem fs = new POIFSFileSystem();\r
         OutputStream os = e.getDataStream(fs);\r
         IOUtils.copy(new ByteArrayInputStream(payloadExpected), os);\r
         os.close();\r