/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.apache.commons.compress.archivers.zip;

import org.apache.commons.compress.AbstractTestCase;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.jupiter.api.Test;
import org.junit.rules.ExpectedException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.file.Files;

public class ZipSplitOutputStreamTest extends AbstractTestCase {
    @Rule
    public final ExpectedException thrown = ExpectedException.none();

    @Test
    public void throwsExceptionIfSplitSizeIsTooSmall() throws IOException {
        thrown.expect(IllegalArgumentException.class);
        new ZipSplitOutputStream(File.createTempFile("temp", "zip"), (64 * 1024 - 1));
    }

    @Test
    public void throwsExceptionIfSplitSizeIsTooLarge() throws IOException {
        thrown.expect(IllegalArgumentException.class);
        new ZipSplitOutputStream(File.createTempFile("temp", "zip"), (4 * 1024 * 1024 * 1024L));
    }

    @Test
    public void throwsIfUnsplittableSizeLargerThanSplitSize() throws IOException {
        thrown.expect(IllegalArgumentException.class);
        final long splitSize = 100 * 1024;
        final ZipSplitOutputStream output = new ZipSplitOutputStream(File.createTempFile("temp", "zip"), splitSize);
        output.prepareToWriteUnsplittableContent(splitSize + 1);
    }

    @Test
    public void splitZipBeginsWithZipSplitSignature() throws IOException {
        final File tempFile = File.createTempFile("temp", "zip");
        new ZipSplitOutputStream(tempFile, 100 * 1024L);

        final InputStream inputStream = Files.newInputStream(tempFile.toPath());
        final byte[] buffer = new byte[4];
        inputStream.read(buffer);

        Assert.assertEquals(ByteBuffer.wrap(ZipArchiveOutputStream.DD_SIG).getInt(), ByteBuffer.wrap(buffer).getInt());
    }

    @Test
    public void testCreateSplittedFiles() throws IOException {
        final File testOutputFile = new File(dir, "testCreateSplittedFiles.zip");
        final int splitSize = 100 * 1024; /* 100KB */
        final ZipSplitOutputStream zipSplitOutputStream = new ZipSplitOutputStream(testOutputFile, splitSize);

        final File fileToTest = getFile("COMPRESS-477/split_zip_created_by_zip/zip_to_compare_created_by_zip.zip");
        final InputStream inputStream = Files.newInputStream(fileToTest.toPath());
        final byte[] buffer = new byte[4096];
        int readLen;

        while ((readLen = inputStream.read(buffer)) > 0) {
            zipSplitOutputStream.write(buffer, 0, readLen);
        }

        inputStream.close();
        zipSplitOutputStream.close();

        File zipFile = new File(dir.getPath(), "testCreateSplittedFiles.z01");
        Assert.assertEquals(zipFile.length(), splitSize);

        zipFile = new File(dir.getPath(), "testCreateSplittedFiles.z02");
        Assert.assertEquals(zipFile.length(), splitSize);

        zipFile = new File(dir.getPath(), "testCreateSplittedFiles.z03");
        Assert.assertEquals(zipFile.length(), splitSize);

        zipFile = new File(dir.getPath(), "testCreateSplittedFiles.z04");
        Assert.assertEquals(zipFile.length(), splitSize);

        zipFile = new File(dir.getPath(), "testCreateSplittedFiles.z05");
        Assert.assertEquals(zipFile.length(), splitSize);

        zipFile = new File(dir.getPath(), "testCreateSplittedFiles.zip");
        Assert.assertEquals(zipFile.length(), (fileToTest.length() + 4 - splitSize * 5));
    }
}

@@ -873,458 +873,359 @@
 ort 
-org.apache.commons.compress.AbstractTestCase;%0Aimport org.junit.Assert;%0Aimport org.junit.Rule;%0Aimport org.junit.jupiter.api.Test;%0Aimport org.junit.rules.ExpectedException;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.nio.ByteBuffer;%0Aimport java.nio.file.Files;%0A%0Apublic class ZipSplitOutputStreamTest extends AbstractTestCase %7B%0A    @Rule%0A    public final ExpectedException thrown = ExpectedException.none();
+static org.junit.Assert.assertThrows;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.nio.ByteBuffer;%0Aimport java.nio.file.Files;%0A%0Aimport org.apache.commons.compress.AbstractTestCase;%0Aimport org.junit.Assert;%0Aimport org.junit.jupiter.api.Test;%0A%0Apublic class ZipSplitOutputStreamTest extends AbstractTestCase %7B
 %0A%0A  
@@ -1312,37 +1312,36 @@
 n %7B%0A        
-thrown.expect
+assertThrows
 (IllegalArgu
@@ -1355,34 +1355,31 @@
 eption.class
-);%0A       
+, () -%3E
  new ZipSpli
@@ -1444,16 +1444,17 @@
 24 - 1))
+)
 ;%0A    %7D%0A
@@ -1544,37 +1544,36 @@
 n %7B%0A        
-thrown.expect
+assertThrows
 (IllegalArgu
@@ -1591,26 +1591,23 @@
 on.class
-);%0A       
+, () -%3E
  new Zip
@@ -1686,16 +1686,17 @@
  1024L))
+)
 ;%0A    %7D%0A
@@ -1793,63 +1793,8 @@
 n %7B%0A
-        thrown.expect(IllegalArgumentException.class);%0A
     
@@ -1956,16 +1956,67 @@
 %0A       
+ assertThrows(IllegalArgumentException.class, () -%3E
  output.
@@ -2063,16 +2063,17 @@
 ize + 1)
+)
 ;%0A    %7D%0A

Fix broken tests.