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

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


The following commit(s) were added to refs/heads/master by this push:
     new 41b2678d Let JUnit manage temporary files
41b2678d is described below

commit 41b2678dcb180505eafd5f673a17f543984d8eac
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Nov 4 12:58:04 2023 -0400

    Let JUnit manage temporary files
---
 .../org/apache/commons/compress/AbstractTest.java  | 25 ++++------------------
 .../commons/compress/archivers/SevenZTest.java     | 13 ++++++-----
 .../examples/ParameterizedArchiverTest.java        |  1 -
 .../examples/ParameterizedExpanderTest.java        |  1 -
 .../archivers/examples/SevenZArchiverTest.java     |  2 --
 5 files changed, 10 insertions(+), 32 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/AbstractTest.java 
b/src/test/java/org/apache/commons/compress/AbstractTest.java
index 0b3c5604..2446d954 100644
--- a/src/test/java/org/apache/commons/compress/AbstractTest.java
+++ b/src/test/java/org/apache/commons/compress/AbstractTest.java
@@ -43,8 +43,6 @@ import 
org.apache.commons.compress.archivers.ArchiveStreamFactory;
 import org.apache.commons.compress.archivers.ar.ArArchiveOutputStream;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.io.TempDir;
 
 public abstract class AbstractTest extends AbstractTempDirTest {
@@ -89,7 +87,7 @@ public abstract class AbstractTest extends 
AbstractTempDirTest {
         }
         try {
             return new File(url.toURI());
-        } catch (final URISyntaxException ex) {
+        } catch (URISyntaxException ex) {
             throw new IOException(ex);
         }
     }
