You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2020/09/15 18:57:59 UTC

[logging-log4j2] 06/10: Migrate rolling action tests to JUnit 5

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

mattsicker pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 6abea70e808beff9fe6dd7d9669de1e4e6e5867f
Author: Matt Sicker <bo...@gmail.com>
AuthorDate: Sun Sep 13 20:10:51 2020 -0500

    Migrate rolling action tests to JUnit 5
    
    Backported from 3.x.
    
    Signed-off-by: Matt Sicker <bo...@gmail.com>
---
 .../rolling/action/AbstractActionTest.java         | 33 ++++----
 .../rolling/action/Bzip2CompressActionTest.java    | 39 +++++-----
 .../appender/rolling/action/DeleteActionTest.java  | 15 ++--
 .../rolling/action/DeletingVisitorTest.java        | 10 +--
 .../core/appender/rolling/action/DurationTest.java | 21 +++---
 .../rolling/action/FileRenameActionTest.java       | 87 +++++-----------------
 .../core/appender/rolling/action/FileSizeTest.java | 13 ++--
 .../rolling/action/IfAccumulatedFileCountTest.java |  6 +-
 .../rolling/action/IfAccumulatedFileSizeTest.java  |  4 +-
 .../core/appender/rolling/action/IfAllTest.java    | 10 +--
 .../core/appender/rolling/action/IfAnyTest.java    |  8 +-
 .../appender/rolling/action/IfFileNameTest.java    | 22 +++---
 .../rolling/action/IfLastModifiedTest.java         |  4 +-
 .../core/appender/rolling/action/IfNotTest.java    | 10 +--
 .../action/PathSortByModificationTimeTest.java     | 52 ++++++-------
 .../rolling/action/ScriptConditionTest.java        | 31 ++++----
 .../rolling/action/SortingVisitorTest.java         | 57 ++++++--------
 17 files changed, 178 insertions(+), 244 deletions(-)

diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractActionTest.java
index a1c3d21..fc2b7f1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractActionTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractActionTest.java
@@ -16,24 +16,23 @@
  */
 package org.apache.logging.log4j.core.appender.rolling.action;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.junit.StatusLoggerLevel;
