poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1834654 - in /poi/trunk/src: ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
Date Fri, 29 Jun 2018 08:13:22 GMT
Author: centic
Date: Fri Jun 29 08:13:22 2018
New Revision: 1834654

URL: http://svn.apache.org/viewvc?rev=1834654&view=rev
Log:
Slightly adjust afew tests some more

Modified:
    poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
    poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java

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=1834654&r1=1834653&r2=1834654&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 Jun 29 08:13:22
2018
@@ -36,7 +36,6 @@ import org.apache.poi.util.POILogFactory
 import org.apache.poi.util.POILogger;
 import org.apache.poi.util.TempFile;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackageAccess;
 import org.apache.poi.xssf.usermodel.XSSFWorkbookFactory;
@@ -57,7 +56,6 @@ public final class TestWorkbookFactory {
      *
      * @param filename the sample workbook to read in
      * @param wb the workbook to close
-     * @throws IOException
      */
     private static void assertCloseDoesNotModifyFile(String filename, Workbook wb) throws
IOException {
         final byte[] before = HSSFTestDataSamples.getTestDataFileContent(filename);
@@ -113,6 +111,7 @@ public final class TestWorkbookFactory {
                         HSSFTestDataSamples.openSampleFileStream(xlsx))
         );
         assertNotNull(wb);
+        //noinspection ConstantConditions
         assertTrue(wb instanceof XSSFWorkbook);
         assertCloseDoesNotModifyFile(xlsx, wb);
     }
@@ -176,11 +175,9 @@ public final class TestWorkbookFactory {
         // Invalid type -> exception
         final byte[] before = HSSFTestDataSamples.getTestDataFileContent(txt);
         try {
-            InputStream stream = HSSFTestDataSamples.openSampleFileStream(txt);
-            try {
+            try (InputStream stream = HSSFTestDataSamples.openSampleFileStream(txt)) {
                 wb = WorkbookFactory.create(stream);
-            } finally {
-                stream.close();
+                assertNotNull(wb);
             }
             fail();
         } catch(IOException e) {
@@ -254,7 +251,9 @@ public final class TestWorkbookFactory {
             );
             assertCloseDoesNotModifyFile(xls_prot[0], wb);
             fail("Shouldn't be able to open with the wrong password");
-        } catch (EncryptedDocumentException e) {}
+        } catch (EncryptedDocumentException e) {
+            // expected here
+        }
 
         try {
             wb = WorkbookFactory.create(
@@ -262,7 +261,9 @@ public final class TestWorkbookFactory {
             );
             assertCloseDoesNotModifyFile(xlsx_prot[0], wb);
             fail("Shouldn't be able to open with the wrong password");
-        } catch (EncryptedDocumentException e) {}
+        } catch (EncryptedDocumentException e) {
+            // expected here
+        }
     }
 
     /**
@@ -363,21 +364,24 @@ public final class TestWorkbookFactory {
         try {
             WorkbookFactory.create(emptyFile);
             fail("Shouldn't be able to create for an empty file");
-        } catch (final EmptyFileException expected) {}
-        emptyFile.delete();
+        } catch (final EmptyFileException expected) {
+            // expected here
+        }
+
+        assertTrue(emptyFile.delete());
     }
 
     /**
       * Check that a helpful exception is raised on a non-existing file
       */
     @Test
-    public void testNonExistantFile() throws Exception {
-        File nonExistantFile = new File("notExistantFile");
-        assertFalse(nonExistantFile.exists());
+    public void testNonExistingFile() throws Exception {
+        File nonExistingFile = new File("notExistingFile");
+        assertFalse(nonExistingFile.exists());
 
         try {
-            WorkbookFactory.create(nonExistantFile, "password", true);
-            fail("Should not be able to create for a non-existant file");
+            WorkbookFactory.create(nonExistingFile, "password", true);
+            fail("Should not be able to create for a non-existing file");
         } catch (final FileNotFoundException e) {
             // expected
         }

Modified: poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java?rev=1834654&r1=1834653&r2=1834654&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java Fri
Jun 29 08:13:22 2018
@@ -75,18 +75,16 @@ public class BaseTestSlideShowFactory {
 
     @SuppressWarnings("resource")
     protected static void testFactoryFromProtectedFile(String protectedFile, String password)
throws Exception {
-        SlideShow<?,?> ss;
-        // from protected file 
-        ss = SlideShowFactory.create(fromFile(protectedFile), password);
+        // from protected file
+        SlideShow<?,?> ss = SlideShowFactory.create(fromFile(protectedFile), password);
         assertNotNull(ss);
         assertCloseDoesNotModifyFile(protectedFile, ss);
     }
 
     @SuppressWarnings("resource")
     protected static void testFactoryFromProtectedStream(String protectedFile, String password)
throws Exception {
-        SlideShow<?,?> ss;
         // from protected stream
-        ss = SlideShowFactory.create(fromStream(protectedFile), password);
+        SlideShow<?,?> ss = SlideShowFactory.create(fromStream(protectedFile), password);
         assertNotNull(ss);
         assertCloseDoesNotModifyFile(protectedFile, ss);
     }
@@ -163,7 +161,6 @@ public class BaseTestSlideShowFactory {
      *
      * @param filename the sample filename or full path of the slideshow to check before
and after closing
      * @param ss the slideshow to close or revert
-     * @throws IOException
      */
     private static void assertCloseDoesNotModifyFile(String filename, SlideShow<?,?>
ss) throws IOException {
         final byte[] before = readFile(filename);
@@ -177,11 +174,8 @@ public class BaseTestSlideShowFactory {
             // if the file after closing is different, then re-set 
             // the file to the state before in order to not have a dirty SCM 
             // working tree when running this test
-            FileOutputStream str = new FileOutputStream(_slTests.getFile(filename));
-            try {
+            try (FileOutputStream str = new FileOutputStream(_slTests.getFile(filename)))
{
                 str.write(before);
-            } finally {
-                str.close();
             }
             
             throw e;



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


Mime
View raw message