You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/11/03 18:25:21 UTC

(commons-compress) branch master updated: Use JUnit to manage temporary directories for tests

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 e04f9906 Use JUnit to manage temporary directories for tests
e04f9906 is described below

commit e04f9906210eb3abadd20e15dc805ce711ecb247
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 3 14:25:15 2023 -0400

    Use JUnit to manage temporary directories for tests
---
 .../apache/commons/compress/AbstractTestCase.java  |  47 ++--
 .../commons/compress/archivers/ArTestCase.java     | 244 +++++++++------------
 .../commons/compress/archivers/CpioTestCase.java   | 191 +++++++---------
 .../commons/compress/archivers/DumpTestCase.java   |   2 +-
 .../commons/compress/archivers/JarTestCase.java    |  10 +-
 .../commons/compress/archivers/SevenZTestCase.java |   2 +-
 .../commons/compress/archivers/TarTestCase.java    | 180 ++++++---------
 .../commons/compress/archivers/ZipTestCase.java    | 136 ++++--------
 .../archivers/ar/ArArchiveOutputStreamTest.java    |  13 +-
 .../cpio/CpioArchiveOutputStreamTest.java          |   2 +-
 .../compress/archivers/examples/ExpanderTest.java  |  86 ++++----
 .../examples/ParameterizedArchiverTest.java        |  16 +-
 .../examples/ParameterizedExpanderTest.java        |  32 +--
 .../archivers/examples/SevenZArchiverTest.java     |  16 +-
 .../compress/archivers/sevenz/SevenZFileTest.java  |  10 +-
 .../archivers/sevenz/SevenZOutputFileTest.java     |  38 ++--
 .../commons/compress/archivers/tar/BigFilesIT.java |   2 +-
 .../compress/archivers/tar/SparseFilesTest.java    |   4 +-
 .../archivers/tar/TarArchiveInputStreamTest.java   |   6 +-
 .../compress/archivers/tar/TarFileTest.java        |   7 +-
 .../archivers/zip/X5455_ExtendedTimestampTest.java |   3 +-
 .../archivers/zip/ZipSplitOutputStreamTest.java    |  14 +-
 .../compress/changes/ChangeSetRawTypesTest.java    |  12 +-
 .../compress/changes/ChangeSetSafeTypesTest.java   |  12 +-
 .../compress/compressors/BZip2TestCase.java        |   6 +-
 .../compress/compressors/DeflateTestCase.java      |   8 +-
 .../compress/compressors/FramedSnappyTestCase.java |   8 +-
 .../commons/compress/compressors/GZipTestCase.java |   4 +-
 .../commons/compress/compressors/LZMATestCase.java |   6 +-
 .../compress/compressors/Pack200TestCase.java      |   6 +-
 .../commons/compress/compressors/XZTestCase.java   |   4 +-
 .../commons/compress/compressors/ZTestCase.java    |   2 +-
 .../brotli/BrotliCompressorInputStreamTest.java    |   2 +-
 .../lz4/BlockLZ4CompressorRoundtripTest.java       |   2 +-
 .../compress/compressors/lz4/FactoryTest.java      |   2 +-
 .../lz4/FramedLZ4CompressorRoundtripTest.java      |   2 +-
 .../compressors/pack200/Pack200UtilsTest.java      |  73 +++---
 .../FramedSnappyCompressorInputStreamTest.java     |   8 +-
 .../compressors/snappy/SnappyRoundtripTest.java    |   6 +-
 .../zstandard/ZstdCompressorInputStreamTest.java   |   2 +-
 .../compressors/zstandard/ZstdRoundtripTest.java   |   4 +-
 .../harmony/pack200/tests/ArchiveTest.java         |   2 +-
 42 files changed, 519 insertions(+), 713 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/AbstractTestCase.java b/src/test/java/org/apache/commons/compress/AbstractTestCase.java
index 72ce37f1..4ec6d703 100644
--- a/src/test/java/org/apache/commons/compress/AbstractTestCase.java
+++ b/src/test/java/org/apache/commons/compress/AbstractTestCase.java
@@ -98,19 +98,15 @@ public abstract class AbstractTestCase {
         return getFile(path).toPath();
     }
 
-    public static File mkdir(final String prefix) throws IOException {
-        return Files.createTempDirectory(prefix).toFile();
-    }
-
     public static InputStream newInputStream(final String path) throws IOException {
         return Files.newInputStream(getPath(path));
     }
 
     @TempDir
-    protected File dir;
+    protected File tempDirFile;
 
     @TempDir
-    protected File resultDir;
+    protected File tempResultDir;
 
     /** Used to delete the archive in {@link #tearDown()}. */
     private Path archivePath;
