commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1807556 - /commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/FileLockTestCase.java
Date Thu, 07 Sep 2017 04:39:23 GMT
Author: ggregory
Date: Thu Sep  7 04:39:23 2017
New Revision: 1807556

URL: http://svn.apache.org/viewvc?rev=1807556&view=rev
Log:
Add test.

Modified:
    commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/FileLockTestCase.java

Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/FileLockTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/FileLockTestCase.java?rev=1807556&r1=1807555&r2=1807556&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/FileLockTestCase.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/FileLockTestCase.java
Thu Sep  7 04:39:23 2017
@@ -63,13 +63,17 @@ public class FileLockTestCase {
     private void resolveAndOpenReadCloseInputStream() throws IOException, FileSystemException
{
         try (final FileObject zipFileObject = manager.resolveFile(zipFileUri)) {
             try (InputStream inputStream = zipFileObject.getContent().getInputStream()) {
-                String string = IOUtils.toString(inputStream, "UTF-8");
-                Assert.assertNotNull(string);
-                Assert.assertEquals("This is a test file.", string);
+                readAndAssert(inputStream);
             }
         }
     }
 
+    private void readAndAssert(InputStream inputStream) throws IOException {
+        String string = IOUtils.toString(inputStream, "UTF-8");
+        Assert.assertNotNull(string);
+        Assert.assertEquals("This is a test file.", string);
+    }
+
     @Before
     public void setup() throws IOException {
         final File zipFile = new File("src/test/resources/test-data/test.zip");
@@ -164,5 +168,22 @@ public class FileLockTestCase {
         }
         assertDelete();
     }
+
+    @Test
+    public void testReadClosedFileObject() throws Exception {
+        final FileObject zipFileObjectRef;
+        try (final FileObject zipFileObject = manager.resolveFile(zipFileUri)) {
+            zipFileObjectRef = zipFileObject;
+            try (final InputStream inputStream = zipFileObject.getContent().getInputStream())
{
+                readAndAssert(inputStream);
+            }
+        }
+        try (final InputStream inputStream = zipFileObjectRef.getContent().getInputStream())
{
+            readAndAssert(inputStream);
+        } finally {
+            zipFileObjectRef.close();
+        }
+        assertDelete();
+    }
 
 }



Mime
View raw message