+import org.apache.logging.log4j.status.StatusData;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 import java.util.List;
 
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.junit.StatusLoggerRule;
-import org.apache.logging.log4j.status.StatusData;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.junit.Rule;
-import org.junit.Test;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
+@StatusLoggerLevel("WARN")
 public class AbstractActionTest {
 
-    @Rule
-    public StatusLoggerRule statusLogger = new StatusLoggerRule(Level.WARN);
-
     // Test for LOG4J2-2658
     @Test
     public void testExceptionsAreLoggedToStatusLogger() {
@@ -41,11 +40,11 @@ public class AbstractActionTest {
         statusLogger.clear();
         new TestAction().run();
         List<StatusData> statusDataList = statusLogger.getStatusData();
-        assertEquals(1, statusDataList.size());
+        assertThat(statusDataList, hasSize(1));
         StatusData statusData = statusDataList.get(0);
         assertEquals(Level.WARN, statusData.getLevel());
         String formattedMessage = statusData.getFormattedStatus();
-        assertTrue(formattedMessage, formattedMessage.contains("Exception reported by action 'class org.apache."
+        assertThat(formattedMessage, containsString("Exception reported by action 'class org.apache."
                 + "logging.log4j.core.appender.rolling.action.AbstractActionTest$TestAction' java.io.IOException: "
                 + "failed" + System.lineSeparator()
                 + "\tat org.apache.logging.log4j.core.appender.rolling.action.AbstractActionTest"
@@ -63,11 +62,11 @@ public class AbstractActionTest {
             }
         }.run();
         List<StatusData> statusDataList = statusLogger.getStatusData();
-        assertEquals(1, statusDataList.size());
+        assertThat(statusDataList, hasSize(1));
         StatusData statusData = statusDataList.get(0);
         assertEquals(Level.WARN, statusData.getLevel());
         String formattedMessage = statusData.getFormattedStatus();
-        assertTrue(formattedMessage.contains("Exception reported by action"));
+        assertThat(formattedMessage, containsString("Exception reported by action"));
     }
 
     @Test
@@ -81,11 +80,11 @@ public class AbstractActionTest {
             }
         }.run();
         List<StatusData> statusDataList = statusLogger.getStatusData();
-        assertEquals(1, statusDataList.size());
+        assertThat(statusDataList, hasSize(1));
         StatusData statusData = statusDataList.get(0);
         assertEquals(Level.WARN, statusData.getLevel());
         String formattedMessage = statusData.getFormattedStatus();
-        assertTrue(formattedMessage.contains("Exception reported by action"));
+        assertThat(formattedMessage, containsString("Exception reported by action"));
     }
 
     private static final class TestAction extends AbstractAction {
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/Bzip2CompressActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/Bzip2CompressActionTest.java
index 8178adc..bde1b75 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/Bzip2CompressActionTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/Bzip2CompressActionTest.java
@@ -17,30 +17,33 @@
 
 package org.apache.logging.log4j.core.appender.rolling.action;
 
+import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 
-import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests Bzip2CompressAction.
  */
 public class Bzip2CompressActionTest {
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testConstructorDisallowsNullSource() {
-        new CommonsCompressAction("bzip2", null, new File("any"), true);
+        assertThrows(NullPointerException.class,
+                () -> new CommonsCompressAction("bzip2", null, new File("any"), true));
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testConstructorDisallowsNullDestination() {
-        new CommonsCompressAction("bzip2", new File("any"), null, true);
+        assertThrows(NullPointerException.class,
+                () -> new CommonsCompressAction("bzip2", new File("any"), null, true));
     }
 
     @Test
@@ -50,29 +53,28 @@ public class Bzip2CompressActionTest {
             source = new File(source.getName() + Math.random());
         }
         final boolean actual = CommonsCompressAction.execute("bzip2", source, new File("any2"), true);
-        assertEquals("Cannot compress non-existing file", false, actual);
+        assertFalse(actual, "Cannot compress non-existing file");
     }
 
     @Test
-    public void testExecuteCompressesSourceFileToDestinationFile() throws IOException {
+    public void testExecuteCompressesSourceFileToDestinationFile(@TempDir final File tempDir) throws IOException {
         final String LINE1 = "Here is line 1. Random text: ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
         final String LINE2 = "Here is line 2. Random text: ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
         final String LINE3 = "Here is line 3. Random text: ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
-        final File source = new File("target/compressme");
+        final File source = new File(tempDir, "compressme");
         try (FileWriter fw = new FileWriter(source, false)) {
             fw.write(LINE1);
             fw.write(LINE2);
             fw.write(LINE3);
             fw.flush();
         }
-        final File destination = new File("target/compressme.bz2");
-        destination.delete(); // just in case
-        assertFalse("Destination should not exist yet", destination.exists());
+        final File destination = new File(tempDir, "compressme.bz2");
+        assertFalse(destination.exists(), "Destination should not exist yet");
 
         final boolean actual = CommonsCompressAction.execute("bzip2", source, destination, true);
-        assertEquals("Bzip2CompressAction should have succeeded", true, actual);
-        assertTrue("Destination should exist after Bzip2CompressAction", destination.exists());
-        assertFalse("Source should have been deleted", source.exists());
+        assertTrue(actual, "Bzip2CompressAction should have succeeded");
+        assertTrue(destination.exists(), "Destination should exist after Bzip2CompressAction");
+        assertFalse(source.exists(), "Source should have been deleted");
 
         final byte[] bz2 = new byte[] { (byte) 0x42, (byte) 0x5A, (byte) 0x68, (byte) 0x39, (byte) 0x31, (byte) 0x41,
                 (byte) 0x59, (byte) 0x26, (byte) 0x53, (byte) 0x59, (byte) 0x9C, (byte) 0xE1, (byte) 0xE8, (byte) 0x2D,
@@ -102,9 +104,8 @@ public class Bzip2CompressActionTest {
                 n = fis.read(actualBz2, offset, actualBz2.length - offset);
                 offset += n;
             } while (offset < actualBz2.length);
-            assertArrayEquals("Compressed data corrupt", bz2, actualBz2);
+            assertArrayEquals(bz2, actualBz2, "Compressed data corrupt");
         }
-        destination.delete();
 
         // uncompress
         try (BZip2CompressorInputStream bzin = new BZip2CompressorInputStream(new ByteArrayInputStream(bz2))) {
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java
index 8f13ae2..222845b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java
@@ -26,13 +26,12 @@ import java.util.Collections;
 import java.util.EnumSet;
 
 import org.apache.logging.log4j.core.BasicConfigurationFactory;
-import org.apache.logging.log4j.core.appender.rolling.action.DeleteAction;
-import org.apache.logging.log4j.core.appender.rolling.action.DeletingVisitor;
-import org.apache.logging.log4j.core.appender.rolling.action.PathCondition;
 import org.apache.logging.log4j.core.config.Configuration;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the {@code DeleteAction} class.
@@ -98,7 +97,7 @@ public class DeleteActionTest {
     public void testCreateFileVisitorReturnsDeletingVisitor() {
         final DeleteAction delete = createAnyFilter("any", true, 0, false);
         final FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions());
-        assertTrue(visitor instanceof DeletingVisitor);
+        assertThat(visitor, instanceOf(DeletingVisitor.class));
     }
 
     @Test
@@ -106,14 +105,14 @@ public class DeleteActionTest {
         final DeleteAction delete = createAnyFilter("any", true, 0, false);
         assertFalse(delete.isTestMode());
         final FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions());
-        assertTrue(visitor instanceof DeletingVisitor);
+        assertThat(visitor, instanceOf(DeletingVisitor.class));
         assertFalse(((DeletingVisitor) visitor).isTestMode());
 
         final DeleteAction deleteTestMode = createAnyFilter("any", true, 0, true);
         assertTrue(deleteTestMode.isTestMode());
         final FileVisitor<Path> testVisitor = deleteTestMode.createFileVisitor(delete.getBasePath(),
                 delete.getPathConditions());
-        assertTrue(testVisitor instanceof DeletingVisitor);
+        assertThat(testVisitor, instanceOf(DeletingVisitor.class));
         assertTrue(((DeletingVisitor) testVisitor).isTestMode());
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java
index ed472ad..98cd8b8 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java
@@ -28,9 +28,9 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the {@code DeletingVisitor} class.
@@ -58,7 +58,7 @@ public class DeletingVisitorTest {
     public void testAcceptedFilesAreDeleted() throws IOException {
         final Path base = Paths.get("/a/b/c");
         final FixedCondition ACCEPT_ALL = new FixedCondition(true);
-        final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(ACCEPT_ALL), false);
+        final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Collections.singletonList(ACCEPT_ALL), false);
 
         final Path any = Paths.get("/a/b/c/any");
         visitor.visitFile(any, null);
@@ -69,7 +69,7 @@ public class DeletingVisitorTest {
     public void testRejectedFilesAreNotDeleted() throws IOException {
         final Path base = Paths.get("/a/b/c");
         final FixedCondition REJECT_ALL = new FixedCondition(false);
-        final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(REJECT_ALL), false);
+        final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Collections.singletonList(REJECT_ALL), false);
 
         final Path any = Paths.get("/a/b/c/any");
         visitor.visitFile(any, null);
@@ -130,7 +130,7 @@ public class DeletingVisitorTest {
             }
         };
         final Path base = Paths.get("/a/b/c");
-        final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(filter), false);
+        final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Collections.singletonList(filter), false);
 
         final Path child = Paths.get("/a/b/c/relative");
         visitor.visitFile(child, null);
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DurationTest.java
index 456f95b..c156ded 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DurationTest.java
@@ -17,34 +17,33 @@
 
 package org.apache.logging.log4j.core.appender.rolling.action;
 
-import org.apache.logging.log4j.core.appender.rolling.action.Duration;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the Duration class.
  */
 public class DurationTest {
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testParseFailsIfNullText() {
-        Duration.parse(null);
+        assertThrows(NullPointerException.class, () -> Duration.parse(null));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testParseFailsIfInvalidPattern() {
-        Duration.parse("abc");
+        assertThrows(IllegalArgumentException.class, () -> Duration.parse("abc"));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testParseFailsIfSectionsOutOfOrder() {
-        Duration.parse("P4DT2M1S3H");
+        assertThrows(IllegalArgumentException.class, () -> Duration.parse("P4DT2M1S3H"));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testParseFailsIfTButMissingTime() {
-        Duration.parse("P1dT");
+        assertThrows(IllegalArgumentException.class, () -> Duration.parse("P1dT"));
     }
 
     @Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameActionTest.java
index 8a4fc8e..3ab9ff8 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameActionTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameActionTest.java
@@ -16,67 +16,48 @@
  */
 package org.apache.logging.log4j.core.appender.rolling.action;
 
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
 import java.io.File;
 import java.io.PrintStream;
 
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
-/**
- *
- */
 public class FileRenameActionTest {
 
-    private static final String DIR = "target/fileRename";
-
-    @BeforeClass
-    public static void beforeClass() throws Exception {
-        final File file = new File(DIR);
-        file.mkdirs();
-    }
-
-    @AfterClass
-    public static void afterClass() {
-        deleteDir();
-    }
-
-    @After
-    public void after() {
-        deleteFiles();
-    }
+    @TempDir
+    File tempDir;
 
     @Test
     public void testRename1() throws Exception {
-        final File file = new File("target/fileRename/fileRename.log");
+        final File file = new File(tempDir, "fileRename.log");
         try (final PrintStream pos = new PrintStream(file)) {
             for (int i = 0; i < 100; ++i) {
                 pos.println("This is line " + i);
             }
         }
 
-        final File dest = new File("target/fileRename/newFile.log");
+        final File dest = new File(tempDir, "newFile.log");
         final FileRenameAction action = new FileRenameAction(file, dest, false);
         action.execute();
-        assertTrue("Renamed file does not exist", dest.exists());
-        assertTrue("Old file exists", !file.exists());
+        assertTrue(dest.exists(), "Renamed file does not exist");
+        assertFalse(file.exists(), "Old file exists");
     }
 
     @Test
     public void testEmpty() throws Exception {
-        final File file = new File("target/fileRename/fileRename.log");
+        final File file = new File(tempDir, "fileRename.log");
         try (final PrintStream pos = new PrintStream(file)) {
             // do nothing
         }
 
-        final File dest = new File("target/fileRename/newFile.log");
+        final File dest = new File(tempDir, "newFile.log");
         final FileRenameAction action = new FileRenameAction(file, dest, false);
         action.execute();
-        assertTrue("Renamed file does not exist", !dest.exists());
-        assertTrue("Old file does not exist", !file.exists());
+        assertFalse(dest.exists(), "Renamed file does not exist");
+        assertFalse(file.exists(), "Old file does not exist");
     }
 
 
@@ -90,40 +71,10 @@ public class FileRenameActionTest {
         }
 
         final File dest = new File("newFile.log");
-        try {
-            final FileRenameAction action = new FileRenameAction(file, dest, false);
-            action.execute();
-            assertTrue("Renamed file does not exist", dest.exists());
-            assertTrue("Old file exists", !file.exists());
-        } finally {
-            try {
-                dest.delete();
-                file.delete();
-            } catch (final Exception ex) {
-                System.out.println("Unable to cleanup files written to main directory");
-            }
-        }
-    }
-
-
-    private static void deleteDir() {
-        final File dir = new File(DIR);
-        if (dir.exists()) {
-            final File[] files = dir.listFiles();
-            for (final File file : files) {
-                file.delete();
-            }
-            dir.delete();
-        }
+        final FileRenameAction action = new FileRenameAction(file, dest, false);
+        action.execute();
+        assertTrue(dest.exists(), "Renamed file does not exist");
+        assertFalse(file.exists(), "Old file exists");
     }
 
-    private static void deleteFiles() {
-        final File dir = new File(DIR);
-        if (dir.exists()) {
-            final File[] files = dir.listFiles();
-            for (final File file : files) {
-                file.delete();
-            }
-        }
-    }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileSizeTest.java
index dfa7cec..5e3d402 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileSizeTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileSizeTest.java
@@ -17,29 +17,28 @@
 package org.apache.logging.log4j.core.appender.rolling.action;
 
 import org.apache.logging.log4j.core.appender.rolling.FileSize;
-import org.junit.Test;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
 
-import java.text.NumberFormat;
 import java.util.Locale;
 
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class FileSizeTest {
 
     @Test
     public void testParse() {
-        assertThat(FileSize.parse("5k", 0), is(5L * 1024));
+        assertEquals(5 * 1024, FileSize.parse("5k", 0));
     }
 
     @Test
+    @Tag("locale")
     public void testParseInEurope() {
         // Caveat: Breaks the ability for this test to run in parallel with other tests :(
         Locale previousDefault = Locale.getDefault();
         try {
             Locale.setDefault(new Locale("de", "DE"));
-            assertThat(FileSize.parse("1,000", 0), is(1000L));
+            assertEquals(1000, FileSize.parse("1,000", 0));
         } finally {
             Locale.setDefault(previousDefault);
         }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCountTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCountTest.java
index 0022b40..af5ab26 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCountTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCountTest.java
@@ -17,9 +17,9 @@
 
 package org.apache.logging.log4j.core.appender.rolling.action;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the IfAccumulatedFileCount class.
@@ -54,7 +54,7 @@ public class IfAccumulatedFileCountTest {
 
         for (int i = 1; i < 10; i++) {
             if (i <= 3) {
-                assertFalse("i=" + i, condition.accept(null, null, null));
+                assertFalse(condition.accept(null, null, null), "i=" + i);
                 assertEquals(0, counter.getAcceptCount());
             } else {
                 assertTrue(condition.accept(null, null, null));
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileSizeTest.java
index 740c998..76bb0fc 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileSizeTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileSizeTest.java
@@ -17,9 +17,9 @@
 
 package org.apache.logging.log4j.core.appender.rolling.action;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the IfAccumulatedFileSize class.
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAllTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAllTest.java
index aa4884a..5e85d1c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAllTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAllTest.java
@@ -17,11 +17,9 @@
 
 package org.apache.logging.log4j.core.appender.rolling.action;
 
-import org.apache.logging.log4j.core.appender.rolling.action.IfAll;
-import org.apache.logging.log4j.core.appender.rolling.action.PathCondition;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the And composite condition.
@@ -37,12 +35,12 @@ public class IfAllTest {
         assertFalse(IfAll.createAndCondition(TRUE, FALSE).accept(null, null, null));
         assertFalse(IfAll.createAndCondition(FALSE, FALSE).accept(null, null, null));
     }
-
+    
     @Test
     public void testEmptyIsFalse() {
         assertFalse(IfAll.createAndCondition().accept(null, null, null));
     }
-
+    
     @Test
     public void testBeforeTreeWalk() {
         final CountingCondition counter = new CountingCondition(true);
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAnyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAnyTest.java
index ba63a27..2a2c7db 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAnyTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAnyTest.java
@@ -17,9 +17,9 @@
 
 package org.apache.logging.log4j.core.appender.rolling.action;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the Or composite condition.
@@ -35,12 +35,12 @@ public class IfAnyTest {
         assertTrue(IfAny.createOrCondition(TRUE, FALSE).accept(null, null, null));
         assertFalse(IfAny.createOrCondition(FALSE, FALSE).accept(null, null, null));
     }
-
+    
     @Test
     public void testEmptyIsFalse() {
         assertFalse(IfAny.createOrCondition().accept(null, null, null));
     }
-
+    
     @Test
     public void testBeforeTreeWalk() {
         final CountingCondition counter = new CountingCondition(true);
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfFileNameTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfFileNameTest.java
index 978031e..9b0b0db 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfFileNameTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfFileNameTest.java
@@ -20,18 +20,18 @@ package org.apache.logging.log4j.core.appender.rolling.action;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 public class IfFileNameTest {
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testCreateNameConditionFailsIfBothRegexAndPathAreNull() {
-        IfFileName.createNameCondition(null, null);
+        assertThrows(IllegalArgumentException.class, () -> IfFileName.createNameCondition(null, null));
     }
 
-    @Test()
+    @Test
     public void testCreateNameConditionAcceptsIfEitherRegexOrPathOrBothAreNonNull() {
         IfFileName.createNameCondition("bar", null);
         IfFileName.createNameCondition(null, "foo");
@@ -51,7 +51,7 @@ public class IfFileNameTest {
         final IfFileName filter = IfFileName.createNameCondition("path", "regex");
         final Path relativePath = Paths.get("path");
         assertTrue(filter.accept(null, relativePath, null));
-
+        
         final Path pathMatchingRegex = Paths.get("regex");
         assertFalse(filter.accept(null, pathMatchingRegex, null));
     }
@@ -61,7 +61,7 @@ public class IfFileNameTest {
         final IfFileName regexFilter = IfFileName.createNameCondition(null, "regex");
         final Path pathMatchingRegex = Paths.get("regex");
         assertTrue(regexFilter.accept(null, pathMatchingRegex, null));
-
+        
         final Path noMatch = Paths.get("nomatch");
         assertFalse(regexFilter.accept(null, noMatch, null));
     }
@@ -71,7 +71,7 @@ public class IfFileNameTest {
         final IfFileName pathFilter = IfFileName.createNameCondition("path", null);
         final Path relativePath = Paths.get("path");
         assertTrue(pathFilter.accept(null, relativePath, null));
-
+        
         final IfFileName regexFilter = IfFileName.createNameCondition(null, "regex");
         final Path pathMatchingRegex = Paths.get("regex");
         assertTrue(regexFilter.accept(null, pathMatchingRegex, null));
@@ -82,14 +82,14 @@ public class IfFileNameTest {
         final CountingCondition counter = new CountingCondition(true);
         final IfFileName regexFilter = IfFileName.createNameCondition(null, "regex", counter);
         final Path pathMatchingRegex = Paths.get("regex");
-
+        
         assertTrue(regexFilter.accept(null, pathMatchingRegex, null));
         assertEquals(1, counter.getAcceptCount());
         assertTrue(regexFilter.accept(null, pathMatchingRegex, null));
         assertEquals(2, counter.getAcceptCount());
         assertTrue(regexFilter.accept(null, pathMatchingRegex, null));
         assertEquals(3, counter.getAcceptCount());
-
+        
         final Path noMatch = Paths.get("nomatch");
         assertFalse(regexFilter.accept(null, noMatch, null));
         assertEquals(3, counter.getAcceptCount()); // no increase
@@ -104,7 +104,7 @@ public class IfFileNameTest {
         final CountingCondition counter = new CountingCondition(true);
         final IfFileName globFilter = IfFileName.createNameCondition("glob", null, counter);
         final Path pathMatchingGlob = Paths.get("glob");
-
+        
         assertTrue(globFilter.accept(null, pathMatchingGlob, null));
         assertEquals(1, counter.getAcceptCount());
         assertTrue(globFilter.accept(null, pathMatchingGlob, null));
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java
index 520e68d..b6f177c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java
@@ -19,9 +19,9 @@ package org.apache.logging.log4j.core.appender.rolling.action;
 
 import java.nio.file.attribute.FileTime;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the FileAgeFilter class.
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfNotTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfNotTest.java
index c5abfb9..3563bb1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfNotTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfNotTest.java
@@ -17,10 +17,9 @@
 
 package org.apache.logging.log4j.core.appender.rolling.action;
 
-import org.apache.logging.log4j.core.appender.rolling.action.IfNot;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the Not composite condition.
@@ -36,9 +35,10 @@ public class IfNotTest {
         assertTrue(IfNot.createNotCondition(new FixedCondition(false)).accept(null, null, null));
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testEmptyIsFalse() {
-        assertFalse(IfNot.createNotCondition(null).accept(null, null, null));
+        assertThrows(NullPointerException.class,
+                () -> IfNot.createNotCondition(null).accept(null, null, null));
     }
 
     @Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTimeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTimeTest.java
index 15b2eae..60c43a3 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTimeTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTimeTest.java
@@ -21,9 +21,9 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.attribute.FileTime;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the {@code PathSortByModificationTime} class.
@@ -49,18 +49,18 @@ public class PathSortByModificationTimeTest {
         final DummyFileAttributes a2 = new DummyFileAttributes();
         a1.lastModified = FileTime.fromMillis(100);
         a2.lastModified = FileTime.fromMillis(222);
-
-        assertEquals("same path, 2nd more recent", 1, sorter.compare(path(p1, a1), path(p1, a2)));
-        assertEquals("path ignored, 2nd more recent", 1, sorter.compare(path(p1, a1), path(p2, a2)));
-        assertEquals("path ignored, 2nd more recent", 1, sorter.compare(path(p2, a1), path(p1, a2)));
-
-        assertEquals("same path, 1st more recent", -1, sorter.compare(path(p1, a2), path(p1, a1)));
-        assertEquals("path ignored, 1st more recent", -1, sorter.compare(path(p1, a2), path(p2, a1)));
-        assertEquals("path ignored, 1st more recent", -1, sorter.compare(path(p2, a2), path(p1, a1)));
-
-        assertEquals("same path, same time", 0, sorter.compare(path(p1, a1), path(p1, a1)));
-        assertEquals("p2 < p1, same time", 1, sorter.compare(path(p1, a1), path(p2, a1)));
-        assertEquals("p2 < p1, same time", -1, sorter.compare(path(p2, a1), path(p1, a1)));
+        
+        assertEquals(1, sorter.compare(path(p1, a1), path(p1, a2)), "same path, 2nd more recent");
+        assertEquals(1, sorter.compare(path(p1, a1), path(p2, a2)), "path ignored, 2nd more recent");
+        assertEquals(1, sorter.compare(path(p2, a1), path(p1, a2)), "path ignored, 2nd more recent");
+        
+        assertEquals(-1, sorter.compare(path(p1, a2), path(p1, a1)), "same path, 1st more recent");
+        assertEquals(-1, sorter.compare(path(p1, a2), path(p2, a1)), "path ignored, 1st more recent");
+        assertEquals(-1, sorter.compare(path(p2, a2), path(p1, a1)), "path ignored, 1st more recent");
+        
+        assertEquals(0, sorter.compare(path(p1, a1), path(p1, a1)), "same path, same time");
+        assertEquals(1, sorter.compare(path(p1, a1), path(p2, a1)), "p2 < p1, same time");
+        assertEquals(-1, sorter.compare(path(p2, a1), path(p1, a1)), "p2 < p1, same time");
     }
 
     @Test
@@ -72,18 +72,18 @@ public class PathSortByModificationTimeTest {
         final DummyFileAttributes a2 = new DummyFileAttributes();
         a1.lastModified = FileTime.fromMillis(100);
         a2.lastModified = FileTime.fromMillis(222);
-
-        assertEquals("same path, 2nd more recent", -1, sorter.compare(path(p1, a1), path(p1, a2)));
-        assertEquals("path ignored, 2nd more recent", -1, sorter.compare(path(p1, a1), path(p2, a2)));
-        assertEquals("path ignored, 2nd more recent", -1, sorter.compare(path(p2, a1), path(p1, a2)));
-
-        assertEquals("same path, 1st more recent", 1, sorter.compare(path(p1, a2), path(p1, a1)));
-        assertEquals("path ignored, 1st more recent", 1, sorter.compare(path(p1, a2), path(p2, a1)));
-        assertEquals("path ignored, 1st more recent", 1, sorter.compare(path(p2, a2), path(p1, a1)));
-
-        assertEquals("same path, same time", 0, sorter.compare(path(p1, a1), path(p1, a1)));
-        assertEquals("p1 < p2, same time", -1, sorter.compare(path(p1, a1), path(p2, a1)));
-        assertEquals("p1 < p2, same time", 1, sorter.compare(path(p2, a1), path(p1, a1)));
+        
+        assertEquals(-1, sorter.compare(path(p1, a1), path(p1, a2)), "same path, 2nd more recent");
+        assertEquals(-1, sorter.compare(path(p1, a1), path(p2, a2)), "path ignored, 2nd more recent");
+        assertEquals(-1, sorter.compare(path(p2, a1), path(p1, a2)), "path ignored, 2nd more recent");
+        
+        assertEquals(1, sorter.compare(path(p1, a2), path(p1, a1)), "same path, 1st more recent");
+        assertEquals(1, sorter.compare(path(p1, a2), path(p2, a1)), "path ignored, 1st more recent");
+        assertEquals(1, sorter.compare(path(p2, a2), path(p1, a1)), "path ignored, 1st more recent");
+        
+        assertEquals(0, sorter.compare(path(p1, a1), path(p1, a1)), "same path, same time");
+        assertEquals(-1, sorter.compare(path(p1, a1), path(p2, a1)), "p1 < p2, same time");
+        assertEquals(1, sorter.compare(path(p2, a1), path(p1, a1)), "p1 < p2, same time");
     }
 
     private PathWithAttributes path(final Path path, final DummyFileAttributes attributes) {
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptConditionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptConditionTest.java
index 0379767..346e898 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptConditionTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptConditionTest.java
@@ -17,33 +17,33 @@
 
 package org.apache.logging.log4j.core.appender.rolling.action;
 
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.script.Script;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.logging.log4j.categories.Scripts;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.DefaultConfiguration;
-import org.apache.logging.log4j.core.script.Script;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the ScriptCondition class.
  */
 public class ScriptConditionTest {
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testConstructorDisallowsNullScript() {
-        new ScriptCondition(null, new DefaultConfiguration());
+        assertThrows(NullPointerException.class, () -> new ScriptCondition(null, new DefaultConfiguration()));
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testConstructorDisallowsNullConfig() {
-        new ScriptCondition(new Script("test", "js", "print('hi')"), null);
+        assertThrows(NullPointerException.class,
+                () -> new ScriptCondition(new Script("test", "js", "print('hi')"), null));
     }
 
     @Test
@@ -51,9 +51,10 @@ public class ScriptConditionTest {
         assertNull(ScriptCondition.createCondition(null, new DefaultConfiguration()));
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testCreateConditionDisallowsNullConfig() {
-        ScriptCondition.createCondition(new Script("test", "js", "print('hi')"), null);
+        assertThrows(NullPointerException.class, () -> ScriptCondition.createCondition(
+                new Script("test", "js", "print('hi')"), null));
     }
 
     @Test
@@ -92,7 +93,7 @@ public class ScriptConditionTest {
     }
 
     @Test
-    @Category(Scripts.Groovy.class)
+    @Tag("groovy")
     public void testSelectFilesToDelete3() {
         final Configuration config = new DefaultConfiguration();
         config.initialize(); // creates the ScriptManager
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java
index a292851..9df7ab8 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java
@@ -17,6 +17,10 @@
 
 package org.apache.logging.log4j.core.appender.rolling.action;
 
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
 import java.io.IOException;
 import java.nio.file.FileVisitOption;
 import java.nio.file.FileVisitResult;
@@ -24,34 +28,29 @@ import java.nio.file.Files;
 import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.nio.file.attribute.FileAttribute;
 import java.nio.file.attribute.FileTime;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests the SortingVisitor class.
  */
 public class SortingVisitorTest {
 
-    private Path base;
+    @TempDir
+    Path base;
     private Path aaa;
     private Path bbb;
     private Path ccc;
 
-    @Before
+    @BeforeEach
     public void setUp() throws Exception {
-        base = Files.createTempDirectory("tempDir", new FileAttribute<?>[0]);
-        aaa = Files.createTempFile(base, "aaa", null, new FileAttribute<?>[0]);
-        bbb = Files.createTempFile(base, "bbb", null, new FileAttribute<?>[0]);
-        ccc = Files.createTempFile(base, "ccc", null, new FileAttribute<?>[0]);
+        aaa = Files.createFile(base.resolve("aaa"));
+        bbb = Files.createFile(base.resolve("bbb"));
+        ccc = Files.createFile(base.resolve("ccc"));
 
         // lastModified granularity is 1 sec(!) on some file systems...
         final long now = System.currentTimeMillis();
@@ -60,14 +59,6 @@ public class SortingVisitorTest {
         Files.setLastModifiedTime(ccc, FileTime.fromMillis(now + 2000));
     }
 
-    @After
-    public void tearDown() throws Exception {
-        Files.deleteIfExists(ccc);
-        Files.deleteIfExists(bbb);
-        Files.deleteIfExists(aaa);
-        Files.deleteIfExists(base);
-    }
-
     @Test
     public void testRecentFirst() throws Exception {
         final SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(true));
@@ -76,10 +67,10 @@ public class SortingVisitorTest {
 
         final List<PathWithAttributes> found = visitor.getSortedPaths();
         assertNotNull(found);
-        assertEquals("file count", 3, found.size());
-        assertEquals("1st: most recent; sorted=" + found, ccc, found.get(0).getPath());
-        assertEquals("2nd; sorted=" + found, bbb, found.get(1).getPath());
-        assertEquals("3rd: oldest; sorted=" + found, aaa, found.get(2).getPath());
+        assertEquals(3, found.size(), "file count");
+        assertEquals(ccc, found.get(0).getPath(), "1st: most recent; sorted=" + found);
+        assertEquals(bbb, found.get(1).getPath(), "2nd; sorted=" + found);
+        assertEquals(aaa, found.get(2).getPath(), "3rd: oldest; sorted=" + found);
     }
 
     @Test
@@ -90,16 +81,16 @@ public class SortingVisitorTest {
 
         final List<PathWithAttributes> found = visitor.getSortedPaths();
         assertNotNull(found);
-        assertEquals("file count", 3, found.size());
-        assertEquals("1st: oldest first; sorted=" + found, aaa, found.get(0).getPath());
-        assertEquals("2nd; sorted=" + found, bbb, found.get(1).getPath());
-        assertEquals("3rd: most recent sorted; list=" + found, ccc, found.get(2).getPath());
+        assertEquals(3, found.size(), "file count");
+        assertEquals(aaa, found.get(0).getPath(), "1st: oldest first; sorted=" + found);
+        assertEquals(bbb, found.get(1).getPath(), "2nd; sorted=" + found);
+        assertEquals(ccc, found.get(2).getPath(), "3rd: most recent sorted; list=" + found);
     }
 
     @Test
     public void testNoSuchFileFailure() throws IOException {
         SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(false));
-        assertEquals(
+        assertSame(
                 FileVisitResult.CONTINUE,
                 visitor.visitFileFailed(Paths.get("doesNotExist"), new NoSuchFileException("doesNotExist")));
     }
@@ -108,11 +99,7 @@ public class SortingVisitorTest {
     public void testIOException() {
         SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(false));
         IOException exception = new IOException();
-        try {
-            visitor.visitFileFailed(Paths.get("doesNotExist"), exception);
-            fail();
-        } catch (IOException e) {
-            assertSame(exception, e);
-        }
+        assertSame(exception,
+                assertThrows(IOException.class, () -> visitor.visitFileFailed(Paths.get("doesNotExist"), exception)));
     }
 }