@@ -161,7 +157,7 @@ public abstract class AbstractTestCase {
      */
     protected File checkArchiveContent(final ArchiveInputStream<?> inputStream, final List<String> expected, final boolean cleanUp)
             throws Exception {
-        final File result = mkdir("dir-result");
+        final File result = createTempDirectory("dir-result");
         result.deleteOnExit();
 
         try {
@@ -321,28 +317,16 @@ public abstract class AbstractTestCase {
         return archivePath;
     }
 
-    protected File createTempDir() throws IOException {
-        final File tmpDir = mkdir("testdir");
-        tmpDir.deleteOnExit();
-        return tmpDir;
+    public File createTempDirectory(final String prefix) throws IOException {
+        return Files.createTempDirectory(getTempDirPath(), prefix).toFile();
     }
 
-    /**
-     * Creates a temporary directory and a temporary file inside that
-     * directory, returns both of them (the directory is the first
-     * element of the two element array).
-     *
-     * @return temporary directory and file pair.
-     * @throws IOException Some I/O error.
-     */
-    protected File[] createTempDirAndFile() throws IOException {
-        final File tmpDir = createTempDir();
-        final File tmpFile = File.createTempFile("testfile", "", tmpDir);
-        tmpFile.deleteOnExit();
-        try (OutputStream outputStream = Files.newOutputStream(tmpFile.toPath())) {
-            outputStream.write(new byte[] { 'f', 'o', 'o' });
-            return new File[] { tmpDir, tmpFile };
-        }
+    protected File createTempFile() throws IOException {
+        return File.createTempFile("testfile", "", getTempDirFile());
+    }
+
+    protected File createTempFile(final String prefix, final String suffix) throws IOException {
+        return File.createTempFile(prefix, suffix, getTempDirFile());
     }
 
     /**
@@ -356,6 +340,14 @@ public abstract class AbstractTestCase {
         return entry.getName();
     }
 
+    protected File getTempDirFile() {
+        return tempDirFile;
+    }
+
+    protected Path getTempDirPath() {
+        return tempDirFile.toPath();
+    }
+
     protected void setLongFileMode(final ArchiveOutputStream<?> outputStream) {
         if (outputStream instanceof ArArchiveOutputStream) {
             ((ArArchiveOutputStream) outputStream).setLongFileMode(ArArchiveOutputStream.LONGFILE_BSD);
@@ -369,7 +361,6 @@ public abstract class AbstractTestCase {
 
     @AfterEach
     public void tearDown() throws Exception {
-        dir = resultDir = null;
         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/ArTestCase.java b/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
index 4d9b56f8..a6812f6a 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
@@ -42,7 +42,7 @@ public final class ArTestCase extends AbstractTestCase {
 
     @Test
     public void testArArchiveCreation() throws Exception {
-        final File output = new File(dir, "bla.ar");
+        final File output = new File(getTempDirFile(), "bla.ar");
 
         final File file1 = getFile("test1.xml");
         final File file2 = getFile("test2.xml");
@@ -61,7 +61,7 @@ public final class ArTestCase extends AbstractTestCase {
 
     @Test
     public void testArDelete() throws Exception {
-        final File output = new File(dir, "bla.ar");
+        final File output = new File(getTempDirFile(), "bla.ar");
 
         final File file1 = getFile("test1.xml");
         final File file2 = getFile("test2.xml");
@@ -81,7 +81,7 @@ public final class ArTestCase extends AbstractTestCase {
 
         assertEquals(8 + 60 + file1.length() + file1.length() % 2 + 60 + file2.length() + file2.length() % 2, output.length());
 
-        final File output2 = new File(dir, "bla2.ar");
+        final File output2 = new File(getTempDirFile(), "bla2.ar");
 
         int copied = 0;
         int deleted = 0;
@@ -140,7 +140,7 @@ public final class ArTestCase extends AbstractTestCase {
 
     @Test
     public void testArUnarchive() throws Exception {
-        final File output = new File(dir, "bla.ar");
+        final File output = new File(getTempDirFile(), "bla.ar");
         {
             final File file1 = getFile("test1.xml");
             final File file2 = getFile("test2.xml");
@@ -162,182 +162,138 @@ public final class ArTestCase extends AbstractTestCase {
                 final ArchiveInputStream<ArArchiveEntry> in = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is))) {
             final ArArchiveEntry entry = in.getNextEntry();
 
-            final File target = new File(dir, entry.getName());
+            final File target = new File(getTempDirFile(), entry.getName());
             Files.copy(in, target.toPath());
         }
     }
 
     @Test
     public void testExplicitFileEntry() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
-        archive = File.createTempFile("test.", ".ar", tmp[0]);
-        archive.deleteOnExit();
-        try {
-            try (ArArchiveOutputStream aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-                final ArArchiveEntry in = new ArArchiveEntry("foo", tmp[1].length(), 0, 0, 0, tmp[1].lastModified() / 1000);
-                aos.putArchiveEntry(in);
-                final byte[] b = new byte[(int) tmp[1].length()];
-                try (InputStream fis = Files.newInputStream(tmp[1].toPath())) {
-                    while (fis.read(b) > 0) {
-                        aos.write(b);
-                    }
+        final File file = createTempFile();
+        final File archive = createTempFile("test.", ".ar");
+        try (ArArchiveOutputStream aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            final ArArchiveEntry in = new ArArchiveEntry("foo", file.length(), 0, 0, 0, file.lastModified() / 1000);
+            aos.putArchiveEntry(in);
+            final byte[] b = new byte[(int) file.length()];
+            try (InputStream fis = Files.newInputStream(file.toPath())) {
+                while (fis.read(b) > 0) {
+                    aos.write(b);
                 }
-                aos.closeArchiveEntry();
-            }
-            //
-            final ArArchiveEntry out;
-            try (ArArchiveInputStream ais = new ArArchiveInputStream(Files.newInputStream(archive.toPath()))) {
-                out = ais.getNextArEntry();
             }
-            assertNotNull(out);
-            assertEquals("foo", out.getName());
-            assertEquals(tmp[1].length(), out.getSize());
-            assertEquals(tmp[1].lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
-            assertFalse(out.isDirectory());
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
+            aos.closeArchiveEntry();
         }
+        //
+        final ArArchiveEntry out;
+        try (ArArchiveInputStream ais = new ArArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+            out = ais.getNextArEntry();
+        }
+        assertNotNull(out);
+        assertEquals("foo", out.getName());
+        assertEquals(file.length(), out.getSize());
+        assertEquals(file.lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
+        assertFalse(out.isDirectory());
     }
 
     @Test
     public void testFileEntryFromFile() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
-        final File directory = tmp[0];
-        final File file = tmp[1];
-        archive = File.createTempFile("test.", ".ar", directory);
-        archive.deleteOnExit();
-        try {
-            try (ArArchiveOutputStream aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-                final ArArchiveEntry in = new ArArchiveEntry(file, "foo");
-                aos.putArchiveEntry(in);
-                final byte[] b = new byte[(int) file.length()];
-                try (InputStream fis = Files.newInputStream(file.toPath())) {
-                    while (fis.read(b) > 0) {
-                        aos.write(b);
-                    }
+        final File file = createTempFile();
+        final File archive = createTempFile("test.", ".ar");
+        try (ArArchiveOutputStream aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            final ArArchiveEntry in = new ArArchiveEntry(file, "foo");
+            aos.putArchiveEntry(in);
+            final byte[] b = new byte[(int) file.length()];
+            try (InputStream fis = Files.newInputStream(file.toPath())) {
+                while (fis.read(b) > 0) {
+                    aos.write(b);
                 }
-                aos.closeArchiveEntry();
             }
-            final ArArchiveEntry out;
-            try (ArArchiveInputStream ais = new ArArchiveInputStream(Files.newInputStream(archive.toPath()))) {
-                out = ais.getNextArEntry();
-            }
-            assertNotNull(out);
-            assertEquals("foo", out.getName());
-            assertEquals(file.length(), out.getSize());
-            // AR stores time with a granularity of 1 second
-            assertEquals(file.lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
-            assertFalse(out.isDirectory());
-        } finally {
-            forceDelete(archive);
-            forceDelete(file);
-            forceDelete(directory);
+            aos.closeArchiveEntry();
+        }
+        final ArArchiveEntry out;
+        try (ArArchiveInputStream ais = new ArArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+            out = ais.getNextArEntry();
         }
+        assertNotNull(out);
+        assertEquals("foo", out.getName());
+        assertEquals(file.length(), out.getSize());
+        // AR stores time with a granularity of 1 second
+        assertEquals(file.lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
+        assertFalse(out.isDirectory());
     }
 
     @Test
     public void testFileEntryFromPath() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
-        final File directory = tmp[0];
-        final File file = tmp[1];
-        archive = File.createTempFile("test.", ".ar", directory);
-        archive.deleteOnExit();
-        try {
-            try (ArArchiveOutputStream aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-                final ArArchiveEntry in = new ArArchiveEntry(file.toPath(), "foo");
-                aos.putArchiveEntry(in);
-                final byte[] b = new byte[(int) file.length()];
-                try (InputStream fis = Files.newInputStream(file.toPath())) {
-                    while (fis.read(b) > 0) {
-                        aos.write(b);
-                    }
+        final File file = createTempFile();
+        final File archive = createTempFile("test.", ".ar");
+        try (ArArchiveOutputStream aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            final ArArchiveEntry in = new ArArchiveEntry(file.toPath(), "foo");
+            aos.putArchiveEntry(in);
+            final byte[] b = new byte[(int) file.length()];
+            try (InputStream fis = Files.newInputStream(file.toPath())) {
+                while (fis.read(b) > 0) {
+                    aos.write(b);
                 }
-                aos.closeArchiveEntry();
-            }
-            final ArArchiveEntry out;
-            try (ArArchiveInputStream ais = new ArArchiveInputStream(Files.newInputStream(archive.toPath()))) {
-                out = ais.getNextArEntry();
             }
-            assertNotNull(out);
-            assertEquals("foo", out.getName());
-            assertEquals(file.length(), out.getSize());
-            // AR stores time with a granularity of 1 second
-            assertEquals(file.lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
-            assertFalse(out.isDirectory());
-        } finally {
-            forceDelete(archive);
-            forceDelete(file);
-            forceDelete(directory);
+            aos.closeArchiveEntry();
         }
+        final ArArchiveEntry out;
+        try (ArArchiveInputStream ais = new ArArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+            out = ais.getNextArEntry();
+        }
+        assertNotNull(out);
+        assertEquals("foo", out.getName());
+        assertEquals(file.length(), out.getSize());
+        // AR stores time with a granularity of 1 second
+        assertEquals(file.lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
+        assertFalse(out.isDirectory());
     }
 
     // TODO: revisit - does AR not support storing directories?
     @Disabled
     @Test
     public void testXtestDirectoryEntryFromFile() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
-        archive = File.createTempFile("test.", ".ar", tmp[0]);
-        archive.deleteOnExit();
-        try {
-            final long beforeArchiveWrite;
-            try (ArArchiveOutputStream aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-                beforeArchiveWrite = tmp[0].lastModified();
-                final ArArchiveEntry in = new ArArchiveEntry(tmp[0], "foo");
-                aos.putArchiveEntry(in);
-                aos.closeArchiveEntry();
-            }
-            final ArArchiveEntry out;
-            try (ArArchiveInputStream ais = new ArArchiveInputStream(Files.newInputStream(archive.toPath()))) {
-                out = ais.getNextArEntry();
-            }
-            assertNotNull(out);
-            assertEquals("foo/", out.getName());
-            assertEquals(0, out.getSize());
-            // AR stores time with a granularity of 1 second
-            assertEquals(beforeArchiveWrite / 1000, out.getLastModifiedDate().getTime() / 1000);
-            assertTrue(out.isDirectory());
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
+        final File tmp = createTempFile();
+        final File archive = createTempFile("test.", ".ar");
+        final long beforeArchiveWrite;
+        try (ArArchiveOutputStream aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            beforeArchiveWrite = tmp.lastModified();
+            final ArArchiveEntry in = new ArArchiveEntry(tmp, "foo");
+            aos.putArchiveEntry(in);
+            aos.closeArchiveEntry();
+        }
+        final ArArchiveEntry out;
+        try (ArArchiveInputStream ais = new ArArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+            out = ais.getNextArEntry();
         }
+        assertNotNull(out);
+        assertEquals("foo/", out.getName());
+        assertEquals(0, out.getSize());
+        // AR stores time with a granularity of 1 second
+        assertEquals(beforeArchiveWrite / 1000, out.getLastModifiedDate().getTime() / 1000);
+        assertTrue(out.isDirectory());
     }
 
     // TODO: revisit - does AR not support storing directories?
     @Disabled
     @Test
     public void testXtestExplicitDirectoryEntry() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
-        archive = File.createTempFile("test.", ".ar", tmp[0]);
-        archive.deleteOnExit();
-        try {
-            final long beforeArchiveWrite;
-            try (ArArchiveOutputStream aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-                beforeArchiveWrite = tmp[0].lastModified();
-                final ArArchiveEntry in = new ArArchiveEntry("foo", 0, 0, 0, 0, tmp[1].lastModified() / 1000);
-                aos.putArchiveEntry(in);
-                aos.closeArchiveEntry();
-            }
-            final ArArchiveEntry out;
-            try (ArArchiveInputStream ais = new ArArchiveInputStream(Files.newInputStream(archive.toPath()))) {
-                out = ais.getNextArEntry();
-            }
-            assertNotNull(out);
-            assertEquals("foo/", out.getName());
-            assertEquals(0, out.getSize());
-            assertEquals(beforeArchiveWrite / 1000, out.getLastModifiedDate().getTime() / 1000);
-            assertTrue(out.isDirectory());
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
+        final File tmp = createTempFile();
+        final File archive = createTempFile("test.", ".ar");
+        final long beforeArchiveWrite;
+        try (ArArchiveOutputStream aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            beforeArchiveWrite = getTempDirFile().lastModified();
+            final ArArchiveEntry in = new ArArchiveEntry("foo", 0, 0, 0, 0, tmp.lastModified() / 1000);
+            aos.putArchiveEntry(in);
+            aos.closeArchiveEntry();
+        }
+        final ArArchiveEntry out;
+        try (ArArchiveInputStream ais = new ArArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+            out = ais.getNextArEntry();
         }
+        assertNotNull(out);
+        assertEquals("foo/", out.getName());
+        assertEquals(0, out.getSize());
+        assertEquals(beforeArchiveWrite / 1000, out.getLastModifiedDate().getTime() / 1000);
+        assertTrue(out.isDirectory());
     }
 }
diff --git a/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java b/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java
index e582cc8b..f0f30a2f 100644
--- a/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java
@@ -41,7 +41,7 @@ public final class CpioTestCase extends AbstractTestCase {
 
     @Test
     public void testCpioArchiveCreation() throws Exception {
-        final File output = new File(dir, "bla.cpio");
+        final File output = new File(getTempDirFile(), "bla.cpio");
 
         final File file1 = getFile("test1.xml");
         final File file2 = getFile("test2.xml");
@@ -61,7 +61,7 @@ public final class CpioTestCase extends AbstractTestCase {
 
     @Test
     public void testCpioUnarchive() throws Exception {
-        final File output = new File(dir, "bla.cpio");
+        final File output = new File(getTempDirFile(), "bla.cpio");
         final File file1 = getFile("test1.xml");
         final File file2 = getFile("test2.xml");
         final long file1Length = file1.length();
@@ -91,7 +91,7 @@ public final class CpioTestCase extends AbstractTestCase {
                 ArchiveInputStream<?> archiveInputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("cpio", inputStream)) {
             ArchiveEntry entry;
             while ((entry = archiveInputStream.getNextEntry()) != null) {
-                final File cpioget = new File(dir, entry.getName());
+                final File cpioget = new File(getTempDirFile(), entry.getName());
                 Files.copy(archiveInputStream, cpioget.toPath());
                 result.put(entry.getName(), cpioget);
             }
@@ -108,134 +108,101 @@ public final class CpioTestCase extends AbstractTestCase {
 
     @Test
     public void testDirectoryEntryFromFile() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
-        archive = File.createTempFile("test.", ".cpio", tmp[0]);
-        archive.deleteOnExit();
-        final long beforeArchiveWrite = tmp[0].lastModified();
-        final CpioArchiveEntry entryIn = new CpioArchiveEntry(tmp[0], "foo");
-        try {
-            try (CpioArchiveOutputStream tos = new CpioArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-                tos.putArchiveEntry(entryIn);
-                tos.closeArchiveEntry();
-            }
-            final CpioArchiveEntry entryOut;
-            try (CpioArchiveInputStream tis = new CpioArchiveInputStream(Files.newInputStream(archive.toPath()))) {
-                entryOut = tis.getNextCPIOEntry();
-            }
-            assertNotNull(entryOut);
-            assertEquals("foo", entryOut.getName());
-            assertEquals(0, entryOut.getSize());
-            // CPIO stores time with a granularity of 1 second
-            assertEquals(beforeArchiveWrite / 1000, entryOut.getLastModifiedDate().getTime() / 1000);
-            assertTrue(entryOut.isDirectory());
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
+        final File archive = createTempFile("test.", ".cpio");
+        final File dir = getTempDirFile();
+        final long beforeArchiveWrite = dir.lastModified();
+        final CpioArchiveEntry entryIn = new CpioArchiveEntry(dir, "foo");
+        try (CpioArchiveOutputStream tos = new CpioArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            tos.putArchiveEntry(entryIn);
+            tos.closeArchiveEntry();
+        }
+        final CpioArchiveEntry entryOut;
+        try (CpioArchiveInputStream tis = new CpioArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+            entryOut = tis.getNextCPIOEntry();
         }
+        assertNotNull(entryOut);
+        assertEquals("foo", entryOut.getName());
+        assertEquals(0, entryOut.getSize());
+        // CPIO stores time with a granularity of 1 second
+        assertEquals(beforeArchiveWrite / 1000, entryOut.getLastModifiedDate().getTime() / 1000);
+        assertTrue(entryOut.isDirectory());
     }
 
     @Test
     public void testExplicitDirectoryEntry() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
-        archive = File.createTempFile("test.", ".cpio", tmp[0]);
-        archive.deleteOnExit();
-        try {
-            final long beforeArchiveWrite;
-            try (CpioArchiveOutputStream tos = new CpioArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-                beforeArchiveWrite = tmp[0].lastModified();
-                final CpioArchiveEntry in = new CpioArchiveEntry("foo/");
-                in.setTime(beforeArchiveWrite / 1000);
-                in.setMode(CpioConstants.C_ISDIR);
-                tos.putArchiveEntry(in);
-                tos.closeArchiveEntry();
-            }
-            final CpioArchiveEntry out;
-            try (CpioArchiveInputStream tis = new CpioArchiveInputStream(Files.newInputStream(archive.toPath()))) {
-                out = tis.getNextCPIOEntry();
-            }
-            assertNotNull(out);
-            assertEquals("foo/", out.getName());
-            assertEquals(0, out.getSize());
-            assertEquals(beforeArchiveWrite / 1000, out.getLastModifiedDate().getTime() / 1000);
-            assertTrue(out.isDirectory());
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
+        final File archive = createTempFile("test.", ".cpio");
+        final long beforeArchiveWrite;
+        try (CpioArchiveOutputStream tos = new CpioArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            beforeArchiveWrite = getTempDirFile().lastModified();
+            final CpioArchiveEntry in = new CpioArchiveEntry("foo/");
+            in.setTime(beforeArchiveWrite / 1000);
+            in.setMode(CpioConstants.C_ISDIR);
+            tos.putArchiveEntry(in);
+            tos.closeArchiveEntry();
         }
+        final CpioArchiveEntry out;
+        try (CpioArchiveInputStream tis = new CpioArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+            out = tis.getNextCPIOEntry();
+        }
+        assertNotNull(out);
+        assertEquals("foo/", out.getName());
+        assertEquals(0, out.getSize());
+        assertEquals(beforeArchiveWrite / 1000, out.getLastModifiedDate().getTime() / 1000);
+        assertTrue(out.isDirectory());
     }
 
     @Test
     public void testExplicitFileEntry() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
-        try {
-            archive = File.createTempFile("test.", ".cpio", tmp[0]);
-            archive.deleteOnExit();
-            try (CpioArchiveOutputStream tos = new CpioArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-                final CpioArchiveEntry in = new CpioArchiveEntry("foo");
-                in.setTime(tmp[1].lastModified() / 1000);
-                in.setSize(tmp[1].length());
-                in.setMode(CpioConstants.C_ISREG);
-                tos.putArchiveEntry(in);
-                final byte[] b = new byte[(int) tmp[1].length()];
-                try (InputStream fis = Files.newInputStream(tmp[1].toPath())) {
-                    while (fis.read(b) > 0) {
-                        tos.write(b);
-                    }
+        final File tmp = createTempFile();
+        final File archive = createTempFile("test.", ".cpio");
+        try (CpioArchiveOutputStream tos = new CpioArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            final CpioArchiveEntry in = new CpioArchiveEntry("foo");
+            in.setTime(tmp.lastModified() / 1000);
+            in.setSize(tmp.length());
+            in.setMode(CpioConstants.C_ISREG);
+            tos.putArchiveEntry(in);
+            final byte[] b = new byte[(int) tmp.length()];
+            try (InputStream fis = Files.newInputStream(tmp.toPath())) {
+                while (fis.read(b) > 0) {
+                    tos.write(b);
                 }
-                tos.closeArchiveEntry();
-            }
-            final CpioArchiveEntry out;
-            try (CpioArchiveInputStream tis = new CpioArchiveInputStream(Files.newInputStream(archive.toPath()))) {
-                out = tis.getNextCPIOEntry();
             }
-            assertNotNull(out);
-            assertEquals("foo", out.getName());
-            assertEquals(tmp[1].length(), out.getSize());
-            assertEquals(tmp[1].lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
-            assertFalse(out.isDirectory());
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
+            tos.closeArchiveEntry();
+        }
+        final CpioArchiveEntry out;
+        try (CpioArchiveInputStream tis = new CpioArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+            out = tis.getNextCPIOEntry();
         }
+        assertNotNull(out);
+        assertEquals("foo", out.getName());
+        assertEquals(tmp.length(), out.getSize());
+        assertEquals(tmp.lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
+        assertFalse(out.isDirectory());
     }
 
     @Test
     public void testFileEntryFromFile() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
-        try {
-            archive = File.createTempFile("test.", ".cpio", tmp[0]);
-            archive.deleteOnExit();
-            try (CpioArchiveOutputStream tos = new CpioArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-                final CpioArchiveEntry in = new CpioArchiveEntry(tmp[1], "foo");
-                tos.putArchiveEntry(in);
-                final byte[] b = new byte[(int) tmp[1].length()];
-                try (InputStream fis = Files.newInputStream(tmp[1].toPath())) {
-                    while (fis.read(b) > 0) {
-                        tos.write(b);
-                    }
+        final File tmp = createTempFile();
+        final File archive = createTempFile("test.", ".cpio");
+        try (CpioArchiveOutputStream tos = new CpioArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            final CpioArchiveEntry in = new CpioArchiveEntry(tmp, "foo");
+            tos.putArchiveEntry(in);
+            final byte[] b = new byte[(int) tmp.length()];
+            try (InputStream fis = Files.newInputStream(tmp.toPath())) {
+                while (fis.read(b) > 0) {
+                    tos.write(b);
                 }
-                tos.closeArchiveEntry();
             }
-            final CpioArchiveEntry out;
-            try (CpioArchiveInputStream tis = new CpioArchiveInputStream(Files.newInputStream(archive.toPath()))) {
-                out = tis.getNextCPIOEntry();
-            }
-            assertNotNull(out);
-            assertEquals("foo", out.getName());
-            assertEquals(tmp[1].length(), out.getSize());
-            assertEquals(tmp[1].lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
-            assertFalse(out.isDirectory());
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
+            tos.closeArchiveEntry();
+        }
+        final CpioArchiveEntry out;
+        try (CpioArchiveInputStream tis = new CpioArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+            out = tis.getNextCPIOEntry();
         }
+        assertNotNull(out);
+        assertEquals("foo", out.getName());
+        assertEquals(tmp.length(), out.getSize());
+        assertEquals(tmp.lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
+        assertFalse(out.isDirectory());
     }
 }
diff --git a/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java b/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java
index f88cd0b0..1500ce04 100644
--- a/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java
@@ -87,7 +87,7 @@ public final class DumpTestCase extends AbstractTestCase {
                 ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("dump", is)) {
             ArchiveEntry entry = in.getNextEntry();
             while (entry != null) {
-                final File archiveEntry = new File(dir, entry.getName());
+                final File archiveEntry = new File(getTempDirFile(), entry.getName());
                 archiveEntry.getParentFile().mkdirs();
                 if (entry.isDirectory()) {
                     archiveEntry.mkdir();
diff --git a/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java b/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java
index 4dcce2d7..be255bcd 100644
--- a/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java
@@ -32,7 +32,7 @@ public final class JarTestCase extends AbstractTestCase {
 
     @Test
     public void testJarArchiveCreation() throws Exception {
-        final File output = new File(dir, "bla.jar");
+        final File output = new File(getTempDirFile(), "bla.jar");
 
         final File file1 = getFile("test1.xml");
         final File file2 = getFile("test2.xml");
@@ -57,17 +57,17 @@ public final class JarTestCase extends AbstractTestCase {
                 ZipArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
 
             ZipArchiveEntry entry = in.getNextEntry();
-            File o = new File(dir, entry.getName());
+            File o = new File(getTempDirFile(), entry.getName());
             o.getParentFile().mkdirs();
             Files.copy(in, o.toPath());
 
             entry = in.getNextEntry();
-            o = new File(dir, entry.getName());
+            o = new File(getTempDirFile(), entry.getName());
             o.getParentFile().mkdirs();
             Files.copy(in, o.toPath());
 
             entry = in.getNextEntry();
-            o = new File(dir, entry.getName());
+            o = new File(getTempDirFile(), entry.getName());
             o.getParentFile().mkdirs();
             Files.copy(in, o.toPath());
         }
@@ -81,7 +81,7 @@ public final class JarTestCase extends AbstractTestCase {
 
             ArchiveEntry entry = in.getNextEntry();
             while (entry != null) {
-                final File archiveEntry = new File(dir, entry.getName());
+                final File archiveEntry = new File(getTempDirFile(), entry.getName());
                 archiveEntry.getParentFile().mkdirs();
                 if (entry.isDirectory()) {
                     archiveEntry.mkdir();
diff --git a/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java b/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java
index f87266b8..9d80ebfb 100644
--- a/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/SevenZTestCase.java
@@ -108,7 +108,7 @@ public class SevenZTestCase extends AbstractTestCase {
     @BeforeEach
     public void setUp() throws Exception {
         super.setUp();
-        output = new File(dir, "bla.7z");
+        output = new File(getTempDirFile(), "bla.7z");
     }
 
     private void singleByteReadConsistentlyReturnsMinusOneAtEof(final SevenZFile archive) throws Exception {
diff --git a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java
index e241dd9e..bc0c272d 100644
--- a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java
@@ -73,7 +73,7 @@ public final class TarTestCase extends AbstractTestCase {
     public void testCOMPRESS114() throws Exception {
         final File input = getFile("COMPRESS-114.tar");
         try (final InputStream is = Files.newInputStream(input.toPath());
-             final TarArchiveInputStream in = new TarArchiveInputStream(is, CharsetNames.ISO_8859_1)) {
+                final TarArchiveInputStream in = new TarArchiveInputStream(is, CharsetNames.ISO_8859_1)) {
             TarArchiveEntry entry = in.getNextEntry();
             assertEquals("3\u00b1\u00b1\u00b1F06\u00b1W2345\u00b1ZB\u00b1la\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1BLA", entry.getName());
             assertEquals(TarConstants.LF_NORMAL, entry.getLinkFlag());
@@ -105,16 +105,14 @@ public final class TarTestCase extends AbstractTestCase {
 
     @Test
     public void testDirectoryEntryFromFile() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
         TarArchiveOutputStream tos = null;
         TarArchiveInputStream tis = null;
         try {
-            archive = File.createTempFile("test.", ".tar", tmp[0]);
-            archive.deleteOnExit();
+            final File archive = createTempFile("test.", ".tar");
             tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()));
-            final long beforeArchiveWrite = tmp[0].lastModified();
-            final TarArchiveEntry in = new TarArchiveEntry(tmp[0], "foo");
+            final File dir = getTempDirFile();
+            final long beforeArchiveWrite = dir.lastModified();
+            final TarArchiveEntry in = new TarArchiveEntry(dir, "foo");
             tos.putArchiveEntry(in);
             tos.closeArchiveEntry();
             tos.close();
@@ -128,8 +126,7 @@ public final class TarTestCase extends AbstractTestCase {
             assertEquals(TarConstants.LF_DIR, out.getLinkFlag());
             assertEquals(0, out.getSize());
             // TAR stores time with a granularity of 1 second
-            assertEquals(beforeArchiveWrite / 1000,
-                         out.getLastModifiedDate().getTime() / 1000);
+            assertEquals(beforeArchiveWrite / 1000, out.getLastModifiedDate().getTime() / 1000);
             assertTrue(out.isDirectory());
         } finally {
             if (tis != null) {
@@ -138,9 +135,6 @@ public final class TarTestCase extends AbstractTestCase {
             if (tos != null) {
                 tos.close();
             }
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
         }
     }
 
@@ -148,7 +142,7 @@ public final class TarTestCase extends AbstractTestCase {
     public void testDirectoryRead() throws IOException {
         final File input = getFile("directory.tar");
         try (final InputStream is = Files.newInputStream(input.toPath());
-             final TarArchiveInputStream in = new TarArchiveInputStream(is)) {
+                final TarArchiveInputStream in = new TarArchiveInputStream(is)) {
             final TarArchiveEntry directoryEntry = in.getNextTarEntry();
             assertEquals("directory/", directoryEntry.getName());
             assertEquals(TarConstants.LF_DIR, directoryEntry.getLinkFlag());
@@ -160,15 +154,13 @@ public final class TarTestCase extends AbstractTestCase {
 
     @Test
     public void testExplicitDirectoryEntry() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
         TarArchiveOutputStream tos = null;
         TarArchiveInputStream tis = null;
         try {
-            archive = File.createTempFile("test.", ".tar", tmp[0]);
+            final File archive = createTempFile("test.", ".tar");
             archive.deleteOnExit();
             tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()));
-            final long beforeArchiveWrite = tmp[0].lastModified();
+            final long beforeArchiveWrite = getTempDirFile().lastModified();
             final TarArchiveEntry in = new TarArchiveEntry("foo/");
             in.setModTime(beforeArchiveWrite);
             tos.putArchiveEntry(in);
@@ -183,8 +175,7 @@ public final class TarTestCase extends AbstractTestCase {
             assertEquals("foo/", out.getName());
             assertEquals(TarConstants.LF_DIR, in.getLinkFlag());
             assertEquals(0, out.getSize());
-            assertEquals(beforeArchiveWrite / 1000,
-                         out.getLastModifiedDate().getTime() / 1000);
+            assertEquals(beforeArchiveWrite / 1000, out.getLastModifiedDate().getTime() / 1000);
             assertTrue(out.isDirectory());
         } finally {
             if (tis != null) {
@@ -193,28 +184,24 @@ public final class TarTestCase extends AbstractTestCase {
             if (tos != null) {
                 tos.close();
             }
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
         }
     }
 
     @Test
     public void testExplicitFileEntry() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
+        final File tmp = createTempFile();
         TarArchiveOutputStream tos = null;
         TarArchiveInputStream tis = null;
         try {
-            archive = File.createTempFile("test.", ".tar", tmp[0]);
+            final File archive = createTempFile("test.", ".tar");
             archive.deleteOnExit();
             tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()));
             final TarArchiveEntry entryIn = new TarArchiveEntry("foo");
-            entryIn.setModTime(tmp[1].lastModified());
-            entryIn.setSize(tmp[1].length());
+            entryIn.setModTime(tmp.lastModified());
+            entryIn.setSize(tmp.length());
             tos.putArchiveEntry(entryIn);
-            final byte[] b = new byte[(int) tmp[1].length()];
-            try (InputStream fis = Files.newInputStream(tmp[1].toPath())) {
+            final byte[] b = new byte[(int) tmp.length()];
+            try (InputStream fis = Files.newInputStream(tmp.toPath())) {
                 while (fis.read(b) > 0) {
                     tos.write(b);
                 }
@@ -229,8 +216,8 @@ public final class TarTestCase extends AbstractTestCase {
             assertNotNull(entryOut);
             assertEquals("foo", entryOut.getName());
             assertEquals(TarConstants.LF_NORMAL, entryOut.getLinkFlag());
-            assertEquals(tmp[1].length(), entryOut.getSize());
-            assertEquals(tmp[1].lastModified() / 1000, entryOut.getLastModifiedDate().getTime() / 1000);
+            assertEquals(tmp.length(), entryOut.getSize());
+            assertEquals(tmp.lastModified() / 1000, entryOut.getLastModifiedDate().getTime() / 1000);
             assertFalse(entryOut.isDirectory());
         } finally {
             if (tis != null) {
@@ -239,45 +226,34 @@ public final class TarTestCase extends AbstractTestCase {
             if (tos != null) {
                 tos.close();
             }
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
         }
     }
 
     @Test
     public void testFileEntryFromFile() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
-        archive = File.createTempFile("test.", ".tar", tmp[0]);
-        archive.deleteOnExit();
-        final TarArchiveEntry in = new TarArchiveEntry(tmp[1], "foo");
-        try {
-            try (TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-                tos.putArchiveEntry(in);
-                final byte[] b = new byte[(int) tmp[1].length()];
-                try (InputStream fis = Files.newInputStream(tmp[1].toPath())) {
-                    while (fis.read(b) > 0) {
-                        tos.write(b);
-                    }
+        final File tmp = createTempFile();
+        final File archive = createTempFile("test.", ".tar");
+        final TarArchiveEntry in = new TarArchiveEntry(tmp, "foo");
+        try (TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            tos.putArchiveEntry(in);
+            final byte[] b = new byte[(int) tmp.length()];
+            try (InputStream fis = Files.newInputStream(tmp.toPath())) {
+                while (fis.read(b) > 0) {
+                    tos.write(b);
                 }
-                tos.closeArchiveEntry();
-            }
-            final TarArchiveEntry out;
-            try (TarArchiveInputStream tis = new TarArchiveInputStream(Files.newInputStream(archive.toPath()))) {
-                out = tis.getNextTarEntry();
             }
-            assertNotNull(out);
-            assertEquals("foo", out.getName());
-            assertEquals(TarConstants.LF_NORMAL, out.getLinkFlag());
-            assertEquals(tmp[1].length(), out.getSize());
-            assertEquals(tmp[1].lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
-            assertFalse(out.isDirectory());
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
+            tos.closeArchiveEntry();
+        }
+        final TarArchiveEntry out;
+        try (TarArchiveInputStream tis = new TarArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+            out = tis.getNextTarEntry();
         }
+        assertNotNull(out);
+        assertEquals("foo", out.getName());
+        assertEquals(TarConstants.LF_NORMAL, out.getLinkFlag());
+        assertEquals(tmp.length(), out.getSize());
+        assertEquals(tmp.lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
+        assertFalse(out.isDirectory());
     }
 
     @Test
@@ -289,7 +265,7 @@ public final class TarTestCase extends AbstractTestCase {
             assertEquals(length.intValue(), fileName.length());
             final byte[] data = createTarWithOneLongNameEntry(fileName);
             try (final ByteArrayInputStream bis = new ByteArrayInputStream(data);
-                 final TarArchiveInputStream tis = new TarArchiveInputStream(bis)) {
+                    final TarArchiveInputStream tis = new TarArchiveInputStream(bis)) {
                 assertEquals(fileName, tis.getNextTarEntry().getName());
             }
         }
@@ -297,7 +273,7 @@ public final class TarTestCase extends AbstractTestCase {
 
     @Test
     public void testTarArchiveCreation() throws Exception {
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         final File file1 = getFile("test1.xml");
         try (OutputStream out = Files.newOutputStream(output.toPath());
                 TarArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", out)) {
@@ -321,7 +297,7 @@ public final class TarTestCase extends AbstractTestCase {
         final byte[] bytes = name.getBytes(UTF_8);
         assertEquals(bytes.length, 99);
 
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         final File file1 = getFile("test1.xml");
         final TarArchiveEntry entry = new TarArchiveEntry(name);
         try (OutputStream out = Files.newOutputStream(output.toPath());
@@ -339,7 +315,7 @@ public final class TarTestCase extends AbstractTestCase {
         }
 
         final String toLongName = "testdata/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567.xml";
-        final File output2 = new File(dir, "bla.tar");
+        final File output2 = new File(getTempDirFile(), "bla.tar");
         try (OutputStream out2 = Files.newOutputStream(output2.toPath());
                 TarArchiveOutputStream os2 = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", out2);) {
             final TarArchiveEntry entry2 = new TarArchiveEntry(toLongName);
@@ -394,13 +370,11 @@ public final class TarTestCase extends AbstractTestCase {
 
     @Test
     public void testTarFileDirectoryEntryFromFile() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        final File archive = File.createTempFile("test.", ".tar", tmp[0]);
-        archive.deleteOnExit();
-
+        final File archive = createTempFile("test.", ".tar");
+        final File dir = getTempDirFile();
         try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-            final long beforeArchiveWrite = tmp[0].lastModified();
-            final TarArchiveEntry in = new TarArchiveEntry(tmp[0], "foo");
+            final long beforeArchiveWrite = dir.lastModified();
+            final TarArchiveEntry in = new TarArchiveEntry(dir, "foo");
             tos.putArchiveEntry(in);
             tos.closeArchiveEntry();
             tos.close();
@@ -413,10 +387,6 @@ public final class TarTestCase extends AbstractTestCase {
                 // TAR stores time with a granularity of 1 second
                 assertEquals(beforeArchiveWrite / 1000, entry.getLastModifiedDate().getTime() / 1000);
                 assertTrue(entry.isDirectory());
-            } finally {
-                forceDelete(archive);
-                forceDelete(tmp[1]);
-                forceDelete(tmp[0]);
             }
         }
     }
@@ -438,14 +408,13 @@ public final class TarTestCase extends AbstractTestCase {
 
     @Test
     public void testTarFileEntryFromFile() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        final File archive = File.createTempFile("test.", ".tar", tmp[0]);
-        archive.deleteOnExit();
+        final File tmp = createTempFile();
+        final File archive = createTempFile("test.", ".tar");
         try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
-            final TarArchiveEntry in = new TarArchiveEntry(tmp[1], "foo");
+            final TarArchiveEntry in = new TarArchiveEntry(tmp, "foo");
             tos.putArchiveEntry(in);
-            final byte[] b = new byte[(int) tmp[1].length()];
-            try (final InputStream fis = Files.newInputStream(tmp[1].toPath())) {
+            final byte[] b = new byte[(int) tmp.length()];
+            try (final InputStream fis = Files.newInputStream(tmp.toPath())) {
                 while (fis.read(b) > 0) {
                     tos.write(b);
                 }
@@ -457,24 +426,18 @@ public final class TarTestCase extends AbstractTestCase {
                 assertNotNull(entry);
                 assertEquals("foo", entry.getName());
                 assertEquals(TarConstants.LF_NORMAL, entry.getLinkFlag());
-                assertEquals(tmp[1].length(), entry.getSize());
-                assertEquals(tmp[1].lastModified() / 1000, entry.getLastModifiedDate().getTime() / 1000);
+                assertEquals(tmp.length(), entry.getSize());
+                assertEquals(tmp.lastModified() / 1000, entry.getLastModifiedDate().getTime() / 1000);
                 assertFalse(entry.isDirectory());
             }
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
         }
     }
 
     @Test
     public void testTarFileExplicitDirectoryEntry() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        final File archive = File.createTempFile("test.", ".tar", tmp[0]);
-        archive.deleteOnExit();
-        try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))){
-            final long beforeArchiveWrite = tmp[0].lastModified();
+        final File archive = createTempFile("test.", ".tar");
+        try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+            final long beforeArchiveWrite = getTempDirFile().lastModified();
             final TarArchiveEntry in = new TarArchiveEntry("foo/");
             in.setModTime(beforeArchiveWrite);
             tos.putArchiveEntry(in);
@@ -489,25 +452,20 @@ public final class TarTestCase extends AbstractTestCase {
                 assertEquals(beforeArchiveWrite / 1000, entry.getLastModifiedDate().getTime() / 1000);
                 assertTrue(entry.isDirectory());
             }
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
         }
     }
 
     @Test
     public void testTarFileExplicitFileEntry() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        final File archive = File.createTempFile("test.", ".tar", tmp[0]);
-        archive.deleteOnExit();
-        try (final TarArchiveOutputStream tos  = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))){
+        final File tmp = createTempFile();
+        final File archive = createTempFile("test.", ".tar");
+        try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
             final TarArchiveEntry in = new TarArchiveEntry("foo");
-            in.setModTime(tmp[1].lastModified());
-            in.setSize(tmp[1].length());
+            in.setModTime(tmp.lastModified());
+            in.setSize(tmp.length());
             tos.putArchiveEntry(in);
-            final byte[] b = new byte[(int) tmp[1].length()];
-            try (final InputStream fis = Files.newInputStream(tmp[1].toPath())) {
+            final byte[] b = new byte[(int) tmp.length()];
+            try (final InputStream fis = Files.newInputStream(tmp.toPath())) {
                 while (fis.read(b) > 0) {
                     tos.write(b);
                 }
@@ -519,14 +477,10 @@ public final class TarTestCase extends AbstractTestCase {
                 assertNotNull(entry);
                 assertEquals("foo", entry.getName());
                 assertEquals(TarConstants.LF_NORMAL, entry.getLinkFlag());
-                assertEquals(tmp[1].length(), entry.getSize());
-                assertEquals(tmp[1].lastModified() / 1000, entry.getLastModifiedDate().getTime() / 1000);
+                assertEquals(tmp.length(), entry.getSize());
+                assertEquals(tmp.lastModified() / 1000, entry.getLastModifiedDate().getTime() / 1000);
                 assertFalse(entry.isDirectory());
             }
-        } finally {
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
         }
     }
 
@@ -552,7 +506,7 @@ public final class TarTestCase extends AbstractTestCase {
         try (TarFile tarFile = new TarFile(file)) {
             TarArchiveEntry entry = tarFile.getEntries().get(0);
             try (InputStream inputStream = tarFile.getInputStream(entry)) {
-                Files.copy(inputStream, new File(dir, entry.getName()).toPath());
+                Files.copy(inputStream, new File(getTempDirFile(), entry.getName()).toPath());
             }
         }
     }
@@ -563,7 +517,7 @@ public final class TarTestCase extends AbstractTestCase {
         try (final InputStream is = Files.newInputStream(input.toPath());
                 final TarArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
             final TarArchiveEntry entry = in.getNextEntry();
-            Files.copy(in, new File(dir, entry.getName()).toPath());
+            Files.copy(in, new File(getTempDirFile(), entry.getName()).toPath());
         }
     }
 }
diff --git a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
index 9a816424..d8407479 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
@@ -147,9 +147,9 @@ public final class ZipTestCase extends AbstractTestCase {
         return zos;
     }
 
-    private File createReferenceFile(final File directory, final Zip64Mode zipMode, final String prefix)
+    private File createReferenceFile(final Zip64Mode zipMode, final String prefix)
             throws IOException {
-        final File reference = File.createTempFile(prefix, ".zip", directory);
+        final File reference = createTempFile(prefix, ".zip");
         try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(reference)) {
             zos.setUseZip64(zipMode);
             createFirstEntry(zos);
@@ -165,7 +165,7 @@ public final class ZipTestCase extends AbstractTestCase {
 
     private void createTestSplitZipSegments() throws IOException {
         final File directoryToZip = getFilesToZip();
-        final File outputZipFile = new File(dir, "splitZip.zip");
+        final File outputZipFile = new File(getTempDirFile(), "splitZip.zip");
         final long splitSize = 100 * 1024L; /* 100 KB */
         try (final ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(outputZipFile,
             splitSize)) {
@@ -188,11 +188,11 @@ public final class ZipTestCase extends AbstractTestCase {
                     continue;
                 }
 
-                outputFile = new File(dir, zipEntry.getName());
+                outputFile = new File(getTempDirFile(), zipEntry.getName());
                 if (!outputFile.getParentFile().exists()) {
                     outputFile.getParentFile().mkdirs();
                 }
-                outputFile = new File(dir, zipEntry.getName());
+                outputFile = new File(getTempDirFile(), zipEntry.getName());
 
                 try (InputStream inputStream = zipFile.getInputStream(zipEntry);
                     OutputStream outputStream = Files.newOutputStream(outputFile.toPath())) {
@@ -203,7 +203,7 @@ public final class ZipTestCase extends AbstractTestCase {
                 }
             }
         }
-        return dir.listFiles()[0];
+        return getTempDirFile().listFiles()[0];
     }
 
     private void readStream(final InputStream in, final ArchiveEntry entry, final Map<String,List<List<Long>>> map) throws IOException {
@@ -226,7 +226,7 @@ public final class ZipTestCase extends AbstractTestCase {
         final File directoryToZip = getFilesToZip();
         createTestSplitZipSegments();
 
-        final File lastFile = new File(dir, "splitZip.zip");
+        final File lastFile = new File(getTempDirFile(), "splitZip.zip");
         try (SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile);
             InputStream inputStream = Channels.newInputStream(channel);
             ZipArchiveInputStream splitInputStream = new ZipArchiveInputStream(inputStream,
@@ -255,13 +255,13 @@ public final class ZipTestCase extends AbstractTestCase {
     @Test
     public void testBuildSplitZipWithSegmentAlreadyExistThrowsException() throws IOException {
         final File directoryToZip = getFilesToZip();
-        final File outputZipFile = new File(dir, "splitZip.zip");
+        final File outputZipFile = new File(getTempDirFile(), "splitZip.zip");
         final long splitSize = 100 * 1024L; /* 100 KB */
         try (final ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(outputZipFile,
             splitSize)) {
 
             // create a file that has the same name of one of the created split segments
-            final File sameNameFile = new File(dir, "splitZip.z01");
+            final File sameNameFile = new File(getTempDirFile(), "splitZip.z01");
             sameNameFile.createNewFile();
 
             assertThrows(IOException.class, () -> addFilesToZip(zipArchiveOutputStream, directoryToZip));
@@ -295,26 +295,25 @@ public final class ZipTestCase extends AbstractTestCase {
     }
 
     @Test
-    public void testCopyRawEntriesFromFile()
-        throws IOException {
+    public void testCopyRawEntriesFromFile() throws IOException {
 
-        final File[] tmp = createTempDirAndFile();
-        final File reference = createReferenceFile(tmp[0], Zip64Mode.Never, "expected.");
+        final File reference = createReferenceFile(Zip64Mode.Never, "expected.");
 
-        final File file1 = File.createTempFile("src1.", ".zip", tmp[0]);
+        final File file1 = createTempFile("src1.", ".zip");
         try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(file1)) {
             zos.setUseZip64(Zip64Mode.Never);
             createFirstEntry(zos).close();
         }
 
-        final File file2 = File.createTempFile("src2.", ".zip", tmp[0]);
+        final File file2 = createTempFile("src2.", ".zip");
         try (final ZipArchiveOutputStream zos1 = new ZipArchiveOutputStream(file2)) {
             zos1.setUseZip64(Zip64Mode.Never);
             createSecondEntry(zos1).close();
         }
 
-        try (final ZipFile zipFile1 = new ZipFile(file1); final ZipFile zipFile2 = new ZipFile(file2)) {
-            final File fileResult = File.createTempFile("file-actual.", ".zip", tmp[0]);
+        try (final ZipFile zipFile1 = new ZipFile(file1);
+                final ZipFile zipFile2 = new ZipFile(file2)) {
+            final File fileResult = createTempFile("file-actual.", ".zip");
             try (final ZipArchiveOutputStream zos2 = new ZipArchiveOutputStream(fileResult)) {
                 zipFile1.copyRawEntries(zos2, allFilesPredicate);
                 zipFile2.copyRawEntries(zos2, allFilesPredicate);
@@ -326,25 +325,22 @@ public final class ZipTestCase extends AbstractTestCase {
         }
     }
 
-
     @Test
-    public void testCopyRawZip64EntryFromFile()
-            throws IOException {
+    public void testCopyRawZip64EntryFromFile() throws IOException {
 
-        final File[] tmp = createTempDirAndFile();
-        final File reference = File.createTempFile("z64reference.", ".zip", tmp[0]);
+        final File reference = createTempFile("z64reference.", ".zip");
         try (final ZipArchiveOutputStream zos1 = new ZipArchiveOutputStream(reference)) {
             zos1.setUseZip64(Zip64Mode.Always);
             createFirstEntry(zos1);
         }
 
-        final File file1 = File.createTempFile("zip64src.", ".zip", tmp[0]);
+        final File file1 = createTempFile("zip64src.", ".zip");
         try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(file1)) {
             zos.setUseZip64(Zip64Mode.Always);
             createFirstEntry(zos).close();
         }
 
-        final File fileResult = File.createTempFile("file-actual.", ".zip", tmp[0]);
+        final File fileResult = createTempFile("file-actual.", ".zip");
         try (final ZipFile zipFile1 = new ZipFile(file1)) {
             try (final ZipArchiveOutputStream zos2 = new ZipArchiveOutputStream(fileResult)) {
                 zos2.setUseZip64(Zip64Mode.Always);
@@ -356,16 +352,14 @@ public final class ZipTestCase extends AbstractTestCase {
 
     @Test
     public void testDirectoryEntryFromFile() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
+        final File tmp = getTempDirFile();
         ZipArchiveOutputStream zos = null;
         ZipFile zf = null;
         try {
-            archive = File.createTempFile("test.", ".zip", tmp[0]);
-            archive.deleteOnExit();
+            final File archive = createTempFile("test.", ".zip");
             zos = new ZipArchiveOutputStream(archive);
-            final long beforeArchiveWrite = tmp[0].lastModified();
-            final ZipArchiveEntry in = new ZipArchiveEntry(tmp[0], "foo");
+            final long beforeArchiveWrite = tmp.lastModified();
+            final ZipArchiveEntry in = new ZipArchiveEntry(tmp, "foo");
             zos.putArchiveEntry(in);
             zos.closeArchiveEntry();
             zos.close();
@@ -376,31 +370,24 @@ public final class ZipTestCase extends AbstractTestCase {
             assertEquals("foo/", out.getName());
             assertEquals(0, out.getSize());
             // ZIP stores time with a granularity of 2 seconds
-            assertEquals(beforeArchiveWrite / 2000,
-                         out.getLastModifiedDate().getTime() / 2000);
+            assertEquals(beforeArchiveWrite / 2000, out.getLastModifiedDate().getTime() / 2000);
             assertTrue(out.isDirectory());
         } finally {
             ZipFile.closeQuietly(zf);
             if (zos != null) {
                 zos.close();
             }
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
         }
     }
 
     @Test
     public void testExplicitDirectoryEntry() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
         ZipArchiveOutputStream zos = null;
         ZipFile zf = null;
         try {
-            archive = File.createTempFile("test.", ".zip", tmp[0]);
-            archive.deleteOnExit();
+            final File archive = createTempFile("test.", ".zip");
             zos = new ZipArchiveOutputStream(archive);
-            final long beforeArchiveWrite = tmp[0].lastModified();
+            final long beforeArchiveWrite = getTempDirFile().lastModified();
             final ZipArchiveEntry in = new ZipArchiveEntry("foo/");
             in.setTime(beforeArchiveWrite);
             zos.putArchiveEntry(in);
@@ -412,37 +399,31 @@ public final class ZipTestCase extends AbstractTestCase {
             assertNotNull(out);
             assertEquals("foo/", out.getName());
             assertEquals(0, out.getSize());
-            assertEquals(beforeArchiveWrite / 2000,
-                         out.getLastModifiedDate().getTime() / 2000);
+            assertEquals(beforeArchiveWrite / 2000, out.getLastModifiedDate().getTime() / 2000);
             assertTrue(out.isDirectory());
         } finally {
             ZipFile.closeQuietly(zf);
             if (zos != null) {
                 zos.close();
             }
-            forceDelete(archive);
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
         }
     }
 
     @Test
     public void testExplicitFileEntry() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
+        final File tmp = createTempFile();
         ZipArchiveOutputStream zos = null;
         ZipFile zf = null;
         InputStream fis = null;
         try {
-            archive = File.createTempFile("test.", ".zip", tmp[0]);
-            archive.deleteOnExit();
+            final File archive = createTempFile("test.", ".zip");
             zos = new ZipArchiveOutputStream(archive);
             final ZipArchiveEntry in = new ZipArchiveEntry("foo");
-            in.setTime(tmp[1].lastModified());
-            in.setSize(tmp[1].length());
+            in.setTime(tmp.lastModified());
+            in.setSize(tmp.length());
             zos.putArchiveEntry(in);
-            final byte[] b = new byte[(int) tmp[1].length()];
-            fis = Files.newInputStream(tmp[1].toPath());
+            final byte[] b = new byte[(int) tmp.length()];
+            fis = Files.newInputStream(tmp.toPath());
             while (fis.read(b) > 0) {
                 zos.write(b);
             }
@@ -455,36 +436,28 @@ public final class ZipTestCase extends AbstractTestCase {
             final ZipArchiveEntry out = zf.getEntry("foo");
             assertNotNull(out);
             assertEquals("foo", out.getName());
-            assertEquals(tmp[1].length(), out.getSize());
-            assertEquals(tmp[1].lastModified() / 2000,
-                         out.getLastModifiedDate().getTime() / 2000);
+            assertEquals(tmp.length(), out.getSize());
+            assertEquals(tmp.lastModified() / 2000, out.getLastModifiedDate().getTime() / 2000);
             assertFalse(out.isDirectory());
         } finally {
             ZipFile.closeQuietly(zf);
             if (zos != null) {
                 zos.close();
             }
-            forceDelete(archive);
             if (fis != null) {
                 fis.close();
             }
-            forceDelete(tmp[1]);
-            forceDelete(tmp[0]);
         }
     }
 
     @Test
     public void testFileEntryFromFile() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archive = null;
         ZipArchiveOutputStream zos = null;
         ZipFile zf = null;
         InputStream fis = null;
-        final File tmpDir = tmp[0];
-        final File tmpFile = tmp[1];
+        final File tmpFile = createTempFile();
         try {
-            archive = File.createTempFile("test.", ".zip", tmpDir);
-            archive.deleteOnExit();
+            final File archive = createTempFile("test.", ".zip");
             zos = new ZipArchiveOutputStream(archive);
             final ZipArchiveEntry in = new ZipArchiveEntry(tmpFile, "foo");
             zos.putArchiveEntry(in);
@@ -503,20 +476,16 @@ public final class ZipTestCase extends AbstractTestCase {
             assertNotNull(out);
             assertEquals("foo", out.getName());
             assertEquals(tmpFile.length(), out.getSize());
-            assertEquals(tmpFile.lastModified() / 2000,
-                         out.getLastModifiedDate().getTime() / 2000);
+            assertEquals(tmpFile.lastModified() / 2000, out.getLastModifiedDate().getTime() / 2000);
             assertFalse(out.isDirectory());
         } finally {
             ZipFile.closeQuietly(zf);
             if (zos != null) {
                 zos.close();
             }
-            forceDelete(archive);
             if (fis != null) {
                 fis.close();
             }
-            forceDelete(tmpFile);
-            forceDelete(tmpDir);
         }
     }
 
@@ -698,12 +667,8 @@ public final class ZipTestCase extends AbstractTestCase {
 
     @Test
     public void testUnixModeInAddRaw() throws IOException {
-
-        final File[] tmp = createTempDirAndFile();
-
-        final File file1 = File.createTempFile("unixModeBits.", ".zip", tmp[0]);
+        final File file1 = createTempFile("unixModeBits.", ".zip");
         try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(file1)) {
-
             final ZipArchiveEntry archiveEntry = new ZipArchiveEntry("fred");
             archiveEntry.setUnixMode(0664);
             archiveEntry.setMethod(ZipEntry.STORED);
@@ -711,7 +676,6 @@ public final class ZipTestCase extends AbstractTestCase {
             archiveEntry.setCompressedSize(3);
             zos.addRawArchiveEntry(archiveEntry, new ByteArrayInputStream("fud".getBytes()));
         }
-
         try (final ZipFile zf1 = new ZipFile(file1)) {
             final ZipArchiveEntry fred = zf1.getEntry("fred");
             assertEquals(0664, fred.getUnixMode());
@@ -726,7 +690,7 @@ public final class ZipTestCase extends AbstractTestCase {
     @Test
     public void testZipArchiveCreation() throws Exception {
         // Archive
-        final File output = new File(dir, "bla.zip");
+        final File output = new File(getTempDirFile(), "bla.zip");
         final File file1 = getFile("test1.xml");
         final File file2 = getFile("test2.xml");
 
@@ -750,7 +714,7 @@ public final class ZipTestCase extends AbstractTestCase {
                 fileInputStream)) {
                 ZipArchiveEntry entry;
                 while ((entry = archiveInputStream.getNextEntry()) != null) {
-                    final File outfile = new File(resultDir.getCanonicalPath() + "/result/" + entry.getName());
+                    final File outfile = new File(tempResultDir.getCanonicalPath() + "/result/" + entry.getName());
                     outfile.getParentFile().mkdirs();
                     Files.copy(archiveInputStream, outfile.toPath());
                     results.add(outfile);
@@ -809,17 +773,15 @@ public final class ZipTestCase extends AbstractTestCase {
 
     @Test
     public void testZipArchiveEntryNewFromPath() throws Exception {
-        final File[] tmp = createTempDirAndFile();
-        File archiveFile = null;
         Path archivePath;
         ZipArchiveOutputStream zos = null;
         ZipFile zf = null;
         InputStream fis = null;
-        final File tmpDir = tmp[0];
-        final File tmpFile = tmp[1];
+        final File tmpFile = createTempFile();
+        
         final Path tmpFilePath = tmpFile.toPath();
         try {
-            archiveFile = File.createTempFile("test.", ".zip", tmpDir);
+            final File archiveFile = createTempFile("test.", ".zip");
             archivePath = archiveFile.toPath();
             archiveFile.deleteOnExit();
             zos = new ZipArchiveOutputStream(archivePath);
@@ -840,20 +802,16 @@ public final class ZipTestCase extends AbstractTestCase {
             assertNotNull(out);
             assertEquals("foo", out.getName());
             assertEquals(tmpFile.length(), out.getSize());
-            assertEquals(tmpFile.lastModified() / 2000,
-                         out.getLastModifiedDate().getTime() / 2000);
+            assertEquals(tmpFile.lastModified() / 2000, out.getLastModifiedDate().getTime() / 2000);
             assertFalse(out.isDirectory());
         } finally {
             ZipFile.closeQuietly(zf);
             if (zos != null) {
                 zos.close();
             }
-            forceDelete(archiveFile);
             if (fis != null) {
                 fis.close();
             }
-            forceDelete(tmpFile);
-            forceDelete(tmpDir);
         }
     }
 
@@ -867,7 +825,7 @@ public final class ZipTestCase extends AbstractTestCase {
         try (final InputStream is = Files.newInputStream(input.toPath());
                 final ArchiveInputStream<ZipArchiveEntry> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", is)) {
             final ZipArchiveEntry entry = in.getNextEntry();
-            Files.copy(in, new File(dir, entry.getName()).toPath());
+            Files.copy(in, new File(getTempDirFile(), entry.getName()).toPath());
         }
     }
 }
diff --git a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java
index acef80ed..64d4f070 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java
@@ -37,17 +37,16 @@ public class ArArchiveOutputStreamTest extends AbstractTestCase {
     public void testLongFileNamesCauseExceptionByDefault() throws IOException {
         try (ArArchiveOutputStream os = new ArArchiveOutputStream(new ByteArrayOutputStream())) {
             final ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt", 0);
-            final IOException ex = assertThrows(IOException.class, () -> os.putArchiveEntry(ae),
-                    "Expected an exception");
+            final IOException ex = assertThrows(IOException.class, () -> os.putArchiveEntry(ae), "Expected an exception");
             assertTrue(ex.getMessage().startsWith("File name too long"));
         }
     }
 
     @Test
     public void testLongFileNamesWorkUsingBSDDialect() throws Exception {
-        final File[] df = createTempDirAndFile();
-        try (OutputStream fos = Files.newOutputStream(df[1].toPath());
-             ArArchiveOutputStream os = new ArArchiveOutputStream(fos)) {
+        final File file = createTempFile();
+        try (OutputStream fos = Files.newOutputStream(file.toPath());
+                ArArchiveOutputStream os = new ArArchiveOutputStream(fos)) {
             os.setLongFileMode(ArArchiveOutputStream.LONGFILE_BSD);
             final ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt", 14);
             os.putArchiveEntry(ae);
@@ -56,9 +55,7 @@ public class ArArchiveOutputStreamTest extends AbstractTestCase {
 
             final List<String> expected = new ArrayList<>();
             expected.add("this_is_a_long_name.txt");
-            checkArchiveContent(df[1], expected);
-        } finally {
-            forceDelete(df[0]);
+            checkArchiveContent(file, expected);
         }
     }
 }
diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java
index c7ae4454..28546a24 100644
--- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java
@@ -33,7 +33,7 @@ public class CpioArchiveOutputStreamTest extends AbstractTestCase {
     @Test
     public void testWriteOldBinary() throws Exception {
         final File f = getFile("test1.xml");
-        final File output = new File(dir, "test.cpio");
+        final File output = new File(getTempDirFile(), "test.cpio");
         try (final OutputStream out = Files.newOutputStream(output.toPath());
                 CpioArchiveOutputStream os = new CpioArchiveOutputStream(out, CpioConstants.FORMAT_OLD_BINARY)) {
             os.putArchiveEntry(new CpioArchiveEntry(CpioConstants.FORMAT_OLD_BINARY, f, "test1.xml"));
diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java
index 1c041483..faa533be 100644
--- a/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java
@@ -54,26 +54,26 @@ public class ExpanderTest extends AbstractTestCase {
     private File archive;
 
     private void assertHelloWorld(final String fileName, final String suffix) throws IOException {
-        assertTrue(new File(resultDir, fileName).isFile(), fileName + " does not exist");
+        assertTrue(new File(tempResultDir, fileName).isFile(), fileName + " does not exist");
         final byte[] expected = ("Hello, world " + suffix).getBytes(UTF_8);
-        try (InputStream is = Files.newInputStream(new File(resultDir, fileName).toPath())) {
+        try (InputStream is = Files.newInputStream(new File(tempResultDir, fileName).toPath())) {
             final byte[] actual = IOUtils.toByteArray(is);
             assertArrayEquals(expected, actual);
         }
     }
 
     private void setup7z() throws IOException {
-        archive = new File(dir, "test.7z");
-        final File dummy = new File(dir, "x");
+        archive = new File(getTempDirFile(), "test.7z");
+        final File dummy = new File(getTempDirFile(), "x");
         try (OutputStream o = Files.newOutputStream(dummy.toPath())) {
             o.write(new byte[14]);
         }
         try (SevenZOutputFile aos = new SevenZOutputFile(archive)) {
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a/b"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b/c"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a/b/c"));
             aos.closeArchiveEntry();
             aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/d.txt"));
             aos.write("Hello, world 1".getBytes(UTF_8));
@@ -86,18 +86,18 @@ public class ExpanderTest extends AbstractTestCase {
     }
 
     private void setupTar() throws IOException, ArchiveException {
-        archive = new File(dir, "test.tar");
-        final File dummy = new File(dir, "x");
+        archive = new File(getTempDirFile(), "test.tar");
+        final File dummy = new File(getTempDirFile(), "x");
         try (OutputStream o = Files.newOutputStream(dummy.toPath())) {
             o.write(new byte[14]);
         }
         try (@SuppressWarnings("resource") // Files.newOutputStream result closed by ArchiveOutputStream
         ArchiveOutputStream<ArchiveEntry> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", Files.newOutputStream(archive.toPath()))) {
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a/b"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b/c"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a/b/c"));
             aos.closeArchiveEntry();
             aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/d.txt"));
             aos.write("Hello, world 1".getBytes(UTF_8));
@@ -110,20 +110,20 @@ public class ExpanderTest extends AbstractTestCase {
     }
 
     private void setupTarForCompress603() throws IOException, ArchiveException {
-        archive = new File(dir, "test.tar");
-        final File dummy = new File(dir, "x");
+        archive = new File(getTempDirFile(), "test.tar");
+        final File dummy = new File(getTempDirFile(), "x");
         try (OutputStream o = Files.newOutputStream(dummy.toPath())) {
             o.write(new byte[14]);
         }
         try (@SuppressWarnings("resource") // Files.newOutputStream result closed by ArchiveOutputStream
         ArchiveOutputStream<ArchiveEntry> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", Files.newOutputStream(archive.toPath()))) {
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "./"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "./"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "./a"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "./a"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "./a/b"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "./a/b"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "./a/b/c"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "./a/b/c"));
             aos.closeArchiveEntry();
             aos.putArchiveEntry(aos.createArchiveEntry(dummy, "./a/b/d.txt"));
             aos.write("Hello, world 1".getBytes(UTF_8));
@@ -136,18 +136,18 @@ public class ExpanderTest extends AbstractTestCase {
     }
 
     private void setupZip() throws IOException, ArchiveException {
-        archive = new File(dir, "test.zip");
-        final File dummy = new File(dir, "x");
+        archive = new File(getTempDirFile(), "test.zip");
+        final File dummy = new File(getTempDirFile(), "x");
         try (OutputStream o = Files.newOutputStream(dummy.toPath())) {
             o.write(new byte[14]);
         }
         try (@SuppressWarnings("resource") // // Files.newOutputStream result closed by ArchiveOutputStream
         ArchiveOutputStream<ArchiveEntry> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("zip", Files.newOutputStream(archive.toPath()))) {
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a/b"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b/c"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a/b/c"));
             aos.closeArchiveEntry();
             aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/d.txt"));
             aos.write("Hello, world 1".getBytes(UTF_8));
@@ -160,8 +160,8 @@ public class ExpanderTest extends AbstractTestCase {
     }
 
     private void setupZip(final String entry) throws IOException, ArchiveException {
-        archive = new File(dir, "test.zip");
-        final File dummy = new File(dir, "x");
+        archive = new File(getTempDirFile(), "test.zip");
+        final File dummy = new File(getTempDirFile(), "x");
         try (OutputStream o = Files.newOutputStream(dummy.toPath())) {
             o.write(new byte[14]);
         }
@@ -178,7 +178,7 @@ public class ExpanderTest extends AbstractTestCase {
     public void tarFileVersion() throws IOException, ArchiveException {
         setupTar();
         try (TarFile f = new TarFile(archive)) {
-            new Expander().expand(f, resultDir);
+            new Expander().expand(f, tempResultDir);
         }
         verifyTargetDir();
     }
@@ -187,7 +187,7 @@ public class ExpanderTest extends AbstractTestCase {
     public void testCompress603Tar() throws IOException, ArchiveException {
         setupTarForCompress603();
         try (TarFile f = new TarFile(archive)) {
-            new Expander().expand(f, resultDir);
+            new Expander().expand(f, tempResultDir);
         }
         verifyTargetDir();
     }
@@ -196,14 +196,14 @@ public class ExpanderTest extends AbstractTestCase {
     public void testFileCantEscapeDoubleDotPath() throws IOException, ArchiveException {
         setupZip("../foo");
         try (ZipFile f = new ZipFile(archive)) {
-            assertThrows(IOException.class, () -> new Expander().expand(f, resultDir));
+            assertThrows(IOException.class, () -> new Expander().expand(f, tempResultDir));
         }
     }
 
     @Test
     public void testFileCantEscapeDoubleDotPathWithSimilarSibling() throws IOException, ArchiveException {
-        final String sibling = resultDir.getName() + "x";
-        final File s = new File(resultDir.getParentFile(), sibling);
+        final String sibling = tempResultDir.getName() + "x";
+        final File s = new File(tempResultDir.getParentFile(), sibling);
         assumeFalse(s.exists());
         s.mkdirs();
         assumeTrue(s.exists());
@@ -211,7 +211,7 @@ public class ExpanderTest extends AbstractTestCase {
         try {
             setupZip("../" + sibling + "/a");
             try (ZipFile f = new ZipFile(archive)) {
-                assertThrows(IOException.class, () -> new Expander().expand(f, resultDir));
+                assertThrows(IOException.class, () -> new Expander().expand(f, tempResultDir));
             }
         } finally {
             forceDelete(s);
@@ -222,16 +222,16 @@ public class ExpanderTest extends AbstractTestCase {
     public void testFileCantEscapeViaAbsolutePath() throws IOException, ArchiveException {
         setupZip("/tmp/foo");
         try (ZipFile f = new ZipFile(archive)) {
-            assertThrows(IOException.class, () -> new Expander().expand(f, resultDir));
+            assertThrows(IOException.class, () -> new Expander().expand(f, tempResultDir));
         }
-        assertFalse(new File(resultDir, "tmp/foo").isFile());
+        assertFalse(new File(tempResultDir, "tmp/foo").isFile());
     }
 
     @Test
     public void testSevenZChannelVersion() throws IOException, ArchiveException {
         setup7z();
         try (SeekableByteChannel c = FileChannel.open(archive.toPath(), StandardOpenOption.READ)) {
-            new Expander().expand("7z", c, resultDir);
+            new Expander().expand("7z", c, tempResultDir);
         }
         verifyTargetDir();
     }
@@ -240,7 +240,7 @@ public class ExpanderTest extends AbstractTestCase {
     public void testSevenZFileVersion() throws IOException {
         setup7z();
         try (SevenZFile f = new SevenZFile(archive)) {
-            new Expander().expand(f, resultDir);
+            new Expander().expand(f, tempResultDir);
         }
         verifyTargetDir();
     }
@@ -249,7 +249,7 @@ public class ExpanderTest extends AbstractTestCase {
     public void testSevenZInputStreamVersion() throws IOException {
         setup7z();
         try (InputStream i = new BufferedInputStream(Files.newInputStream(archive.toPath()))) {
-            assertThrows(StreamingNotSupportedException.class, () -> new Expander().expand("7z", i, resultDir));
+            assertThrows(StreamingNotSupportedException.class, () -> new Expander().expand("7z", i, tempResultDir));
         }
     }
 
@@ -257,21 +257,21 @@ public class ExpanderTest extends AbstractTestCase {
     public void testSevenZInputStreamVersionWithAutoDetection() throws IOException {
         setup7z();
         try (InputStream i = new BufferedInputStream(Files.newInputStream(archive.toPath()))) {
-            assertThrows(StreamingNotSupportedException.class, () -> new Expander().expand(i, resultDir));
+            assertThrows(StreamingNotSupportedException.class, () -> new Expander().expand(i, tempResultDir));
         }
     }
 
     @Test
     public void testSevenZTwoFileVersion() throws IOException, ArchiveException {
         setup7z();
-        new Expander().expand("7z", archive, resultDir);
+        new Expander().expand("7z", archive, tempResultDir);
         verifyTargetDir();
     }
 
     @Test
     public void testSevenZTwoFileVersionWithAutoDetection() throws IOException, ArchiveException {
         setup7z();
-        new Expander().expand(archive, resultDir);
+        new Expander().expand(archive, tempResultDir);
         verifyTargetDir();
     }
 
@@ -279,15 +279,15 @@ public class ExpanderTest extends AbstractTestCase {
     public void testZipFileVersion() throws IOException, ArchiveException {
         setupZip();
         try (ZipFile f = new ZipFile(archive)) {
-            new Expander().expand(f, resultDir);
+            new Expander().expand(f, tempResultDir);
         }
         verifyTargetDir();
     }
 
     private void verifyTargetDir() throws IOException {
-        assertTrue(new File(resultDir, "a").isDirectory(), "a has not been created");
-        assertTrue(new File(resultDir, "a/b").isDirectory(), "a/b has not been created");
-        assertTrue(new File(resultDir, "a/b/c").isDirectory(), "a/b/c has not been created");
+        assertTrue(new File(tempResultDir, "a").isDirectory(), "a has not been created");
+        assertTrue(new File(tempResultDir, "a/b").isDirectory(), "a/b has not been created");
+        assertTrue(new File(tempResultDir, "a/b/c").isDirectory(), "a/b/c has not been created");
         assertHelloWorld("a/b/d.txt", "1");
         assertHelloWorld("a/b/c/e.txt", "2");
     }
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 00fce551..788cb376 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
@@ -69,7 +69,7 @@ public class ParameterizedArchiverTest extends AbstractTestCase {
         setUp(format);
         try (OutputStream os = Files.newOutputStream(target.toPath());
              ArchiveOutputStream<?> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format, os)) {
-            new Archiver().create(aos, dir);
+            new Archiver().create(aos, getTempDirFile());
         }
         verifyContent(format);
     }
@@ -97,7 +97,7 @@ public class ParameterizedArchiverTest extends AbstractTestCase {
         setUp(format);
         try (SeekableByteChannel c = FileChannel.open(target.toPath(), StandardOpenOption.WRITE,
             StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
-            new Archiver().create(format, c, dir);
+            new Archiver().create(format, c, getTempDirFile());
         }
         verifyContent(format);
     }
@@ -107,7 +107,7 @@ public class ParameterizedArchiverTest extends AbstractTestCase {
     public void fileVersion(final String format) throws Exception {
         // TODO How to parameterize a BeforeEach method?
         setUp(format);
-        new Archiver().create(format, target, dir);
+        new Archiver().create(format, target, getTempDirFile());
         verifyContent(format);
     }
 
@@ -117,22 +117,22 @@ public class ParameterizedArchiverTest extends AbstractTestCase {
         // TODO How to parameterize a BeforeEach method?
         setUp(format);
         try (OutputStream os = Files.newOutputStream(target.toPath())) {
-            new Archiver().create(format, os, dir);
+            new Archiver().create(format, os, getTempDirFile());
         }
         verifyContent(format);
     }
 
     public void setUp(final String format) throws Exception {
         super.setUp();
-        final File c = new File(dir, "a/b/c");
+        final File c = new File(getTempDirFile(), "a/b/c");
         c.mkdirs();
-        try (OutputStream os = Files.newOutputStream(new File(dir, "a/b/d.txt").toPath())) {
+        try (OutputStream os = Files.newOutputStream(new File(getTempDirFile(), "a/b/d.txt").toPath())) {
             os.write("Hello, world 1".getBytes(UTF_8));
         }
-        try (OutputStream os = Files.newOutputStream(new File(dir, "a/b/c/e.txt").toPath())) {
+        try (OutputStream os = Files.newOutputStream(new File(getTempDirFile(), "a/b/c/e.txt").toPath())) {
             os.write("Hello, world 2".getBytes(UTF_8));
         }
-        target = new File(resultDir, "test." + format);
+        target = new File(tempResultDir, "test." + format);
     }
 
     private void verifyContent(final String format) throws IOException, ArchiveException {
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 b244499a..b6dad792 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
@@ -65,15 +65,15 @@ public class ParameterizedExpanderTest extends AbstractTestCase {
         setUp(format);
         try (InputStream i = new BufferedInputStream(Files.newInputStream(archive.toPath()));
              ArchiveInputStream<?> ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(format, i)) {
-            new Expander().expand(ais, resultDir);
+            new Expander().expand(ais, tempResultDir);
         }
         verifyTargetDir();
     }
 
     private void assertHelloWorld(final String fileName, final String suffix) throws IOException {
-        assertTrue(new File(resultDir, fileName).isFile(), fileName + " does not exist");
+        assertTrue(new File(tempResultDir, fileName).isFile(), fileName + " does not exist");
         final byte[] expected = ("Hello, world " + suffix).getBytes(UTF_8);
-        try (InputStream is = Files.newInputStream(new File(resultDir, fileName).toPath())) {
+        try (InputStream is = Files.newInputStream(new File(tempResultDir, fileName).toPath())) {
             final byte[] actual = IOUtils.toByteArray(is);
             assertArrayEquals(expected, actual);
         }
@@ -85,7 +85,7 @@ public class ParameterizedExpanderTest extends AbstractTestCase {
         // TODO How to parameterize a BeforeEach method?
         setUp(format);
         try (SeekableByteChannel c = FileChannel.open(archive.toPath(), StandardOpenOption.READ)) {
-            new Expander().expand(format, c, resultDir);
+            new Expander().expand(format, c, tempResultDir);
         }
         verifyTargetDir();
     }
@@ -95,7 +95,7 @@ public class ParameterizedExpanderTest extends AbstractTestCase {
     public void fileVersion(final String format) throws Exception {
         // TODO How to parameterize a BeforeEach method?
         setUp(format);
-        new Expander().expand(format, archive, resultDir);
+        new Expander().expand(format, archive, tempResultDir);
         verifyTargetDir();
     }
 
@@ -104,7 +104,7 @@ public class ParameterizedExpanderTest extends AbstractTestCase {
     public void fileVersionWithAutoDetection(final String format) throws Exception {
         // TODO How to parameterize a BeforeEach method?
         setUp(format);
-        new Expander().expand(archive, resultDir);
+        new Expander().expand(archive, tempResultDir);
         verifyTargetDir();
     }
 
@@ -114,7 +114,7 @@ public class ParameterizedExpanderTest extends AbstractTestCase {
         // TODO How to parameterize a BeforeEach method?
         setUp(format);
         try (InputStream i = new BufferedInputStream(Files.newInputStream(archive.toPath()))) {
-            new Expander().expand(format, i, resultDir);
+            new Expander().expand(format, i, tempResultDir);
         }
         verifyTargetDir();
     }
@@ -125,24 +125,24 @@ public class ParameterizedExpanderTest extends AbstractTestCase {
         // TODO How to parameterize a BeforeEach method?
         setUp(format);
         try (InputStream i = new BufferedInputStream(Files.newInputStream(archive.toPath()))) {
-            new Expander().expand(i, resultDir);
+            new Expander().expand(i, tempResultDir);
         }
         verifyTargetDir();
     }
 
     public void setUp(final String format) throws Exception {
         super.setUp();
-        archive = new File(dir, "test." + format);
-        final File dummy = new File(dir, "x");
+        archive = new File(getTempDirFile(), "test." + format);
+        final File dummy = new File(getTempDirFile(), "x");
         try (OutputStream o = Files.newOutputStream(dummy.toPath())) {
             o.write(new byte[14]);
         }
         try (ArchiveOutputStream<ArchiveEntry> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format, Files.newOutputStream(archive.toPath()))) {
-            aos.putArchiveEntry(aos.createArchiveEntry(dir.toPath(), "a"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile().toPath(), "a"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a/b"));
             aos.closeArchiveEntry();
-            aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b/c"));
+            aos.putArchiveEntry(aos.createArchiveEntry(getTempDirFile(), "a/b/c"));
             aos.closeArchiveEntry();
             aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/d.txt"));
             aos.write("Hello, world 1".getBytes(UTF_8));
@@ -155,9 +155,9 @@ public class ParameterizedExpanderTest extends AbstractTestCase {
     }
 
     private void verifyTargetDir() throws IOException {
-        assertTrue(new File(resultDir, "a").isDirectory(), "a has not been created");
-        assertTrue(new File(resultDir, "a/b").isDirectory(), "a/b has not been created");
-        assertTrue(new File(resultDir, "a/b/c").isDirectory(), "a/b/c has not been created");
+        assertTrue(new File(tempResultDir, "a").isDirectory(), "a has not been created");
+        assertTrue(new File(tempResultDir, "a/b").isDirectory(), "a/b has not been created");
+        assertTrue(new File(tempResultDir, "a/b/c").isDirectory(), "a/b/c has not been created");
         assertHelloWorld("a/b/d.txt", "1");
         assertHelloWorld("a/b/c/e.txt", "2");
     }
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 a9721b75..ee3f03df 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
@@ -67,36 +67,36 @@ public class SevenZArchiverTest extends AbstractTestCase {
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        final File c = new File(dir, "a/b/c");
+        final File c = new File(getTempDirFile(), "a/b/c");
         c.mkdirs();
-        try (OutputStream os = Files.newOutputStream(new File(dir, "a/b/d.txt").toPath())) {
+        try (OutputStream os = Files.newOutputStream(new File(getTempDirFile(), "a/b/d.txt").toPath())) {
             os.write("Hello, world 1".getBytes(UTF_8));
         }
-        try (OutputStream os = Files.newOutputStream(new File(dir, "a/b/c/e.txt").toPath())) {
+        try (OutputStream os = Files.newOutputStream(new File(getTempDirFile(), "a/b/c/e.txt").toPath())) {
             os.write("Hello, world 2".getBytes(UTF_8));
         }
-        target = new File(resultDir, "test.7z");
+        target = new File(tempResultDir, "test.7z");
     }
 
     @Test
     public void testChannelVersion() throws IOException, ArchiveException {
         try (SeekableByteChannel c = FileChannel.open(target.toPath(), StandardOpenOption.WRITE,
             StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
-            new Archiver().create("7z", c, dir);
+            new Archiver().create("7z", c, getTempDirFile());
         }
         verifyContent();
     }
 
     @Test
     public void testFileVersion() throws IOException, ArchiveException {
-        new Archiver().create("7z", target, dir);
+        new Archiver().create("7z", target, getTempDirFile());
         verifyContent();
     }
 
     @Test
     public void testOutputStreamVersion() throws IOException {
         try (OutputStream os = Files.newOutputStream(target.toPath())) {
-            assertThrows(StreamingNotSupportedException.class, () -> new Archiver().create("7z", os, dir));
+            assertThrows(StreamingNotSupportedException.class, () -> new Archiver().create("7z", os, getTempDirFile()));
         }
     }
 
@@ -105,7 +105,7 @@ public class SevenZArchiverTest extends AbstractTestCase {
     public void testUnknownFormat() throws IOException {
         try (SeekableByteChannel c = FileChannel.open(target.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE,
             StandardOpenOption.TRUNCATE_EXISTING)) {
-            assertThrows(ArchiveException.class, () -> new Archiver().create("unknown format", c, dir));
+            assertThrows(ArchiveException.class, () -> new Archiver().create("unknown format", c, getTempDirFile()));
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
index 5b9a22ba..ff567aa0 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
@@ -352,7 +352,7 @@ public class SevenZFileTest extends AbstractTestCase {
      */
     @Test
     public void testHandlesEmptyArchiveWithFilesInfo() throws Exception {
-        final File f = new File(dir, "empty.7z");
+        final File f = new File(getTempDirFile(), "empty.7z");
         try (SevenZOutputFile s = new SevenZOutputFile(f)) {
         }
         try (SevenZFile z = new SevenZFile(f)) {
@@ -754,7 +754,7 @@ public class SevenZFileTest extends AbstractTestCase {
 
     @Test
     public void testReadingBackDeltaDistance() throws Exception {
-        final File output = new File(dir, "delta-distance.7z");
+        final File output = new File(getTempDirFile(), "delta-distance.7z");
         try (SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
             outArchive.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER, 32),
                     new SevenZMethodConfiguration(SevenZMethod.LZMA2)));
@@ -775,7 +775,7 @@ public class SevenZFileTest extends AbstractTestCase {
 
     @Test
     public void testReadingBackLZMA2DictSize() throws Exception {
-        final File output = new File(dir, "lzma2-dictsize.7z");
+        final File output = new File(getTempDirFile(), "lzma2-dictsize.7z");
         try (SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
             outArchive.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 1 << 20)));
             final SevenZArchiveEntry entry = new SevenZArchiveEntry();
@@ -832,7 +832,7 @@ public class SevenZFileTest extends AbstractTestCase {
 
     @Test
     public void testRetrieveInputStreamForAllEntriesWithoutCRCMultipleTimes() throws IOException {
-        try (final SevenZOutputFile out = new SevenZOutputFile(new File(dir, "test.7z"))) {
+        try (final SevenZOutputFile out = new SevenZOutputFile(new File(getTempDirFile(), "test.7z"))) {
             final Path inputFile = Files.createTempFile("SevenZTestTemp", "");
 
             final SevenZArchiveEntry entry = out.createArchiveEntry(inputFile.toFile(), "test.txt");
@@ -843,7 +843,7 @@ public class SevenZFileTest extends AbstractTestCase {
             Files.deleteIfExists(inputFile);
         }
 
-        try (SevenZFile sevenZFile = new SevenZFile(new File(dir, "test.7z"))) {
+        try (SevenZFile sevenZFile = new SevenZFile(new File(getTempDirFile(), "test.7z"))) {
             for (final SevenZArchiveEntry entry : sevenZFile.getEntries()) {
                 final byte[] firstRead = IOUtils.toByteArray(sevenZFile.getInputStream(entry));
                 final byte[] secondRead = IOUtils.toByteArray(sevenZFile.getInputStream(entry));
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
index 65c49e1e..9e9a0ee8 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
@@ -73,7 +73,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
     private File output;
 
     private void addDir(final SevenZOutputFile archive) throws Exception {
-        final SevenZArchiveEntry entry = archive.createArchiveEntry(dir, "foo/");
+        final SevenZArchiveEntry entry = archive.createArchiveEntry(getTempDirFile(), "foo/");
         archive.putArchiveEntry(entry);
         archive.closeArchiveEntry();
     }
@@ -148,7 +148,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testArchiveWithMixedMethods() throws Exception {
-        output = new File(dir, "mixed-methods.7z");
+        output = new File(getTempDirFile(), "mixed-methods.7z");
         try (SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
             addFile(outArchive, 0, true);
             addFile(outArchive, 1, true, Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.BZIP2)));
@@ -205,7 +205,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testBzip2WithConfiguration() throws Exception {
-        output = new File(dir, "bzip2-options.7z");
+        output = new File(getTempDirFile(), "bzip2-options.7z");
         // 400k block size
         createAndReadBack(output, Collections
                           .singletonList(new SevenZMethodConfiguration(SevenZMethod.BZIP2, 4)));
@@ -213,7 +213,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testCantFinishTwice() throws IOException {
-        output = new File(dir, "finish.7z");
+        output = new File(getTempDirFile(), "finish.7z");
         try (SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
             outArchive.finish();
             final IOException ex = assertThrows(IOException.class, outArchive::finish,
@@ -228,7 +228,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
             ? numberOfFiles / numberOfNonEmptyFiles
             : numberOfFiles + 1;
         int nonEmptyFilesAdded = 0;
-        output = new File(dir, "COMPRESS252-" + numberOfFiles + "-" + numberOfNonEmptyFiles + ".7z");
+        output = new File(getTempDirFile(), "COMPRESS252-" + numberOfFiles + "-" + numberOfNonEmptyFiles + ".7z");
         try (SevenZOutputFile archive = new SevenZOutputFile(output)) {
             addDir(archive);
             for (int i = 0; i < numberOfFiles; i++) {
@@ -251,7 +251,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testDeflateWithConfiguration() throws Exception {
-        output = new File(dir, "deflate-options.7z");
+        output = new File(getTempDirFile(), "deflate-options.7z");
         // Deflater.BEST_SPEED
         createAndReadBack(output, Collections
                           .singletonList(new SevenZMethodConfiguration(SevenZMethod.DEFLATE, 1)));
@@ -264,7 +264,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testDirectoriesAndEmptyFiles() throws Exception {
-        output = new File(dir, "empties.7z");
+        output = new File(getTempDirFile(), "empties.7z");
 
         final FileTime accessTime = getHundredNanosFileTime();
         final Date accessDate = new Date(accessTime.toMillis());
@@ -273,7 +273,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
         final Date creationDate = cal.getTime();
 
         try (SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
-            SevenZArchiveEntry entry = outArchive.createArchiveEntry(dir, "foo/");
+            SevenZArchiveEntry entry = outArchive.createArchiveEntry(getTempDirFile(), "foo/");
             outArchive.putArchiveEntry(entry);
             outArchive.closeArchiveEntry();
 
@@ -323,12 +323,12 @@ public class SevenZOutputFileTest extends AbstractTestCase {
             outArchive.write(0);
             outArchive.closeArchiveEntry();
 
-            entry = outArchive.createArchiveEntry(dir, "baz/");
+            entry = outArchive.createArchiveEntry(getTempDirFile(), "baz/");
             entry.setAntiItem(true);
             outArchive.putArchiveEntry(entry);
             outArchive.closeArchiveEntry();
 
-            entry = outArchive.createArchiveEntry(dir.toPath(), "baz2/");
+            entry = outArchive.createArchiveEntry(getTempDirFile().toPath(), "baz2/");
             entry.setAntiItem(true);
             outArchive.putArchiveEntry(entry);
             outArchive.closeArchiveEntry();
@@ -444,7 +444,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testDirectoriesOnly() throws Exception {
-        output = new File(dir, "dirs.7z");
+        output = new File(getTempDirFile(), "dirs.7z");
         try (SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
             final SevenZArchiveEntry entry = new SevenZArchiveEntry();
             entry.setName("foo/");
@@ -485,7 +485,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
      */
     @Test
     public void testEncrypt() throws Exception {
-        output = new File(dir, "encrypted.7z");
+        output = new File(getTempDirFile(), "encrypted.7z");
         try (SevenZOutputFile outArchive = new SevenZOutputFile(output, "foo".toCharArray())) {
             addFile(outArchive, 0, 1, null);
             addFile(outArchive, 1, 16, null);
@@ -512,7 +512,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
     }
 
     private void testFilterRoundTrip(final SevenZMethodConfiguration method) throws Exception {
-        output = new File(dir, method.getMethod() + "-roundtrip.7z");
+        output = new File(getTempDirFile(), method.getMethod() + "-roundtrip.7z");
         final ArrayList<SevenZMethodConfiguration> methods = new ArrayList<>();
         methods.add(method);
         methods.add(new SevenZMethodConfiguration(SevenZMethod.LZMA2));
@@ -526,7 +526,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testLzma2WithIntConfiguration() throws Exception {
-        output = new File(dir, "lzma2-options.7z");
+        output = new File(getTempDirFile(), "lzma2-options.7z");
         // 1 MB dictionary
         createAndReadBack(output, Collections
                           .singletonList(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 1 << 20)));
@@ -534,7 +534,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testLzma2WithOptionsConfiguration() throws Exception {
-        output = new File(dir, "lzma2-options2.7z");
+        output = new File(getTempDirFile(), "lzma2-options2.7z");
         final LZMA2Options opts = new LZMA2Options(1);
         createAndReadBack(output, Collections
                           .singletonList(new SevenZMethodConfiguration(SevenZMethod.LZMA2, opts)));
@@ -542,7 +542,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testLzmaWithIntConfiguration() throws Exception {
-        output = new File(dir, "lzma-options.7z");
+        output = new File(getTempDirFile(), "lzma-options.7z");
         // 1 MB dictionary
         createAndReadBack(output, Collections
                           .singletonList(new SevenZMethodConfiguration(SevenZMethod.LZMA, 1 << 20)));
@@ -550,7 +550,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testLzmaWithOptionsConfiguration() throws Exception {
-        output = new File(dir, "lzma-options2.7z");
+        output = new File(getTempDirFile(), "lzma-options2.7z");
         final LZMA2Options opts = new LZMA2Options(1);
         createAndReadBack(output, Collections
                           .singletonList(new SevenZMethodConfiguration(SevenZMethod.LZMA, opts)));
@@ -567,7 +567,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
     }
 
     private void testRoundTrip(final SevenZMethod method) throws Exception {
-        output = new File(dir, method + "-roundtrip.7z");
+        output = new File(getTempDirFile(), method + "-roundtrip.7z");
         final ArrayList<SevenZMethodConfiguration> methods = new ArrayList<>();
         methods.add(new SevenZMethodConfiguration(method));
         createAndReadBack(output, methods);
@@ -595,7 +595,7 @@ public class SevenZOutputFileTest extends AbstractTestCase {
 
     @Test
     public void testStackOfContentCompressions() throws Exception {
-        output = new File(dir, "multiple-methods.7z");
+        output = new File(getTempDirFile(), "multiple-methods.7z");
         final ArrayList<SevenZMethodConfiguration> methods = new ArrayList<>();
         methods.add(new SevenZMethodConfiguration(SevenZMethod.LZMA2));
         methods.add(new SevenZMethodConfiguration(SevenZMethod.COPY));
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java b/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java
index 007becb7..d863a35e 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java
@@ -64,7 +64,7 @@ public class BigFilesIT extends AbstractTestCase {
     @Test
     public void tarFileReadFileHeadersOfArchiveBiggerThan8GByte() throws Exception {
         final Path file = getPath("8.posix.tar.gz");
-        final Path output = resultDir.toPath().resolve("8.posix.tar");
+        final Path output = tempResultDir.toPath().resolve("8.posix.tar");
         try (InputStream in = new BufferedInputStream(Files.newInputStream(file));
              GzipCompressorInputStream gzin = new GzipCompressorInputStream(in)) {
             Files.copy(gzin, output, StandardCopyOption.REPLACE_EXISTING);
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
index cdae0cb8..27270e55 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
@@ -84,13 +84,13 @@ public class SparseFilesTest extends AbstractTestCase {
     }
 
     private InputStream extractTarAndGetInputStream(final File tarFile, final String sparseFileName) throws IOException, InterruptedException {
-        final ProcessBuilder pb = new ProcessBuilder("tar", "-xf", tarFile.getPath(), "-C", resultDir.getPath());
+        final ProcessBuilder pb = new ProcessBuilder("tar", "-xf", tarFile.getPath(), "-C", tempResultDir.getPath());
         pb.redirectErrorStream(true);
         final Process process = pb.start();
         // wait until the extract finishes
         assertEquals(0, process.waitFor(), new String(IOUtils.toByteArray(process.getInputStream())));
 
-        for (final File file : resultDir.listFiles()) {
+        for (final File file : tempResultDir.listFiles()) {
             if (file.getName().equals(sparseFileName)) {
                 return Files.newInputStream(file.toPath());
             }
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
index 24601544..25d3748b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
@@ -129,7 +129,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase {
 
     @Test
     public void testDirectoryWithLongNameEndsWithSlash() throws IOException, ArchiveException {
-        final String rootPath = dir.getAbsolutePath();
+        final String rootPath = getTempDirFile().getAbsolutePath();
         final String dirDirectory = "COMPRESS-509";
         final int count = 100;
         final File root = new File(rootPath + "/" + dirDirectory);
@@ -320,7 +320,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase {
 
     @Test
     public void testShouldThrowAnExceptionOnTruncatedEntries() throws Exception {
-        final File dir = mkdir("COMPRESS-279");
+        final File dir = createTempDirectory("COMPRESS-279");
         try (TarArchiveInputStream is = getTestStream("/COMPRESS-279.tar")) {
             assertThrows(IOException.class, () -> {
                 TarArchiveEntry entry = is.getNextTarEntry();
@@ -331,8 +331,6 @@ public class TarArchiveInputStreamTest extends AbstractTestCase {
                     entry = is.getNextTarEntry();
                 }
             });
-        } finally {
-            forceDelete(dir);
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java
index b4f506fb..52d9e044 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java
@@ -119,7 +119,7 @@ public class TarFileTest extends AbstractTestCase {
 
     @Test
     public void testDirectoryWithLongNameEndsWithSlash() throws IOException {
-        final String rootPath = dir.getAbsolutePath();
+        final String rootPath = getTempDirFile().getAbsolutePath();
         final String dirDirectory = "COMPRESS-509";
         final int count = 100;
         final File root = new File(rootPath + "/" + dirDirectory);
@@ -198,7 +198,7 @@ public class TarFileTest extends AbstractTestCase {
     @Test
     public void testReadsArchiveCompletely_COMPRESS245() {
         try {
-            final Path tempTar = resultDir.toPath().resolve("COMPRESS-245.tar");
+            final Path tempTar = tempResultDir.toPath().resolve("COMPRESS-245.tar");
             try (final GZIPInputStream gin = new GZIPInputStream(
                     Files.newInputStream(getPath("COMPRESS-245.tar.gz")))) {
                 Files.copy(gin, tempTar);
@@ -252,9 +252,8 @@ public class TarFileTest extends AbstractTestCase {
 
     @Test
     public void testShouldThrowAnExceptionOnTruncatedEntries() throws Exception {
-        final File dir = mkdir("COMPRESS-279");
+        createTempDirectory("COMPRESS-279");
         assertThrows(IOException.class, () -> new TarFile(getPath("COMPRESS-279.tar")));
-        forceDelete(dir);
     }
 
     @Test
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
index dced22b8..aa0087c9 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
@@ -44,6 +44,7 @@ import org.apache.commons.compress.AbstractTestCase;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 public class X5455_ExtendedTimestampTest {
     private final static ZipShort X5455 = new ZipShort(0x5455);
@@ -82,6 +83,7 @@ public class X5455_ExtendedTimestampTest {
      */
     private X5455_ExtendedTimestamp xf;
 
+    @TempDir
     private File tmpDir;
 
     @BeforeEach
@@ -581,7 +583,6 @@ public class X5455_ExtendedTimestampTest {
 
     @Test
     public void testWriteReadRoundtrip() throws IOException {
-        tmpDir = AbstractTestCase.mkdir("X5455");
         final File output = new File(tmpDir, "write_rewrite.zip");
         final Date d = new Date(97, 8, 24, 15, 10, 2);
         try (final OutputStream out = Files.newOutputStream(output.toPath());
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStreamTest.java
index 39e7b7c5..369f70b5 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStreamTest.java
@@ -32,7 +32,7 @@ public class ZipSplitOutputStreamTest extends AbstractTestCase {
 
     @Test
     public void testCreateSplittedFiles() throws IOException {
-        final File testOutputFile = new File(dir, "testCreateSplittedFiles.zip");
+        final File testOutputFile = new File(getTempDirFile(), "testCreateSplittedFiles.zip");
         final int splitSize = 100 * 1024; /* 100 KB */
         final ZipSplitOutputStream zipSplitOutputStream = new ZipSplitOutputStream(testOutputFile, splitSize);
 
@@ -48,22 +48,22 @@ public class ZipSplitOutputStreamTest extends AbstractTestCase {
         }
         zipSplitOutputStream.close();
 
-        File zipFile = new File(dir.getPath(), "testCreateSplittedFiles.z01");
+        File zipFile = new File(getTempDirFile().getPath(), "testCreateSplittedFiles.z01");
         assertEquals(zipFile.length(), splitSize);
 
-        zipFile = new File(dir.getPath(), "testCreateSplittedFiles.z02");
+        zipFile = new File(getTempDirFile().getPath(), "testCreateSplittedFiles.z02");
         assertEquals(zipFile.length(), splitSize);
 
-        zipFile = new File(dir.getPath(), "testCreateSplittedFiles.z03");
+        zipFile = new File(getTempDirFile().getPath(), "testCreateSplittedFiles.z03");
         assertEquals(zipFile.length(), splitSize);
 
-        zipFile = new File(dir.getPath(), "testCreateSplittedFiles.z04");
+        zipFile = new File(getTempDirFile().getPath(), "testCreateSplittedFiles.z04");
         assertEquals(zipFile.length(), splitSize);
 
-        zipFile = new File(dir.getPath(), "testCreateSplittedFiles.z05");
+        zipFile = new File(getTempDirFile().getPath(), "testCreateSplittedFiles.z05");
         assertEquals(zipFile.length(), splitSize);
 
-        zipFile = new File(dir.getPath(), "testCreateSplittedFiles.zip");
+        zipFile = new File(getTempDirFile().getPath(), "testCreateSplittedFiles.zip");
         assertEquals(zipFile.length(), fileToTest.length() + 4 - splitSize * 5);
     }
 
diff --git a/src/test/java/org/apache/commons/compress/changes/ChangeSetRawTypesTest.java b/src/test/java/org/apache/commons/compress/changes/ChangeSetRawTypesTest.java
index 8603efac..fc04850b 100644
--- a/src/test/java/org/apache/commons/compress/changes/ChangeSetRawTypesTest.java
+++ b/src/test/java/org/apache/commons/compress/changes/ChangeSetRawTypesTest.java
@@ -542,7 +542,7 @@ public final class ChangeSetRawTypesTest extends AbstractTestCase {
         changeSet.delete("test2.xml");
         final File file1 = getFile("test.txt");
         final ArArchiveEntry entry = new ArArchiveEntry("test.txt", file1.length());
-        final Path result = dir.toPath().resolve("bla.ar");
+        final Path result = getTempDirFile().toPath().resolve("bla.ar");
         final String archiverName = "ar";
         try (InputStream inputStream = Files.newInputStream(getPath("bla.ar"));
                 ArchiveInputStream archiveInputStream = factory.createArchiveInputStream(archiverName, inputStream);
@@ -573,7 +573,7 @@ public final class ChangeSetRawTypesTest extends AbstractTestCase {
         changeSet.delete(".classpath");
         changeSet.delete(".project");
         final File input = getFile("bla.jar");
-        final Path result = dir.toPath().resolve("bla.jar");
+        final Path result = getTempDirFile().toPath().resolve("bla.jar");
         final String archiverName = "jar";
         try (InputStream inputStream = Files.newInputStream(input.toPath());
                 ArchiveInputStream archiveInputStream = factory.createArchiveInputStream(archiverName, inputStream);
@@ -604,7 +604,7 @@ public final class ChangeSetRawTypesTest extends AbstractTestCase {
         entry.setUserName("avalon");
         entry.setGroupName("excalibur");
         entry.setMode(0100000);
-        final File result = new File(dir, "bla.tar");
+        final File result = new File(getTempDirFile(), "bla.tar");
         final String archiverName = "tar";
         try (InputStream inputStream = Files.newInputStream(getPath("bla.tar"));
                 ArchiveInputStream archiveInputStream = factory.createArchiveInputStream(archiverName, inputStream);
@@ -695,7 +695,7 @@ public final class ChangeSetRawTypesTest extends AbstractTestCase {
         final ChangeSet changeSet = new ChangeSet();
         changeSet.delete("test2.xml");
         final File input = getFile("bla.ar");
-        final File result = new File(dir, "bla.ar");
+        final File result = new File(getTempDirFile(), "bla.ar");
         final String archiverName = "ar";
         try (InputStream inputStream = Files.newInputStream(input.toPath());
                 ArchiveInputStream archiveInputStream = factory.createArchiveInputStream(archiverName, inputStream);
@@ -725,7 +725,7 @@ public final class ChangeSetRawTypesTest extends AbstractTestCase {
         changeSet.delete(".classpath");
         changeSet.delete(".project");
         final File input = getFile("bla.jar");
-        final File result = new File(dir, "bla.jar");
+        final File result = new File(getTempDirFile(), "bla.jar");
         try (InputStream inputStream = Files.newInputStream(input.toPath());
                 ArchiveInputStream archiveInputStream = factory.createArchiveInputStream(archiverName, inputStream);
                 OutputStream newOutputStream = Files.newOutputStream(result.toPath());
@@ -748,7 +748,7 @@ public final class ChangeSetRawTypesTest extends AbstractTestCase {
     public void testDeleteFromTar() throws Exception {
         final ChangeSet changeSet = new ChangeSet();
         changeSet.delete("test2.xml");
-        final File result = new File(dir, "bla.tar");
+        final File result = new File(getTempDirFile(), "bla.tar");
         final String archiverName = "tar";
         try (InputStream inputStream = Files.newInputStream(getFile("bla.tar").toPath());
                 ArchiveInputStream archiveInputStream = factory.createArchiveInputStream(archiverName, inputStream);
diff --git a/src/test/java/org/apache/commons/compress/changes/ChangeSetSafeTypesTest.java b/src/test/java/org/apache/commons/compress/changes/ChangeSetSafeTypesTest.java
index 7c7471e9..281450a5 100644
--- a/src/test/java/org/apache/commons/compress/changes/ChangeSetSafeTypesTest.java
+++ b/src/test/java/org/apache/commons/compress/changes/ChangeSetSafeTypesTest.java
@@ -568,7 +568,7 @@ public final class ChangeSetSafeTypesTest<I extends ArchiveInputStream<E>, O ext
         final File file1 = getFile("test.txt");
         final ArArchiveEntry entry = new ArArchiveEntry("test.txt", file1.length());
         final File input = getFile("bla.ar");
-        final File result = new File(dir, "bla.ar");
+        final File result = new File(getTempDirFile(), "bla.ar");
         try (InputStream inputStream = Files.newInputStream(input.toPath());
                 ArchiveInputStream<ArArchiveEntry> ais = createArchiveInputStream(archiverName, inputStream);
                 OutputStream outputStream = Files.newOutputStream(result.toPath());
@@ -599,7 +599,7 @@ public final class ChangeSetSafeTypesTest<I extends ArchiveInputStream<E>, O ext
         final File file1 = getFile("test.txt");
         final JarArchiveEntry entry = new JarArchiveEntry("testdata/test.txt");
         final File input = getFile("bla.jar");
-        final File result = new File(dir, "bla.jar");
+        final File result = new File(getTempDirFile(), "bla.jar");
         try (InputStream inputStream = Files.newInputStream(input.toPath());
                 ArchiveInputStream<JarArchiveEntry> ais = createArchiveInputStream(archiverName, inputStream);
                 OutputStream outputStream = Files.newOutputStream(result.toPath());
@@ -629,7 +629,7 @@ public final class ChangeSetSafeTypesTest<I extends ArchiveInputStream<E>, O ext
         entry.setGroupName("excalibur");
         entry.setMode(0100000);
         final File input = getFile("bla.tar");
-        final File result = new File(dir, "bla.tar");
+        final File result = new File(getTempDirFile(), "bla.tar");
         try (InputStream inputStream = Files.newInputStream(input.toPath());
                 ArchiveInputStream<TarArchiveEntry> ais = createArchiveInputStream(archiverName, inputStream);
                 OutputStream outputStream = Files.newOutputStream(result.toPath());
@@ -716,7 +716,7 @@ public final class ChangeSetSafeTypesTest<I extends ArchiveInputStream<E>, O ext
         final ChangeSet<E> changeSet = createChangeSet();
         changeSet.delete("test2.xml");
         final File input = getFile("bla.ar");
-        final File temp = new File(dir, "bla.ar");
+        final File temp = new File(getTempDirFile(), "bla.ar");
         try (InputStream inputStream = Files.newInputStream(input.toPath());
                 ArchiveInputStream<E> ais = createArchiveInputStream(archiverName, inputStream);
                 OutputStream outputStream = Files.newOutputStream(temp.toPath());
@@ -745,7 +745,7 @@ public final class ChangeSetSafeTypesTest<I extends ArchiveInputStream<E>, O ext
         changeSet.delete(".project");
 
         final File input = getFile("bla.jar");
-        final File temp = new File(dir, "bla.jar");
+        final File temp = new File(getTempDirFile(), "bla.jar");
         try (InputStream inputStream = Files.newInputStream(input.toPath());
                 ArchiveInputStream<E> ais = createArchiveInputStream(archiverName, inputStream);
                 OutputStream outputStream = Files.newOutputStream(temp.toPath());
@@ -768,7 +768,7 @@ public final class ChangeSetSafeTypesTest<I extends ArchiveInputStream<E>, O ext
         final ChangeSet<E> changeSet = createChangeSet();
         changeSet.delete("test2.xml");
         final File input = getFile("bla.tar");
-        final File temp = new File(dir, "bla.tar");
+        final File temp = new File(getTempDirFile(), "bla.tar");
         try (InputStream inputStream = Files.newInputStream(input.toPath());
                 ArchiveInputStream<E> ais = createArchiveInputStream(archiverName, inputStream);
                 OutputStream outputStream = Files.newOutputStream(temp.toPath());
diff --git a/src/test/java/org/apache/commons/compress/compressors/BZip2TestCase.java b/src/test/java/org/apache/commons/compress/compressors/BZip2TestCase.java
index a3a57147..489fb1f5 100644
--- a/src/test/java/org/apache/commons/compress/compressors/BZip2TestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/BZip2TestCase.java
@@ -34,7 +34,7 @@ public final class BZip2TestCase extends AbstractTestCase {
     @Test
     public void testBzip2Unarchive() throws Exception {
         final File input = getFile("bla.txt.bz2");
-        final File output = new File(dir, "bla.txt");
+        final File output = new File(getTempDirFile(), "bla.txt");
         try (final InputStream is = Files.newInputStream(input.toPath());
                 CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is)) {
             Files.copy(in, output.toPath());
@@ -46,14 +46,14 @@ public final class BZip2TestCase extends AbstractTestCase {
         File output;
         final File input = getFile("test.txt");
         {
-            output = new File(dir, "test.txt.bz2");
+            output = new File(getTempDirFile(), "test.txt.bz2");
             try (OutputStream out = Files.newOutputStream(output.toPath());
                     final CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("bzip2", out)) {
                 Files.copy(input.toPath(), cos);
             }
         }
 
-        final File decompressed = new File(dir, "decompressed.txt");
+        final File decompressed = new File(getTempDirFile(), "decompressed.txt");
         {
             try (InputStream is = Files.newInputStream(output.toPath());
                     CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is)) {
diff --git a/src/test/java/org/apache/commons/compress/compressors/DeflateTestCase.java b/src/test/java/org/apache/commons/compress/compressors/DeflateTestCase.java
index e88bab9c..39b59c3c 100644
--- a/src/test/java/org/apache/commons/compress/compressors/DeflateTestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/DeflateTestCase.java
@@ -39,7 +39,7 @@ public final class DeflateTestCase extends AbstractTestCase {
     @Test
     public void testDeflateCreation() throws Exception {
         final File input = getFile("test1.xml");
-        final File output = new File(dir, "test1.xml.deflatez");
+        final File output = new File(getTempDirFile(), "test1.xml.deflatez");
         try (OutputStream out = Files.newOutputStream(output.toPath())) {
             try (CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("deflate", out)) {
                 Files.copy(input.toPath(), cos);
@@ -55,7 +55,7 @@ public final class DeflateTestCase extends AbstractTestCase {
     @Test
     public void testDeflateUnarchive() throws Exception {
         final File input = getFile("bla.tar.deflatez");
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         try (InputStream is = Files.newInputStream(input.toPath())) {
             // zlib header is expected by default
             try (CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("deflate", is)) {
@@ -72,7 +72,7 @@ public final class DeflateTestCase extends AbstractTestCase {
     @Test
     public void testRawDeflateCreation()  throws Exception {
         final File input = getFile("test1.xml");
-        final File output = new File(dir, "test1.xml.deflate");
+        final File output = new File(getTempDirFile(), "test1.xml.deflate");
         try (OutputStream out = Files.newOutputStream(output.toPath())) {
             final DeflateParameters params = new DeflateParameters();
             params.setWithZlibHeader(false);
@@ -90,7 +90,7 @@ public final class DeflateTestCase extends AbstractTestCase {
     @Test
     public void testRawDeflateUnarchive() throws Exception {
         final File input = getFile("bla.tar.deflate");
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         try (InputStream is = Files.newInputStream(input.toPath())) {
             final DeflateParameters params = new DeflateParameters();
             params.setWithZlibHeader(false);
diff --git a/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java b/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java
index 70885a4d..145fb031 100644
--- a/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java
@@ -62,7 +62,7 @@ public final class FramedSnappyTestCase
 
     private void testRoundtrip(final File input) throws Exception {
         final long start = System.currentTimeMillis();
-        final File outputSz = new File(dir, input.getName() + ".sz");
+        final File outputSz = new File(getTempDirFile(), input.getName() + ".sz");
         try (OutputStream os = Files.newOutputStream(outputSz.toPath());
                 CompressorOutputStream sos = new CompressorStreamFactory().createCompressorOutputStream("snappy-framed", os)) {
             Files.copy(input.toPath(), sos);
@@ -81,14 +81,14 @@ public final class FramedSnappyTestCase
     @Test
     public void testRoundtripWithOneBigWrite() throws Exception {
         final Random r = new Random();
-        final File input = new File(dir, "bigChunkTest");
+        final File input = new File(getTempDirFile(), "bigChunkTest");
         try (OutputStream fs = Files.newOutputStream(input.toPath())) {
             for (int i = 0 ; i < 1 << 17; i++) {
                 fs.write(r.nextInt(256));
             }
         }
         final long start = System.currentTimeMillis();
-        final File outputSz = new File(dir, input.getName() + ".sz");
+        final File outputSz = new File(getTempDirFile(), input.getName() + ".sz");
         try (InputStream is = Files.newInputStream(input.toPath());
              OutputStream os = Files.newOutputStream(outputSz.toPath());
              CompressorOutputStream sos = new CompressorStreamFactory()
@@ -110,7 +110,7 @@ public final class FramedSnappyTestCase
 
     private void testUnarchive(final StreamWrapper<CompressorInputStream> wrapper) throws Exception {
         final File input = getFile("bla.tar.sz");
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         try (InputStream is = Files.newInputStream(input.toPath())) {
             // the intermediate BufferedInputStream is there for mark
             // support in the autodetection test
diff --git a/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java b/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java
index e16009ba..f56f1f6f 100644
--- a/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java
@@ -115,7 +115,7 @@ public final class GZipTestCase extends AbstractTestCase {
     @Test
     public void testGzipCreation() throws Exception {
         final File input = getFile("test1.xml");
-        final File output = new File(dir, "test1.xml.gz");
+        final File output = new File(getTempDirFile(), "test1.xml.gz");
         try (OutputStream out = Files.newOutputStream(output.toPath())) {
             try (CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("gz", out)) {
                 Files.copy(input.toPath(), cos);
@@ -126,7 +126,7 @@ public final class GZipTestCase extends AbstractTestCase {
     @Test
     public void testGzipUnarchive() throws Exception {
         final File input = getFile("bla.tgz");
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         try (InputStream is = Files.newInputStream(input.toPath())) {
             try (CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("gz", is);) {
                 Files.copy(in, output.toPath());
diff --git a/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java b/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java
index b9ecdef5..eb25730b 100644
--- a/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java
@@ -38,7 +38,7 @@ public final class LZMATestCase extends AbstractTestCase {
     @Test
     public void testLzmaRoundtrip() throws Exception {
         final File input = getFile("test1.xml");
-        final File compressed = new File(dir, "test1.xml.xz");
+        final File compressed = new File(getTempDirFile(), "test1.xml.xz");
         try (OutputStream out = Files.newOutputStream(compressed.toPath())) {
             try (CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("lzma", out)) {
                 Files.copy(input.toPath(), cos);
@@ -55,7 +55,7 @@ public final class LZMATestCase extends AbstractTestCase {
     @Test
     public void testLZMAUnarchive() throws Exception {
         final File input = getFile("bla.tar.lzma");
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         try (InputStream is = Files.newInputStream(input.toPath())) {
             try (final CompressorInputStream in = new LZMACompressorInputStream(is)) {
                 Files.copy(in, output.toPath());
@@ -66,7 +66,7 @@ public final class LZMATestCase extends AbstractTestCase {
     @Test
     public void testLZMAUnarchiveWithAutodetection() throws Exception {
         final File input = getFile("bla.tar.lzma");
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         try (InputStream is = new BufferedInputStream(Files.newInputStream(input.toPath()))) {
             try (final CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream(is)) {
                 Files.copy(in, output.toPath());
diff --git a/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java b/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java
index 42bc864f..b224fa42 100644
--- a/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java
@@ -46,7 +46,7 @@ import org.junit.jupiter.api.Test;
 public final class Pack200TestCase extends AbstractTestCase {
 
     private void jarArchiveCreation(final Pack200Strategy mode) throws Exception {
-        final File output = new File(dir, "bla.pack");
+        final File output = new File(getTempDirFile(), "bla.pack");
 
         final File file1 = getFile("test1.xml");
         final File file2 = getFile("test2.xml");
@@ -82,7 +82,7 @@ public final class Pack200TestCase extends AbstractTestCase {
 
             ArchiveEntry entry = in.getNextEntry();
             while (entry != null) {
-                final File archiveEntry = new File(dir, entry.getName());
+                final File archiveEntry = new File(getTempDirFile(), entry.getName());
                 archiveEntry.getParentFile().mkdirs();
                 if (entry.isDirectory()) {
                     archiveEntry.mkdir();
@@ -197,7 +197,7 @@ public final class Pack200TestCase extends AbstractTestCase {
 
     @Test
     public void testOutputStreamMethods() throws Exception {
-        final File output = new File(dir, "bla.pack");
+        final File output = new File(getTempDirFile(), "bla.pack");
         final Map<String, String> m = new HashMap<>();
         m.put("foo", "bar");
         try (OutputStream out = Files.newOutputStream(output.toPath());
diff --git a/src/test/java/org/apache/commons/compress/compressors/XZTestCase.java b/src/test/java/org/apache/commons/compress/compressors/XZTestCase.java
index 3178d915..97a75dcd 100644
--- a/src/test/java/org/apache/commons/compress/compressors/XZTestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/XZTestCase.java
@@ -61,7 +61,7 @@ public final class XZTestCase extends AbstractTestCase {
         final long max = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax();
         System.out.println("XZTestCase: HeapMax=" + max + " bytes " + (double) max / (1024 * 1024) + " MB");
         final File input = getFile("test1.xml");
-        final File output = new File(dir, "test1.xml.xz");
+        final File output = new File(getTempDirFile(), "test1.xml.xz");
         try (OutputStream out = Files.newOutputStream(output.toPath())) {
             try (CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("xz", out)) {
                 Files.copy(input.toPath(), cos);
@@ -72,7 +72,7 @@ public final class XZTestCase extends AbstractTestCase {
     @Test
     public void testXZUnarchive() throws Exception {
         final File input = getFile("bla.tar.xz");
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         try (InputStream is = Files.newInputStream(input.toPath())) {
             try (CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("xz", is)) {
                 Files.copy(in, output.toPath());
diff --git a/src/test/java/org/apache/commons/compress/compressors/ZTestCase.java b/src/test/java/org/apache/commons/compress/compressors/ZTestCase.java
index 7af2dc4c..96c353c2 100644
--- a/src/test/java/org/apache/commons/compress/compressors/ZTestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/ZTestCase.java
@@ -43,7 +43,7 @@ public final class ZTestCase extends AbstractTestCase {
 
     private void testUnarchive(final StreamWrapper<CompressorInputStream> wrapper) throws Exception {
         final File input = getFile("bla.tar.Z");
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         try (InputStream is = Files.newInputStream(input.toPath())) {
             try (InputStream in = wrapper.wrap(is)) {
                 Files.copy(in, output.toPath());
diff --git a/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java
index 7aba9e1a..b40ac932 100644
--- a/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java
@@ -66,7 +66,7 @@ public class BrotliCompressorInputStreamTest extends AbstractTestCase {
 
     @Test
     public void testBrotliUnarchive() throws Exception {
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         try (InputStream is = newInputStream("bla.tar.br")) {
             try (CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("br", is)) {
                 Files.copy(in, output.toPath());
diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorRoundtripTest.java
index fa72b49b..3682096d 100644
--- a/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorRoundtripTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorRoundtripTest.java
@@ -67,7 +67,7 @@ public final class BlockLZ4CompressorRoundtripTest extends AbstractTestCase {
     private void roundTripTest(final String testFile, final String config, final Parameters params) throws IOException {
         final File input = getFile(testFile);
         long start = System.currentTimeMillis();
-        final File outputSz = new File(dir, input.getName() + ".block.lz4");
+        final File outputSz = new File(getTempDirFile(), input.getName() + ".block.lz4");
         try (OutputStream os = Files.newOutputStream(outputSz.toPath()); BlockLZ4CompressorOutputStream los = new BlockLZ4CompressorOutputStream(os, params)) {
             Files.copy(input.toPath(), los);
         }
diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/FactoryTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/FactoryTest.java
index a91e793b..8f4745d6 100644
--- a/src/test/java/org/apache/commons/compress/compressors/lz4/FactoryTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/lz4/FactoryTest.java
@@ -35,7 +35,7 @@ public class FactoryTest extends AbstractTestCase {
     private void roundtripViaFactory(final String format) throws Exception {
         final Path input = getPath("bla.tar");
         long start = System.currentTimeMillis();
-        final Path outputSz = dir.toPath().resolve(input.getFileName() + "." + format + ".lz4");
+        final Path outputSz = getTempDirFile().toPath().resolve(input.getFileName() + "." + format + ".lz4");
         try (OutputStream os = Files.newOutputStream(outputSz);
                 OutputStream los = new CompressorStreamFactory().createCompressorOutputStream(format, os)) {
             Files.copy(input, los);
diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java
index f48b7c79..c772bc8c 100644
--- a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java
@@ -80,7 +80,7 @@ public final class FramedLZ4CompressorRoundtripTest extends AbstractTestCase {
     private void roundTripTest(final String testFile, final FramedLZ4CompressorOutputStream.Parameters params) throws IOException {
         final File input = getFile(testFile);
         long start = System.currentTimeMillis();
-        final File outputSz = new File(dir, input.getName() + ".framed.lz4");
+        final File outputSz = new File(getTempDirFile(), input.getName() + ".framed.lz4");
         byte[] expected;
         try (InputStream is = Files.newInputStream(input.toPath())) {
             expected = IOUtils.toByteArray(is);
diff --git a/src/test/java/org/apache/commons/compress/compressors/pack200/Pack200UtilsTest.java b/src/test/java/org/apache/commons/compress/compressors/pack200/Pack200UtilsTest.java
index e7aeb34d..b060eade 100644
--- a/src/test/java/org/apache/commons/compress/compressors/pack200/Pack200UtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/pack200/Pack200UtilsTest.java
@@ -35,62 +35,47 @@ public final class Pack200UtilsTest extends AbstractTestCase {
     @Test
     public void testNormalize() throws Throwable {
         final File input = getFile("bla.jar");
-        final File[] output = createTempDirAndFile();
-        try {
-            Pack200Utils.normalize(input, output[1], new HashMap<>());
-            try (InputStream is = Files.newInputStream(output[1].toPath());
-                    ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
-
-                ArchiveEntry entry = in.getNextEntry();
-                while (entry != null) {
-                    final File archiveEntry = new File(dir, entry.getName());
-                    archiveEntry.getParentFile().mkdirs();
-                    if (entry.isDirectory()) {
-                        archiveEntry.mkdir();
-                        entry = in.getNextEntry();
-                        continue;
-                    }
-                    Files.copy(in, archiveEntry.toPath());
+        final File output = createTempFile();
+        Pack200Utils.normalize(input, output, new HashMap<>());
+        try (InputStream is = Files.newInputStream(output.toPath());
+                ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+            ArchiveEntry entry = in.getNextEntry();
+            while (entry != null) {
+                final File archiveEntry = new File(getTempDirFile(), entry.getName());
+                archiveEntry.getParentFile().mkdirs();
+                if (entry.isDirectory()) {
+                    archiveEntry.mkdir();
                     entry = in.getNextEntry();
+                    continue;
                 }
-
+                Files.copy(in, archiveEntry.toPath());
+                entry = in.getNextEntry();
             }
-        } finally {
-            output[1].delete();
-            output[0].delete();
         }
     }
 
     @Test
     public void testNormalizeInPlace() throws Throwable {
         final File input = getFile("bla.jar");
-        final File[] output = createTempDirAndFile();
-        try {
-            try (InputStream is = Files.newInputStream(input.toPath())) {
-                Files.copy(is, output[1].toPath(), StandardCopyOption.REPLACE_EXISTING);
-            }
-
-            Pack200Utils.normalize(output[1]);
-
-            try (InputStream is = Files.newInputStream(output[1].toPath());
-                    ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
-
-                ArchiveEntry entry = in.getNextEntry();
-                while (entry != null) {
-                    final File archiveEntry = new File(dir, entry.getName());
-                    archiveEntry.getParentFile().mkdirs();
-                    if (entry.isDirectory()) {
-                        archiveEntry.mkdir();
-                        entry = in.getNextEntry();
-                        continue;
-                    }
-                    Files.copy(in, archiveEntry.toPath());
+        final File output = createTempFile();
+        try (InputStream is = Files.newInputStream(input.toPath())) {
+            Files.copy(is, output.toPath(), StandardCopyOption.REPLACE_EXISTING);
+        }
+        Pack200Utils.normalize(output);
+        try (InputStream is = Files.newInputStream(output.toPath());
+                ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+            ArchiveEntry entry = in.getNextEntry();
+            while (entry != null) {
+                final File archiveEntry = new File(getTempDirFile(), entry.getName());
+                archiveEntry.getParentFile().mkdirs();
+                if (entry.isDirectory()) {
+                    archiveEntry.mkdir();
                     entry = in.getNextEntry();
+                    continue;
                 }
+                Files.copy(in, archiveEntry.toPath());
+                entry = in.getNextEntry();
             }
-        } finally {
-            output[1].delete();
-            output[0].delete();
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java
index fa04bdcb..37092d8e 100644
--- a/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStreamTest.java
@@ -73,8 +73,8 @@ public final class FramedSnappyCompressorInputStreamTest extends AbstractTestCas
      */
     @Test
     public void testLoremIpsum() throws Exception {
-        final File outputSz = new File(dir, "lorem-ipsum.1");
-        final File outputGz = new File(dir, "lorem-ipsum.2");
+        final File outputSz = new File(getTempDirFile(), "lorem-ipsum.1");
+        final File outputGz = new File(getTempDirFile(), "lorem-ipsum.2");
         try (InputStream isSz = newInputStream("lorem-ipsum.txt.sz")) {
             try (InputStream in = new FramedSnappyCompressorInputStream(isSz)) {
                 Files.copy(in, outputSz.toPath());
@@ -115,7 +115,7 @@ public final class FramedSnappyCompressorInputStreamTest extends AbstractTestCas
         try (ZipFile zip = new ZipFile(getFile("testNumbersNew.numbers"))) {
             try (InputStream is = zip.getInputStream(zip.getEntry("Index/Document.iwa"))) {
                 try (FramedSnappyCompressorInputStream in = new FramedSnappyCompressorInputStream(is, FramedSnappyDialect.IWORK_ARCHIVE)) {
-                    Files.copy(in, new File(dir, "snappyIWATest.raw").toPath());
+                    Files.copy(in, new File(getTempDirFile(), "snappyIWATest.raw").toPath());
                 }
             }
         }
@@ -126,7 +126,7 @@ public final class FramedSnappyCompressorInputStreamTest extends AbstractTestCas
      */
     @Test
     public void testReadIWAFileWithBiggerOffset() throws Exception {
-        final File o = new File(dir, "COMPRESS-358.raw");
+        final File o = new File(getTempDirFile(), "COMPRESS-358.raw");
         try (InputStream is = newInputStream("COMPRESS-358.iwa");
                 FramedSnappyCompressorInputStream in = new FramedSnappyCompressorInputStream(is, 1 << 16, FramedSnappyDialect.IWORK_ARCHIVE);) {
             Files.copy(in, o.toPath());
diff --git a/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java
index 8f2f84fe..4445aaa7 100644
--- a/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/snappy/SnappyRoundtripTest.java
@@ -67,7 +67,7 @@ public final class SnappyRoundtripTest extends AbstractTestCase {
 
     private void roundTripTest(final File input, final Parameters params) throws IOException {
         long start = System.currentTimeMillis();
-        final File outputSz = new File(dir, input.getName() + ".raw.sz");
+        final File outputSz = new File(getTempDirFile(), input.getName() + ".raw.sz");
         try (OutputStream os = Files.newOutputStream(outputSz.toPath());
                 SnappyCompressorOutputStream sos = new SnappyCompressorOutputStream(os, input.length(), params)) {
             Files.copy(input.toPath(), sos);
@@ -139,7 +139,7 @@ public final class SnappyRoundtripTest extends AbstractTestCase {
         // Start with the four byte sequence 0000 after that add > 64k
         // of random noise that doesn't contain any 0000 at all, then
         // add 0000.
-        final File f = new File(dir, "reallyBigOffsetTest");
+        final File f = new File(getTempDirFile(), "reallyBigOffsetTest");
         final ByteArrayOutputStream fs = new ByteArrayOutputStream((1<<16) + 1024);
             fs.write(0);
             fs.write(0);
@@ -173,7 +173,7 @@ public final class SnappyRoundtripTest extends AbstractTestCase {
         // The four byte methods would require even more luck and a
         // buffer (and a file written to disk) that was 2^5 bigger
         // than the buffer used here.
-        final File f = new File(dir, "reallyBigLiteralTest");
+        final File f = new File(getTempDirFile(), "reallyBigLiteralTest");
         try (OutputStream fs = Files.newOutputStream(f.toPath())) {
             final int cnt = 1 << 19;
             final Random r = new Random();
diff --git a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java
index 5a7a18a2..7837eb7f 100644
--- a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java
@@ -122,7 +122,7 @@ public class ZstdCompressorInputStreamTest extends AbstractTestCase {
     @Test
     public void testZstandardUnarchive() throws Exception {
         final File input = getFile("bla.tar.zst");
-        final File output = new File(dir, "bla.tar");
+        final File output = new File(getTempDirFile(), "bla.tar");
         try (InputStream is = Files.newInputStream(input.toPath())) {
             try (CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("zstd", is);) {
                 Files.copy(in, output.toPath());
diff --git a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java
index d3f55319..7c817048 100644
--- a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java
@@ -42,7 +42,7 @@ public class ZstdRoundtripTest extends AbstractTestCase {
     private void roundtrip(final OutputStreamCreator oc) throws IOException {
         final File input = getFile("bla.tar");
         long start = System.currentTimeMillis();
-        final File output = new File(dir, input.getName() + ".zstd");
+        final File output = new File(getTempDirFile(), input.getName() + ".zstd");
         try (FileOutputStream os = new FileOutputStream(output);
              ZstdCompressorOutputStream zos = oc.wrap(os)) {
             Files.copy(input.toPath(), zos);
@@ -68,7 +68,7 @@ public class ZstdRoundtripTest extends AbstractTestCase {
     public void testFactoryRoundtrip() throws Exception {
         final File input = getFile("bla.tar");
         long start = System.currentTimeMillis();
-        final File output = new File(dir, input.getName() + ".zstd");
+        final File output = new File(getTempDirFile(), input.getName() + ".zstd");
         try (OutputStream os = Files.newOutputStream(output.toPath());
                 CompressorOutputStream zos = new CompressorStreamFactory().createCompressorOutputStream("zstd", os)) {
             Files.copy(input.toPath(), zos);
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
index 44d116ef..2a743292 100755
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
@@ -73,7 +73,7 @@ public class ArchiveTest {
             final JarEntry entry2 = jarFile2.getJarEntry(name);
             assertNotNull(entry2, "Missing Entry: " + name);
 //            assertEquals(entry.getTime(), entry2.getTime());
-            if (!name.equals("META-INF/MANIFEST.MF")) { 
+            if (!name.equals("META-INF/MANIFEST.MF")) {
                 // Manifests aren't necessarily byte-for-byte identical
                 final InputStream ours = jarFile.getInputStream(entry);
                 final InputStream expected = jarFile2.getInputStream(entry2);