JAMES-2426 don't require a File but write Zip into a OutputStream instead

Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/48729c70
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/48729c70
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/48729c70

Branch: refs/heads/master
Commit: 48729c70ef8a4af19f85ee7f612ca4af6d3329ad
Parents: 73bf8a5
Author: Matthieu Baechler <[email protected]>
Authored: Mon Jun 18 15:11:36 2018 +0200
Committer: Raphael Ouazana <[email protected]>
Committed: Wed Jun 27 16:36:12 2018 +0200

----------------------------------------------------------------------
 .../apache/james/mailbox/backup/ZipperTest.java | 51 ++++++++------------
 1 file changed, 19 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/48729c70/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/ZipperTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/ZipperTest.java 
b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/ZipperTest.java
index a2d9e6f..aa465d3 100644
--- 
a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/ZipperTest.java
+++ 
b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/ZipperTest.java
@@ -28,42 +28,38 @@ import static 
org.apache.james.mailbox.backup.MailboxMessageFixture.SIZE_1;
 import static org.apache.james.mailbox.backup.ZipAssert.EntryChecks.hasName;
 import static org.apache.james.mailbox.backup.ZipAssert.assertThatZip;
 
-import java.io.File;
-import java.io.FileOutputStream;
+import java.io.ByteArrayOutputStream;
 import java.util.stream.Stream;
 
 import org.apache.commons.compress.archivers.zip.ZipFile;
-import org.apache.james.junit.TemporaryFolderExtension;
-import org.apache.james.junit.TemporaryFolderExtension.TemporaryFolder;
+import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
 
-@ExtendWith(TemporaryFolderExtension.class)
-public class ZipperTest {
+class ZipperTest {
+
     private Zipper testee;
-    private File destination;
+    private ByteArrayOutputStream output;
 
     @BeforeEach
-    void beforeEach(TemporaryFolder temporaryFolder) throws Exception {
+    void beforeEach() {
         testee = new Zipper();
-        destination = File.createTempFile("backup-test", ".zip", 
temporaryFolder.getTempDir());
+        output = new ByteArrayOutputStream();
     }
 
     @Test
     void archiveShouldWriteEmptyValidArchiveWhenNoMessage() throws Exception {
-        testee.archive(Stream.of(), new FileOutputStream(destination));
-
-        try (ZipFile zipFile = new ZipFile(destination)) {
+        testee.archive(Stream.of(), output);
+        try (ZipFile zipFile = new ZipFile(toSeekableByteChannel(output))) {
             assertThatZip(zipFile).hasNoEntry();
         }
     }
 
     @Test
     void archiveShouldWriteOneMessageWhenOne() throws Exception {
-        testee.archive(Stream.of(MESSAGE_1), new 
FileOutputStream(destination));
+        testee.archive(Stream.of(MESSAGE_1), output);
 
-        try (ZipFile zipFile = new ZipFile(destination)) {
+        try (ZipFile zipFile = new ZipFile(toSeekableByteChannel(output))) {
             assertThatZip(zipFile)
                 .containsOnlyEntriesMatching(
                     hasName(MESSAGE_ID_1.serialize())
@@ -73,9 +69,9 @@ public class ZipperTest {
 
     @Test
     void archiveShouldWriteTwoMessagesWhenTwo() throws Exception {
-        testee.archive(Stream.of(MESSAGE_1, MESSAGE_2), new 
FileOutputStream(destination));
+        testee.archive(Stream.of(MESSAGE_1, MESSAGE_2), output);
 
-        try (ZipFile zipFile = new ZipFile(destination)) {
+        try (ZipFile zipFile = new ZipFile(toSeekableByteChannel(output))) {
             assertThatZip(zipFile)
                 .containsOnlyEntriesMatching(
                     hasName(MESSAGE_ID_1.serialize())
@@ -86,27 +82,18 @@ public class ZipperTest {
     }
 
     @Test
-    void archiveShouldOverwriteContent() throws Exception {
-        testee.archive(Stream.of(MESSAGE_1), new 
FileOutputStream(destination));
-        testee.archive(Stream.of(MESSAGE_2), new 
FileOutputStream(destination));
-
-        try (ZipFile zipFile = new ZipFile(destination)) {
-            assertThatZip(zipFile)
-                .containsOnlyEntriesMatching(
-                    hasName(MESSAGE_ID_2.serialize())
-                        .hasStringContent(MESSAGE_CONTENT_2));
-        }
-    }
-
-    @Test
     void archiveShouldWriteSizeMetadata() throws Exception {
-        testee.archive(Stream.of(MESSAGE_1), new 
FileOutputStream(destination));
+        testee.archive(Stream.of(MESSAGE_1), output);
 
-        try (ZipFile zipFile = new ZipFile(destination)) {
+        try (ZipFile zipFile = new ZipFile(toSeekableByteChannel(output))) {
             assertThatZip(zipFile)
                 .containsOnlyEntriesMatching(
                     hasName(MESSAGE_ID_1.serialize())
                         .containsExtraFields(new SizeExtraField(SIZE_1)));
         }
     }
+
+    private SeekableInMemoryByteChannel 
toSeekableByteChannel(ByteArrayOutputStream output) {
+        return new SeekableInMemoryByteChannel(output.toByteArray());
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to