You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jo...@apache.org on 2023/02/08 22:57:53 UTC

[commons-fileupload] branch master updated: FILEUPLOAD-348 - Add tests (already pass in 2.0). (#200)

This is an automated email from the ASF dual-hosted git repository.

jochen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git


The following commit(s) were added to refs/heads/master by this push:
     new a00263b  FILEUPLOAD-348 - Add tests (already pass in 2.0). (#200)
a00263b is described below

commit a00263bb327a01243d84cc5f0afdaf02005805f6
Author: Paul Pogonyshev <po...@gmail.com>
AuthorDate: Wed Feb 8 23:57:48 2023 +0100

    FILEUPLOAD-348 - Add tests (already pass in 2.0). (#200)
---
 .../commons/fileupload2/DiskFileItemSerializeTest.java  | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/test/java/org/apache/commons/fileupload2/DiskFileItemSerializeTest.java b/src/test/java/org/apache/commons/fileupload2/DiskFileItemSerializeTest.java
index 295b857..2166979 100644
--- a/src/test/java/org/apache/commons/fileupload2/DiskFileItemSerializeTest.java
+++ b/src/test/java/org/apache/commons/fileupload2/DiskFileItemSerializeTest.java
@@ -87,9 +87,25 @@ public class DiskFileItemSerializeTest {
         } catch (UncheckedIOException e) {
             fail("Unexpected IOException", e);
         }
+        testWritingToFile(item, testFieldValueBytes);
         item.delete();
     }
 
+    /**
+     * Helper method to test writing item contents to a file.
+     */
+    public void testWritingToFile(final FileItem item, final byte[] testFieldValueBytes) {
+        try {
+            final File temp = File.createTempFile("fileupload", null);
+            // Note that the file exists and is initially empty;
+            // write() must be able to handle that.
+            item.write(temp);
+            compareBytes("Initial", FileUtils.readFileToByteArray(temp), testFieldValueBytes);
+        } catch (Exception e) {
+            fail("Unexpected Exception", e);
+        }
+    }
+
     /**
      * Helper method to test creation of a field.
      */
@@ -138,6 +154,7 @@ public class DiskFileItemSerializeTest {
             fail("Unexpected IOException", e);
         }
 
+        testWritingToFile(item, testFieldValueBytes);
         item.delete();
     }