You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2018/10/26 10:58:37 UTC

svn commit: r1844894 - in /poi/trunk/src/ooxml/testcases/org/apache/poi: openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java ss/TestWorkbookFactory.java

Author: centic
Date: Fri Oct 26 10:58:37 2018
New Revision: 1844894

URL: http://svn.apache.org/viewvc?rev=1844894&view=rev
Log:
IDE warnings, slightly more tests and fix test to not leave a modified file behind

Modified:
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java

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=1844894&r1=1844893&r2=1844894&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 Fri Oct 26 10:58:37 2018
@@ -83,9 +83,7 @@ public final class TestOPCComplianceCore
         try {
             InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
             pkg = OPCPackage.open(is);
-        } catch (InvalidFormatException e) {
-            throw new RuntimeException(e);
-        } catch (IOException e) {
+        } catch (InvalidFormatException | IOException e) {
             throw new RuntimeException(e);
         }
         pkg.revert();
@@ -151,9 +149,7 @@ public final class TestOPCComplianceCore
         OPCPackage pkg;
         try {
             pkg = OPCPackage.open(is);
-        } catch (InvalidFormatException e) {
-            throw new RuntimeException(e);
-        } catch (IOException e) {
+        } catch (InvalidFormatException | IOException e) {
             throw new RuntimeException(e);
         }
         URI partUri = createURI("/docProps/core2.xml");

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java?rev=1844894&r1=1844893&r2=1844894&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java Fri Oct 26 10:58:37 2018
@@ -31,6 +31,7 @@ import java.io.InputStream;
 
 import org.apache.poi.EmptyFileException;
 import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.POIDataSamples;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.openxml4j.opc.OPCPackage;
@@ -109,6 +110,13 @@ public final class TestWorkbookFactory {
         assertTrue(wb instanceof HSSFWorkbook);
         assertCloseDoesNotModifyFile(xls, wb);
 
+        wb = WorkbookFactory.create(
+                new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls)).getRoot()
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        assertCloseDoesNotModifyFile(xls, wb);
+
         // Package -> xssf
         wb = XSSFWorkbookFactory.create(
                 OPCPackage.open(
@@ -403,15 +411,15 @@ public final class TestWorkbookFactory {
         assertTrue(altXLS.exists());
         assertTrue(altXLSX.exists());
 
-        try (Workbook wb = WorkbookFactory.create(altXLS)) {
-            assertNotNull(wb);
-            assertTrue(wb instanceof HSSFWorkbook);
-        }
+        Workbook wb = WorkbookFactory.create(altXLS);
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        closeOrRevert(wb);
 
-        try (Workbook wb = WorkbookFactory.create(altXLSX)) {
-            assertNotNull(wb);
-            assertTrue(wb instanceof XSSFWorkbook);
-        }
+        wb = WorkbookFactory.create(altXLSX);
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+        closeOrRevert(wb);
     }
     
     private static class TestFile extends File {
@@ -425,12 +433,24 @@ public final class TestWorkbookFactory {
      */
     @Test
     public void testCreateEmpty() throws Exception {
-        try (Workbook wb = WorkbookFactory.create(false)) {
-            assertTrue(wb instanceof HSSFWorkbook);
-        }
+        Workbook wb = WorkbookFactory.create(false);
+        assertTrue(wb instanceof HSSFWorkbook);
+        closeOrRevert(wb);
+
+        wb = WorkbookFactory.create(true);
+        assertTrue(wb instanceof XSSFWorkbook);
+        closeOrRevert(wb);
+    }
 
-        try (Workbook wb = WorkbookFactory.create(true)) {
-            assertTrue(wb instanceof XSSFWorkbook);
+    @Test
+    public void testInvalidFormatException() {
+        String filename = "OPCCompliance_DerivedPartNameFAIL.docx";
+        try {
+            WorkbookFactory.create(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename));
+            fail("Expecting an Exception for this document");
+        } catch (IOException e) {
+            // expected here
         }
     }
+
 }



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