@@ -105,9 +103,6 @@ public abstract class AbstractTest extends 
AbstractTempDirTest {
     @TempDir
     protected File tempResultDir;
 
-    /** Used to delete the archive in {@link #tearDown()}. */
-    private Path archivePath;
-
     /** Lists the content of the archive as originally created. */
     protected List<String> archiveList;
 
@@ -248,7 +243,7 @@ public abstract class AbstractTest extends 
AbstractTempDirTest {
      *             in case something goes wrong
      */
     protected Path createArchive(final String archiveName) throws Exception {
-        archivePath = createTempPath("test", "." + archiveName);
+        final Path archivePath = createTempPath("test", "." + archiveName);
         archiveList = new ArrayList<>();
         try (OutputStream outputStream = Files.newOutputStream(archivePath);
                 ArchiveOutputStream<ArchiveEntry> archiveOutputStream = 
factory.createArchiveOutputStream(archiveName, outputStream)) {
@@ -283,7 +278,7 @@ public abstract class AbstractTest extends 
AbstractTempDirTest {
      */
     protected Path createEmptyArchive(final String archiveName) throws 
Exception {
         archiveList = new ArrayList<>();
-        archivePath = createTempPath("empty", "." + archiveName);
+        final Path archivePath = createTempPath("empty", "." + archiveName);
         try (OutputStream outputStream = Files.newOutputStream(archivePath);
                 ArchiveOutputStream<?> archiveOutputStream = 
factory.createArchiveOutputStream(archiveName, outputStream)) {
             archiveOutputStream.finish();
@@ -300,7 +295,7 @@ public abstract class AbstractTest extends 
AbstractTempDirTest {
      */
     protected Path createSingleEntryArchive(final String archiveName) throws 
Exception {
         archiveList = new ArrayList<>();
-        archivePath = createTempPath("empty", "." + archiveName);
+        final Path archivePath = createTempPath("empty", "." + archiveName);
         try (OutputStream outputStream = Files.newOutputStream(archivePath);
                 ArchiveOutputStream<?> archiveOutputStream = 
factory.createArchiveOutputStream(archiveName, outputStream)) {
             // Use short file name so does not cause problems for ar
@@ -331,16 +326,4 @@ public abstract class AbstractTest extends 
AbstractTempDirTest {
         }
     }
 
-    @BeforeEach
-    public void setUp() throws Exception {
-        archivePath = null;
-    }
-
-    @AfterEach
-    public void tearDown() throws Exception {
-        if (!forceDelete(archivePath)) {
-            // Note: this exception won't be shown if the test has already 
failed
-            throw new Exception("Could not delete " + archivePath);
-        }
-    }
 }
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/SevenZTest.java 
b/src/test/java/org/apache/commons/compress/archivers/SevenZTest.java
index 9aec40ed..aa16e5b5 100644
--- a/src/test/java/org/apache/commons/compress/archivers/SevenZTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/SevenZTest.java
@@ -44,6 +44,7 @@ public class SevenZTest extends AbstractTest {
     private static void assumeStrongCryptoIsAvailable() throws 
NoSuchAlgorithmException {
         assumeTrue(Cipher.getMaxAllowedKeyLength("AES/ECB/PKCS5Padding") >= 
256, "test requires strong crypto");
     }
+
     private File output;
 
     private final File file1, file2;
@@ -55,7 +56,7 @@ public class SevenZTest extends AbstractTest {
 
     private void copy(final File src, final SevenZOutputFile dst) throws 
IOException {
         try (InputStream fis = Files.newInputStream(src.toPath())) {
-            final byte[] buffer = new byte[8*1024];
+            final byte[] buffer = new byte[8 * 1024];
             int bytesRead;
             while ((bytesRead = fis.read(buffer)) >= 0) {
                 dst.write(buffer, 0, bytesRead);
@@ -82,8 +83,8 @@ public class SevenZTest extends AbstractTest {
 
     private void multiByteReadConsistentlyReturnsMinusOneAtEof(final 
SevenZFile archive) throws Exception {
         final byte[] buf = new byte[2];
-        SevenZArchiveEntry entry = archive.getNextEntry();
-        entry = archive.getNextEntry();
+        assertNotNull(archive.getNextEntry());
+        assertNotNull(archive.getNextEntry());
         readFully(archive);
         assertEquals(-1, archive.read(buf));
         assertEquals(-1, archive.read(buf));
@@ -104,16 +105,14 @@ public class SevenZTest extends AbstractTest {
         }
     }
 
-    @Override
     @BeforeEach
     public void setUp() throws Exception {
-        super.setUp();
         output = newTempFile("bla.7z");
     }
 
     private void singleByteReadConsistentlyReturnsMinusOneAtEof(final 
SevenZFile archive) throws Exception {
-        SevenZArchiveEntry entry = archive.getNextEntry();
-        entry = archive.getNextEntry();
+        assertNotNull(archive.getNextEntry());
+        assertNotNull(archive.getNextEntry());
         readFully(archive);
         assertEquals(-1, archive.read());
         assertEquals(-1, archive.read());
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java
index 1b9723d9..b4b6b3be 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java
@@ -123,7 +123,6 @@ public class ParameterizedArchiverTest extends AbstractTest 
{
     }
 
     public void setUp(final String format) throws Exception {
-        super.setUp();
         final File c = newTempFile("a/b/c");
         c.mkdirs();
         try (OutputStream os = 
Files.newOutputStream(newTempFile("a/b/d.txt").toPath())) {
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java
index 779fb747..ef65476f 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java
@@ -131,7 +131,6 @@ public class ParameterizedExpanderTest extends AbstractTest 
{
     }
 
     public void setUp(final String format) throws Exception {
-        super.setUp();
         archive = newTempFile("test." + format);
         final File dummy = newTempFile("x");
         try (OutputStream o = Files.newOutputStream(dummy.toPath())) {
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java
index 8627ee9b..81b80bbb 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java
@@ -64,9 +64,7 @@ public class SevenZArchiverTest extends AbstractTest {
     }
 
     @BeforeEach
-    @Override
     public void setUp() throws Exception {
-        super.setUp();
         final File c = newTempFile("a/b/c");
         c.mkdirs();
         try (OutputStream os = 
Files.newOutputStream(newTempFile("a/b/d.txt").toPath())) {

Reply via email to