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/08/29 19:43:47 UTC

[logging-log4j2] branch release-2.x updated (f2c311e -> 103f126)

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

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


    from f2c311e  Upload test reports in GitHub Actions.
     new f8c68d1  [LOG4J2-2653] Migrate lookup and net tests to JUnit 5
     new 103f126  [LOG4J2-2653] Migrate layout tests to JUnit 5

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/logging/log4j/LogManager.java  |   9 +-
 .../apache/logging/log4j/spi/LoggerContext.java    |  24 +++++
 .../logging/log4j/CloseableThreadContextTest.java  |  17 +--
 .../log4j/ThreadContextInheritanceTest.java        |  17 +--
 .../apache/logging/log4j/ThreadContextTest.java    |  17 +--
 .../junit/LogManagerLoggerContextFactoryRule.java  |   2 +-
 .../log4j/junit/LoggerContextFactoryExtension.java |   2 +-
 .../log4j/junit/StatusLoggerLevelExtension.java    |   2 +-
 .../logging/log4j/junit/StatusLoggerRule.java      |   2 +-
 ...lExtension.java => ThreadContextExtension.java} |  45 ++++----
 .../logging/log4j/junit/ThreadContextMapRule.java  |   3 +
 .../logging/log4j/junit/ThreadContextRule.java     |   3 +
 .../log4j/junit/ThreadContextStackRule.java        |   2 +
 .../logging/log4j/junit/UsingAnyThreadContext.java |  19 ++--
 .../logging/log4j/junit/UsingThreadContextMap.java |  19 ++--
 .../log4j/junit/UsingThreadContextStack.java       |  19 ++--
 log4j-core/pom.xml                                 |   5 +-
 .../org/apache/logging/log4j/core/LoggerTest.java  |   5 +-
 .../apache/logging/log4j/core/jmx/ServerTest.java  |   4 +-
 .../core/layout/AbstractStringLayoutTest.java      |  30 +++---
 .../ConcurrentLoggingWithGelfLayoutTest.java       |  48 ++++-----
 .../logging/log4j/core/layout/GelfLayoutTest.java  |  19 ++--
 .../logging/log4j/core/layout/GelfLayoutTest2.java |  21 ++--
 .../logging/log4j/core/layout/GelfLayoutTest3.java |  35 +++---
 .../logging/log4j/core/layout/HtmlLayoutTest.java  |  42 ++++----
 .../log4j/core/layout/Log4j2_2195_Test.java        |  53 +++++----
 .../core/layout/PatternLayoutLookupDateTest.java   |  20 ++--
 .../layout/PatternLayoutMainMapLookupTest.java     |  40 +++----
 .../core/layout/PatternLayoutNoLookupDateTest.java |  21 ++--
 .../log4j/core/layout/PatternLayoutTest.java       |  71 ++++++-------
 .../log4j/core/layout/PatternSelectorTest.java     |  16 +--
 .../log4j/core/layout/Rfc5424LayoutTest.java       | 100 +++++++++--------
 .../core/layout/StringBuilderEncoderTest.java      | 118 ++++++++++-----------
 .../log4j/core/layout/SyslogLayoutTest.java        |  30 +++---
 .../logging/log4j/core/lookup/CaseLookupTest.java  |  12 +--
 .../log4j/core/lookup/ContextMapLookupTest.java    |  36 +++----
 .../logging/log4j/core/lookup/DateLookupTest.java  |  11 +-
 .../log4j/core/lookup/EnvironmentLookupTest.java   |   8 +-
 .../logging/log4j/core/lookup/EventLookupTest.java |   7 +-
 .../logging/log4j/core/lookup/Log4jLookupTest.java |  28 +++--
 .../core/lookup/Log4jLookupWithSpacesTest.java     |  29 +++--
 .../lookup/MainInputArgumentsJmxLookupTest.java    |  14 +--
 .../logging/log4j/core/lookup/MainLookupTest.java  |  30 +++---
 .../logging/log4j/core/lookup/MapLookupTest.java   |  26 +++--
 .../log4j/core/lookup/MarkerLookupConfigTest.java  |  45 ++++----
 .../log4j/core/lookup/MarkerLookupTest.java        |   7 +-
 .../core/lookup/ResourceBundleLookupTest.java      |  17 ++-
 .../log4j/core/lookup/StrSubstitutorTest.java      |  15 ++-
 .../core/lookup/StructuredDataLookupTest.java      |   7 +-
 .../core/lookup/SystemPropertiesLookupTest.java    |  15 ++-
 .../message/ExtendedThreadInformationTest.java     |   6 +-
 .../logging/log4j/core/net/PriorityTest.java       |   9 +-
 .../log4j/core/net/SocketMessageLossTest.java      |  24 ++---
 .../log4j/core/net/SocketReconnectTest.java        |  28 ++---
 .../apache/logging/log4j/core/net/SocketTest.java  |  37 ++-----
 .../net/ssl/EnvironmentPasswordProviderTest.java   |   8 +-
 .../core/net/ssl/FilePasswordProviderTest.java     |  13 +--
 .../core/net/ssl/KeyStoreConfigurationTest.java    |  60 ++++++-----
 .../core/net/ssl/MemoryPasswordProviderTest.java   |   6 +-
 .../log4j/core/net/ssl/SslConfigurationTest.java   |  41 ++++---
 .../log4j/core/net/ssl/StoreConfigurationTest.java |  16 +--
 .../core/net/ssl/TrustStoreConfigurationTest.java  |  54 +++++-----
 .../core/pattern/MdcPatternConverterTest.java      |  12 +--
 .../core/pattern/NdcPatternConverterTest.java      |  17 +--
 .../log4j/core/pattern/RegexReplacementTest.java   |  11 +-
 .../logging/log4j/junit/LoggerContextResolver.java |  28 +++--
 .../logging/log4j/junit/LoggerContextSource.java   |  22 +++-
 .../java/org/apache/logging/log4j/junit/Named.java |   7 ++
 .../log4j/junit/ReconfigurationPolicy.java}        |  24 +++--
 pom.xml                                            |   6 ++
 70 files changed, 772 insertions(+), 844 deletions(-)
 copy log4j-api/src/test/java/org/apache/logging/log4j/junit/{StatusLoggerLevelExtension.java => ThreadContextExtension.java} (50%)
 copy log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java => log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingAnyThreadContext.java (71%)
 copy log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java => log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingThreadContextMap.java (71%)
 copy log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java => log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingThreadContextStack.java (71%)
 copy log4j-core/src/{main/java/org/apache/logging/log4j/core/impl/ContextAnchor.java => test/java/org/apache/logging/log4j/junit/ReconfigurationPolicy.java} (61%)


[logging-log4j2] 02/02: [LOG4J2-2653] Migrate layout tests to JUnit 5

Posted by ma...@apache.org.
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 103f126dfd6ff36d278d4537bc96ad4377b298f8
Author: Matt Sicker <bo...@gmail.com>
AuthorDate: Sat Aug 29 14:16:56 2020 -0500

    [LOG4J2-2653] Migrate layout tests to JUnit 5
    
    Backported from 3.x.
    
    Signed-off-by: Matt Sicker <bo...@gmail.com>
---
 .../java/org/apache/logging/log4j/LogManager.java  |   9 +-
 .../apache/logging/log4j/spi/LoggerContext.java    |  24 +++++
 .../logging/log4j/CloseableThreadContextTest.java  |  17 +--
 .../log4j/ThreadContextInheritanceTest.java        |  17 +--
 .../apache/logging/log4j/ThreadContextTest.java    |  17 +--
 .../junit/LogManagerLoggerContextFactoryRule.java  |   2 +-
 .../log4j/junit/LoggerContextFactoryExtension.java |   2 +-
 .../log4j/junit/StatusLoggerLevelExtension.java    |   2 +-
 .../logging/log4j/junit/StatusLoggerRule.java      |   2 +-
 ...lExtension.java => ThreadContextExtension.java} |  45 ++++----
 .../logging/log4j/junit/ThreadContextMapRule.java  |   3 +
 .../logging/log4j/junit/ThreadContextRule.java     |   3 +
 .../log4j/junit/ThreadContextStackRule.java        |   2 +
 .../logging/log4j/junit/UsingAnyThreadContext.java |  19 ++--
 .../logging/log4j/junit/UsingThreadContextMap.java |  19 ++--
 .../log4j/junit/UsingThreadContextStack.java       |  19 ++--
 .../org/apache/logging/log4j/core/LoggerTest.java  |   5 +-
 .../apache/logging/log4j/core/jmx/ServerTest.java  |   4 +-
 .../core/layout/AbstractStringLayoutTest.java      |  30 +++---
 .../ConcurrentLoggingWithGelfLayoutTest.java       |  48 ++++-----
 .../logging/log4j/core/layout/GelfLayoutTest.java  |  19 ++--
 .../logging/log4j/core/layout/GelfLayoutTest2.java |  21 ++--
 .../logging/log4j/core/layout/GelfLayoutTest3.java |  35 +++---
 .../logging/log4j/core/layout/HtmlLayoutTest.java  |  42 ++++----
 .../log4j/core/layout/Log4j2_2195_Test.java        |  53 +++++----
 .../core/layout/PatternLayoutLookupDateTest.java   |  20 ++--
 .../layout/PatternLayoutMainMapLookupTest.java     |  40 +++----
 .../core/layout/PatternLayoutNoLookupDateTest.java |  21 ++--
 .../log4j/core/layout/PatternLayoutTest.java       |  71 ++++++-------
 .../log4j/core/layout/PatternSelectorTest.java     |  16 +--
 .../log4j/core/layout/Rfc5424LayoutTest.java       | 100 +++++++++--------
 .../core/layout/StringBuilderEncoderTest.java      | 118 ++++++++++-----------
 .../log4j/core/layout/SyslogLayoutTest.java        |  30 +++---
 .../core/pattern/MdcPatternConverterTest.java      |  12 +--
 .../core/pattern/NdcPatternConverterTest.java      |  17 +--
 .../log4j/core/pattern/RegexReplacementTest.java   |  11 +-
 .../logging/log4j/junit/LoggerContextResolver.java |  28 +++--
 .../logging/log4j/junit/LoggerContextSource.java   |  22 +++-
 .../java/org/apache/logging/log4j/junit/Named.java |   7 ++
 .../logging/log4j/junit/ReconfigurationPolicy.java |  30 +++---
 40 files changed, 491 insertions(+), 511 deletions(-)

diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java b/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java
index 51d783b..7716c74 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java
@@ -426,11 +426,6 @@ public class LogManager {
         }
     }
 
-    private static String toLoggerName(final Class<?> cls) {
-        final String canonicalName = cls.getCanonicalName();
-        return canonicalName != null ? canonicalName : cls.getName();
-    }
-
     /**
      * Returns the current LoggerContextFactory.
      *
@@ -599,7 +594,7 @@ public class LogManager {
      */
     public static Logger getLogger(final Class<?> clazz) {
         final Class<?> cls = callerClass(clazz);
-        return getContext(cls.getClassLoader(), false).getLogger(toLoggerName(cls));
+        return getContext(cls.getClassLoader(), false).getLogger(cls);
     }
 
     /**
@@ -615,7 +610,7 @@ public class LogManager {
      */
     public static Logger getLogger(final Class<?> clazz, final MessageFactory messageFactory) {
         final Class<?> cls = callerClass(clazz);
-        return getContext(cls.getClassLoader(), false).getLogger(toLoggerName(cls), messageFactory);
+        return getContext(cls.getClassLoader(), false).getLogger(cls, messageFactory);
     }
 
     /**
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java
index 25b0071..eab7b51 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java
@@ -89,6 +89,17 @@ public interface LoggerContext {
     ExtendedLogger getLogger(String name);
 
     /**
+     * Returns an ExtendedLogger using the fully qualified name of the Class as the Logger name.
+     * @param cls The Class whose name should be used as the Logger name.
+     * @return The logger.
+     * @since 2.14.0
+     */
+    default ExtendedLogger getLogger(Class<?> cls) {
+        final String canonicalName = cls.getCanonicalName();
+        return getLogger(canonicalName != null ? canonicalName : cls.getName());
+    }
+
+    /**
      * Returns an ExtendedLogger.
      * @param name The name of the Logger to return.
      * @param messageFactory The message factory is used only when creating a logger, subsequent use does not change
@@ -98,6 +109,19 @@ public interface LoggerContext {
     ExtendedLogger getLogger(String name, MessageFactory messageFactory);
 
     /**
+     * Returns an ExtendedLogger using the fully qualified name of the Class as the Logger name.
+     * @param cls The Class whose name should be used as the Logger name.
+     * @param messageFactory The message factory is used only when creating a logger, subsequent use does not change the
+     *                       logger but will log a warning if mismatched.
+     * @return The logger.
+     * @since 2.14.0
+     */
+    default ExtendedLogger getLogger(Class<?> cls, MessageFactory messageFactory) {
+        final String canonicalName = cls.getCanonicalName();
+        return getLogger(canonicalName != null ? canonicalName : cls.getName(), messageFactory);
+    }
+
+    /**
      * Detects if a Logger with the specified name exists.
      * @param name The Logger name to search for.
      * @return true if the Logger exists, false otherwise.
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/CloseableThreadContextTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/CloseableThreadContextTest.java
index ce06907..54ea122 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/CloseableThreadContextTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/CloseableThreadContextTest.java
@@ -16,8 +16,7 @@
  */
 package org.apache.logging.log4j;
 
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
+import org.apache.logging.log4j.junit.UsingAnyThreadContext;
 import org.junit.jupiter.api.Test;
 
 import java.util.HashMap;
@@ -31,24 +30,12 @@ import static org.junit.jupiter.api.Assertions.*;
  *
  * @since 2.6
  */
+@UsingAnyThreadContext
 public class CloseableThreadContextTest {
 
     private final String key = "key";
     private final String value = "value";
 
-    private ThreadContextHolder threadContextHolder;
-
-    @BeforeEach
-    void clearThreadContext() {
-        threadContextHolder = new ThreadContextHolder(true, true);
-        ThreadContext.clearAll();
-    }
-
-    @AfterEach
-    void restoreThreadContext() {
-        threadContextHolder.restore();
-    }
-
     @Test
     public void shouldAddAnEntryToTheMap() {
         try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.put(key, value)) {
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
index 5bcc1eb..f1cc91e 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
@@ -16,11 +16,10 @@
  */
 package org.apache.logging.log4j;
 
+import org.apache.logging.log4j.junit.UsingAnyThreadContext;
 import org.apache.logging.log4j.spi.DefaultThreadContextMap;
 import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 
@@ -29,21 +28,9 @@ import static org.junit.jupiter.api.Assertions.*;
 /**
  * Tests {@link ThreadContext}.
  */
+@UsingAnyThreadContext
 public class ThreadContextInheritanceTest {
 
-    private ThreadContextHolder threadContextHolder;
-
-    @BeforeEach
-    void clearThreadContext() {
-        threadContextHolder = new ThreadContextHolder(true, true);
-        ThreadContext.clearAll();
-    }
-
-    @AfterEach
-    void restoreThreadContext() {
-        threadContextHolder.restore();
-    }
-
     @BeforeAll
     public static void setupClass() {
         System.setProperty(DefaultThreadContextMap.INHERITABLE_MAP, "true");
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java
index 636b53d..3b6fb3a 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java
@@ -20,31 +20,18 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
+import org.apache.logging.log4j.junit.UsingAnyThreadContext;
 import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.*;
 
+@UsingAnyThreadContext
 public class ThreadContextTest {
     public static void reinitThreadContext() {
         ThreadContext.init();
     }
 
-    private ThreadContextHolder threadContextHolder;
-
-    @BeforeEach
-    void clearThreadContext() {
-        threadContextHolder = new ThreadContextHolder(true, true);
-        ThreadContext.clearAll();
-    }
-
-    @AfterEach
-    void restoreThreadContext() {
-        threadContextHolder.restore();
-    }
-
     @Test
     public void testPush() {
         ThreadContext.push("Hello");
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/LogManagerLoggerContextFactoryRule.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/LogManagerLoggerContextFactoryRule.java
index c7c157f..060e553 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/LogManagerLoggerContextFactoryRule.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/LogManagerLoggerContextFactoryRule.java
@@ -24,7 +24,7 @@ import org.junit.rules.ExternalResource;
  * Sets the {@link LogManager}'s {@link LoggerContextFactory} to the given instance before the test and restores it to
  * the original value after the test.
  *
- * @deprecated Use {@link LoggerContextFactoryExtension}
+ * @deprecated Use {@link LoggerContextFactoryExtension} with JUnit 5
  */
 public class LogManagerLoggerContextFactoryRule extends ExternalResource {
 
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/LoggerContextFactoryExtension.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/LoggerContextFactoryExtension.java
index 9cb557a..1131e1b 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/LoggerContextFactoryExtension.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/LoggerContextFactoryExtension.java
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.extension.ExtensionContext;
 /**
  * JUnit 5 extension that sets a particular {@link LoggerContextFactory} for the entire run of tests in a class.
  *
- * @since 3.0.0
+ * @since 2.14.0
  */
 public class LoggerContextFactoryExtension implements BeforeAllCallback, AfterAllCallback {
 
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerLevelExtension.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerLevelExtension.java
index f112652..5eb7de2 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerLevelExtension.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerLevelExtension.java
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.extension.ExtensionContext;
 /**
  * JUnit 5 test extension that sets a specific StatusLogger logging level for each test.
  *
- * @since 3.0.0
+ * @since 2.14.0
  */
 public class StatusLoggerLevelExtension implements BeforeEachCallback, AfterEachCallback {
 
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerRule.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerRule.java
index a424933..a14114b 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerRule.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerRule.java
@@ -25,7 +25,7 @@ import org.junit.rules.ExternalResource;
  * Log4j configuration file.
  *
  * @since 2.8
- * @deprecated Use {@link StatusLoggerLevelExtension}
+ * @deprecated Use {@link StatusLoggerLevelExtension} with JUnit 5
  */
 public class StatusLoggerRule extends ExternalResource {
 
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerLevelExtension.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextExtension.java
similarity index 50%
copy from log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerLevelExtension.java
copy to log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextExtension.java
index f112652..e163578 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/StatusLoggerLevelExtension.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextExtension.java
@@ -17,40 +17,41 @@
 
 package org.apache.logging.log4j.junit;
 
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.ThreadContextHolder;
 import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.BeforeEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 
-/**
- * JUnit 5 test extension that sets a specific StatusLogger logging level for each test.
- *
- * @since 3.0.0
- */
-public class StatusLoggerLevelExtension implements BeforeEachCallback, AfterEachCallback {
-
-    private static final String KEY = "previousLevel";
-    private final Level level;
-
-    public StatusLoggerLevelExtension(Level level) {
-        this.level = level;
-    }
-
+class ThreadContextExtension implements BeforeEachCallback, AfterEachCallback {
     @Override
     public void beforeEach(ExtensionContext context) throws Exception {
-        final StatusLogger logger = StatusLogger.getLogger();
-        getStore(context).put(KEY, logger.getLevel());
-        logger.setLevel(level);
+        final Class<?> testClass = context.getRequiredTestClass();
+        final ThreadContextHolder holder;
+        if (testClass.isAnnotationPresent(UsingAnyThreadContext.class)) {
+            holder = new ThreadContextHolder(true, true);
+            ThreadContext.clearAll();
+        } else if (testClass.isAnnotationPresent(UsingThreadContextMap.class)) {
+            holder = new ThreadContextHolder(true, false);
+            ThreadContext.clearMap();
+        } else if (testClass.isAnnotationPresent(UsingThreadContextStack.class)) {
+            holder = new ThreadContextHolder(false, true);
+            ThreadContext.clearStack();
+        } else {
+            return;
+        }
+        getStore(context).put(ThreadContextHolder.class, holder);
     }
 
     @Override
     public void afterEach(ExtensionContext context) throws Exception {
-        StatusLogger.getLogger().setLevel(getStore(context).get(KEY, Level.class));
+        final ThreadContextHolder holder = getStore(context).get(ThreadContextHolder.class, ThreadContextHolder.class);
+        if (holder != null) {
+            holder.restore();
+        }
     }
 
     private ExtensionContext.Store getStore(ExtensionContext context) {
-        return context.getStore(ExtensionContext.Namespace
-                .create(getClass(), context.getRequiredTestInstance(), context.getRequiredTestMethod()));
+        return context.getStore(ExtensionContext.Namespace.create(getClass(), context.getRequiredTestInstance()));
     }
 }
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextMapRule.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextMapRule.java
index 4066303..6b153fb 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextMapRule.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextMapRule.java
@@ -25,7 +25,10 @@ package org.apache.logging.log4j.junit;
  * &#64;Rule
  * public final ThreadContextMapRule threadContextRule = new ThreadContextMapRule();
  * </pre>
+ *
+ * @deprecated use {@link UsingThreadContextMap} with JUnit 5
  */
+@Deprecated
 public class ThreadContextMapRule extends ThreadContextRule {
 
     /**
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextRule.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextRule.java
index dad7b5b..1d95bf7 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextRule.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextRule.java
@@ -29,7 +29,10 @@ import org.junit.rules.ExternalResource;
  * &#64;Rule
  * public final ThreadContextRule threadContextRule = new ThreadContextRule();
  * </pre>
+ *
+ * @deprecated use {@link UsingAnyThreadContext} with JUnit 5
  */
+@Deprecated
 public class ThreadContextRule extends ExternalResource {
 
     private final boolean restoreMap;
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextStackRule.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextStackRule.java
index 1581dc8..b51c0b9 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextStackRule.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextStackRule.java
@@ -25,7 +25,9 @@ package org.apache.logging.log4j.junit;
  * &#64;Rule
  * public final ThreadContextStackRule threadContextRule = new ThreadContextStackRule();
  * </pre>
+ * @deprecated use {@link UsingThreadContextStack} with JUnit 5
  */
+@Deprecated
 public class ThreadContextStackRule extends ThreadContextRule {
 
     /**
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingAnyThreadContext.java
similarity index 71%
copy from log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java
copy to log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingAnyThreadContext.java
index fd3e4f4..935df61 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingAnyThreadContext.java
@@ -17,18 +17,25 @@
 
 package org.apache.logging.log4j.junit;
 
+import org.junit.jupiter.api.extension.ExtendWith;
+
 import java.lang.annotation.Documented;
 import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+/**
+ * Marks a test class as using {@link org.apache.logging.log4j.ThreadContext} APIs. This will automatically clear and restore
+ * both the thread context map and stack for each test invocation.
+ *
+ * @since 2.14.0
+ */
 @Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.PARAMETER)
+@Target(ElementType.TYPE)
 @Documented
-public @interface Named {
-    /**
-     * Specifies the name of the configuration item to inject. If blank, uses the name of the annotated parameter.
-     */
-    String value() default "";
+@Inherited
+@ExtendWith(ThreadContextExtension.class)
+public @interface UsingAnyThreadContext {
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingThreadContextMap.java
similarity index 71%
copy from log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java
copy to log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingThreadContextMap.java
index fd3e4f4..df608f8 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingThreadContextMap.java
@@ -17,18 +17,25 @@
 
 package org.apache.logging.log4j.junit;
 
+import org.junit.jupiter.api.extension.ExtendWith;
+
 import java.lang.annotation.Documented;
 import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+/**
+ * Marks a test class as using {@link org.apache.logging.log4j.spi.ThreadContextMap} APIs. This will automatically clear and
+ * restore the thread context map (MDC) for each test invocation.
+ *
+ * @since 2.14.0
+ */
 @Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.PARAMETER)
+@Target(ElementType.TYPE)
 @Documented
-public @interface Named {
-    /**
-     * Specifies the name of the configuration item to inject. If blank, uses the name of the annotated parameter.
-     */
-    String value() default "";
+@Inherited
+@ExtendWith(ThreadContextExtension.class)
+public @interface UsingThreadContextMap {
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingThreadContextStack.java
similarity index 71%
copy from log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java
copy to log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingThreadContextStack.java
index fd3e4f4..7d47e49 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/UsingThreadContextStack.java
@@ -17,18 +17,25 @@
 
 package org.apache.logging.log4j.junit;
 
+import org.junit.jupiter.api.extension.ExtendWith;
+
 import java.lang.annotation.Documented;
 import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+/**
+ * Marks a test class as using {@link org.apache.logging.log4j.spi.ThreadContextStack} APIs. This will automatically clear and
+ * restore the thread context stack (NDC) for each test invocation.
+ *
+ * @since 2.14.0
+ */
 @Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.PARAMETER)
+@Target(ElementType.TYPE)
 @Documented
-public @interface Named {
-    /**
-     * Specifies the name of the configuration item to inject. If blank, uses the name of the annotated parameter.
-     */
-    String value() default "";
+@Inherited
+@ExtendWith(ThreadContextExtension.class)
+public @interface UsingThreadContextStack {
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
index 6d6f276..9ee22f1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
@@ -26,6 +26,7 @@ import org.apache.logging.log4j.core.config.Configurator;
 import org.apache.logging.log4j.core.config.LoggerConfig;
 import org.apache.logging.log4j.junit.LoggerContextSource;
 import org.apache.logging.log4j.junit.Named;
+import org.apache.logging.log4j.junit.ReconfigurationPolicy;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.MessageFactory;
 import org.apache.logging.log4j.message.ParameterizedMessageFactory;
@@ -51,7 +52,7 @@ import java.util.concurrent.TimeUnit;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.junit.jupiter.api.Assertions.*;
 
-@LoggerContextSource(value = LoggerTest.CONFIG, reconfigure = true)
+@LoggerContextSource(value = LoggerTest.CONFIG, reconfigure = ReconfigurationPolicy.AFTER_EACH)
 public class LoggerTest {
 
     static final String CONFIG = "log4j-test2.xml";
@@ -84,7 +85,7 @@ public class LoggerTest {
         final List<LogEvent> events = app.getEvents();
         assertEventCount(events, 3);
         assertEquals(
-                "org.apache.logging.log4j.core.LoggerTest.builder(LoggerTest.java:80)", events.get(0).getSource().toString(),
+                "org.apache.logging.log4j.core.LoggerTest.builder(LoggerTest.java:81)", events.get(0).getSource().toString(),
                 "Incorrect location");
         assertEquals(Level.DEBUG, events.get(0).getLevel(), "Incorrect Level");
         MatcherAssert.assertThat("Incorrect message", events.get(1).getMessage().getFormattedMessage(), equalTo("Hello John"));
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
index 57c8910..e90f943 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
@@ -19,9 +19,9 @@ package org.apache.logging.log4j.core.jmx;
 
 import javax.management.ObjectName;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Unit tests for the Server class.
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
index 04505d4..b29b25d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
@@ -18,9 +18,9 @@ package org.apache.logging.log4j.core.layout;/*
 import java.nio.charset.Charset;
 
 import org.apache.logging.log4j.core.LogEvent;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests AbstractStringLayout.
@@ -48,30 +48,32 @@ public class AbstractStringLayoutTest {
     public void testGetStringBuilderCapacityRestrictedToMax() throws Exception {
         final StringBuilder sb = ConcreteStringLayout.getStringBuilder();
         final int initialCapacity = sb.capacity();
-        assertEquals("initial capacity", ConcreteStringLayout.DEFAULT_STRING_BUILDER_SIZE, sb.capacity());
+        assertEquals(ConcreteStringLayout.DEFAULT_STRING_BUILDER_SIZE, sb.capacity(), "initial capacity");
 
         final int SMALL = 100;
         final String smallMessage = new String(new char[SMALL]);
         sb.append(smallMessage);
-        assertTrue("capacity not grown", sb.capacity() == initialCapacity);
-        assertEquals("length=msg length", SMALL, sb.length());
+        assertEquals(initialCapacity, sb.capacity(), "capacity not grown");
+        assertEquals(SMALL, sb.length(), "length=msg length");
 
         final StringBuilder sb2 = ConcreteStringLayout.getStringBuilder();
-        assertEquals("capacity unchanged", sb2.capacity(), initialCapacity);
-        assertEquals("empty, ready for use", 0, sb2.length());
+        assertEquals(sb2.capacity(), initialCapacity, "capacity unchanged");
+        assertEquals(0, sb2.length(), "empty, ready for use");
 
         final int LARGE = ConcreteStringLayout.MAX_STRING_BUILDER_SIZE * 2;
         final String largeMessage = new String(new char[LARGE]);
         sb2.append(largeMessage);
-        assertTrue("capacity grown to fit msg length", sb2.capacity() >= LARGE);
-        assertTrue("capacity is now greater than max length", sb2.capacity() >= ConcreteStringLayout.MAX_STRING_BUILDER_SIZE);
-        assertEquals("length=msg length", LARGE, sb2.length());
+        assertTrue(sb2.capacity() >= LARGE, "capacity grown to fit msg length");
+        assertTrue(sb2.capacity() >= ConcreteStringLayout.MAX_STRING_BUILDER_SIZE,
+                "capacity is now greater than max length");
+        assertEquals(LARGE, sb2.length(), "length=msg length");
         sb2.setLength(0); // set 0 before next getStringBuilder() call
-        assertEquals("empty, cleared", 0, sb2.length());
-        assertTrue("capacity remains very large", sb2.capacity() >= ConcreteStringLayout.MAX_STRING_BUILDER_SIZE);
+        assertEquals(0, sb2.length(), "empty, cleared");
+        assertTrue(sb2.capacity() >= ConcreteStringLayout.MAX_STRING_BUILDER_SIZE, "capacity remains very large");
 
         final StringBuilder sb3 = ConcreteStringLayout.getStringBuilder();
-        assertEquals("capacity, trimmed to MAX_STRING_BUILDER_SIZE", ConcreteStringLayout.MAX_STRING_BUILDER_SIZE, sb3.capacity());
-        assertEquals("empty, ready for use", 0, sb3.length());
+        assertEquals(ConcreteStringLayout.MAX_STRING_BUILDER_SIZE, sb3.capacity(),
+                "capacity, trimmed to MAX_STRING_BUILDER_SIZE");
+        assertEquals(0, sb3.length(), "empty, ready for use");
     }
 }
\ No newline at end of file
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/ConcurrentLoggingWithGelfLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/ConcurrentLoggingWithGelfLayoutTest.java
index af04b35..7f16909 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/ConcurrentLoggingWithGelfLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/ConcurrentLoggingWithGelfLayoutTest.java
@@ -16,9 +16,11 @@
  */
 package org.apache.logging.log4j.core.layout;
 
-import java.io.File;
+import java.io.IOException;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
@@ -26,35 +28,36 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.AfterClass;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
 
 import static org.hamcrest.CoreMatchers.endsWith;
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.*;
+import static org.hamcrest.MatcherAssert.*;
 
 /**
  * Test for LOG4J2-1769, kind of.
  *
  * @since 2.8
  */
+@Tag("concurrency")
+@LoggerContextSource("log4j2-gelf-layout.xml")
 public class ConcurrentLoggingWithGelfLayoutTest {
-    @ClassRule
-    public static LoggerContextRule context = new LoggerContextRule("log4j2-gelf-layout.xml");
-    private static final String PATH = "target/test-gelf-layout.log";
+    private static final Path PATH = Paths.get("target", "test-gelf-layout.log");
 
-    @AfterClass
-    public static void after() {
-        new File(PATH).delete();
+    @AfterAll
+    static void after() throws IOException {
+        Files.deleteIfExists(PATH);
     }
 
     @Test
-    public void testConcurrentLogging() throws Throwable {
-        final Logger log = context.getLogger(ConcurrentLoggingWithGelfLayoutTest.class);
-        final Set<Thread> threads = Collections.synchronizedSet(new HashSet<Thread>());
-        final List<Throwable> thrown = Collections.synchronizedList(new ArrayList<Throwable>());
+    public void testConcurrentLogging(final LoggerContext context) throws Throwable {
+        final Logger log = context.getLogger(ConcurrentLoggingWithGelfLayoutTest.class.getName());
+        final Set<Thread> threads = Collections.synchronizedSet(new HashSet<>());
+        final List<Throwable> thrown = Collections.synchronizedList(new ArrayList<>());
 
         for (int x = 0; x < Runtime.getRuntime().availableProcessors() * 2; x++) {
             final Thread t = new LoggingThread(threads, log);
@@ -62,12 +65,7 @@ public class ConcurrentLoggingWithGelfLayoutTest {
 
             // Appender is configured with ignoreExceptions="false";
             // any exceptions are propagated to the caller, so we can catch them here.
-            t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
-                @Override
-                public void uncaughtException(final Thread t, final Throwable e) {
-                    thrown.add(e);
-                }
-            });
+            t.setUncaughtExceptionHandler((t1, e) -> thrown.add(e));
             t.start();
         }
 
@@ -82,8 +80,8 @@ public class ConcurrentLoggingWithGelfLayoutTest {
         }
 
         // simple test to ensure content is not corrupted
-        if (new File(PATH).exists()) {
-            final List<String> lines = Files.readAllLines(new File(PATH).toPath(), Charset.defaultCharset());
+        if (Files.exists(PATH)) {
+            final List<String> lines = Files.readAllLines(PATH, Charset.defaultCharset());
             for (final String line : lines) {
                 assertThat(line, startsWith("{\"version\":\"1.1\",\"host\":\"myself\",\"timestamp\":"));
                 assertThat(line, endsWith("\"}"));
@@ -91,7 +89,7 @@ public class ConcurrentLoggingWithGelfLayoutTest {
         }
     }
 
-    private class LoggingThread extends Thread {
+    private static class LoggingThread extends Thread {
         private final Set<Thread> threads;
         private final Logger log;
 
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
index 3cc0a3a..4a6d08d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
@@ -30,13 +30,12 @@ import org.apache.logging.log4j.core.layout.GelfLayout.CompressionType;
 import org.apache.logging.log4j.core.lookup.JavaLookup;
 import org.apache.logging.log4j.core.util.KeyValuePair;
 import org.apache.logging.log4j.core.util.NetUtils;
-import org.apache.logging.log4j.junit.ThreadContextRule;
+import org.apache.logging.log4j.junit.UsingAnyThreadContext;
 import org.apache.logging.log4j.test.appender.EncodingListAppender;
 import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -46,8 +45,9 @@ import java.util.zip.GZIPInputStream;
 import java.util.zip.InflaterInputStream;
 
 import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.*;
 
+@UsingAnyThreadContext
 public class GelfLayoutTest {
 
     static ConfigurationFactory configFactory = new BasicConfigurationFactory();
@@ -64,15 +64,12 @@ public class GelfLayoutTest {
     private static final String MDCVALUE2 = "MdcValue2";
     private static final String VALUE1 = "Value1";
 
-    @Rule
-    public final ThreadContextRule threadContextRule = new ThreadContextRule();
-
-    @AfterClass
+    @AfterAll
     public static void cleanupClass() {
         ConfigurationFactory.removeConfigurationFactory(configFactory);
     }
 
-    @BeforeClass
+    @BeforeAll
     public static void setupClass() {
         ConfigurationFactory.setConfigurationFactory(configFactory);
         final LoggerContext ctx = LoggerContext.getContext();
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest2.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest2.java
index ed0fb4c..2b3f429 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest2.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest2.java
@@ -21,23 +21,24 @@ import java.io.IOException;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.lookup.JavaLookup;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.*;
 
+@LoggerContextSource("GelfLayoutTest2.xml")
 public class GelfLayoutTest2 {
 
-    @ClassRule
-    public static LoggerContextRule context = new LoggerContextRule("GelfLayoutTest2.xml");
-
     @Test
-    public void gelfLayout() throws IOException {
-        final Logger logger = context.getLogger();
+    public void gelfLayout(final LoggerContext context, @Named final ListAppender list) throws IOException {
+        list.clear();
+        final Logger logger = context.getLogger(getClass());
         logger.info("Message");
-        final String gelf = context.getListAppender("list").getMessages().get(0);
+        final String gelf = list.getMessages().get(0);
         final ObjectMapper mapper = new ObjectMapper();
         final JsonNode json = mapper.readTree(gelf);
         assertEquals("Message", json.get("short_message").asText());
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest3.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest3.java
index 9e02b65..fc9a404 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest3.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest3.java
@@ -20,36 +20,31 @@ import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.lookup.JavaLookup;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.After;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
+import org.apache.logging.log4j.junit.UsingAnyThreadContext;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
 
+@LoggerContextSource("GelfLayoutTest3.xml")
+@UsingAnyThreadContext
+@Tag("json")
 public class GelfLayoutTest3 {
 
-    @ClassRule
-    public static LoggerContextRule context = new LoggerContextRule("GelfLayoutTest3.xml");
-
-    @After
-    public void teardown() throws Exception {
-        ThreadContext.clearMap();
-    }
-
     @Test
-    public void gelfLayout() throws IOException {
-        final Logger logger = context.getLogger();
+    public void gelfLayout(final LoggerContext context, @Named final ListAppender list) throws IOException {
+        list.clear();
+        final Logger logger = context.getLogger(getClass());
         ThreadContext.put("loginId", "rgoers");
         ThreadContext.put("internalId", "12345");
         logger.info("My Test Message");
-        final String gelf = context.getListAppender("list").getMessages().get(0);
+        final String gelf = list.getMessages().get(0);
         final ObjectMapper mapper = new ObjectMapper();
         final JsonNode json = mapper.readTree(gelf);
         assertEquals("My Test Message", json.get("short_message").asText());
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
index 20a8dde..b6ad4c4 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
@@ -27,35 +27,29 @@ import org.apache.logging.log4j.core.BasicConfigurationFactory;
 import org.apache.logging.log4j.core.Logger;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.junit.ThreadContextRule;
+import org.apache.logging.log4j.junit.UsingAnyThreadContext;
 import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-/**
- *
- */
+@UsingAnyThreadContext
 public class HtmlLayoutTest {
-    LoggerContext ctx = LoggerContext.getContext();
-    Logger root = ctx.getRootLogger();
+    private final LoggerContext ctx = LoggerContext.getContext();
+    private final Logger root = ctx.getRootLogger();
 
     static ConfigurationFactory cf = new BasicConfigurationFactory();
 
-    @Rule
-    public final ThreadContextRule threadContextRule = new ThreadContextRule();
-
-    @BeforeClass
+    @BeforeAll
     public static void setupClass() {
         ConfigurationFactory.setConfigurationFactory(cf);
         final LoggerContext ctx = LoggerContext.getContext();
         ctx.reconfigure();
     }
 
-    @AfterClass
+    @AfterAll
     public static void cleanupClass() {
         ConfigurationFactory.removeConfigurationFactory(cf);
     }
@@ -140,17 +134,17 @@ public class HtmlLayoutTest {
             sb.append(string);
         }
         final String html = sb.toString();
-        assertTrue("Incorrect number of lines. Require at least 85 " + list.size(), list.size() > 85);
+        assertTrue(list.size() > 85, "Incorrect number of lines. Require at least 85 " + list.size());
         final String string = list.get(3);
-        assertTrue("Incorrect header: " + string, string.equals("<meta charset=\"UTF-8\"/>"));
-        assertTrue("Incorrect title", list.get(4).equals("<title>Log4j Log Messages</title>"));
-        assertTrue("Incorrect footer", list.get(list.size() - 1).equals("</body></html>"));
+        assertEquals("<meta charset=\"UTF-8\"/>", string, "Incorrect header: " + string);
+        assertEquals("<title>Log4j Log Messages</title>", list.get(4), "Incorrect title");
+        assertEquals("</body></html>", list.get(list.size() - 1), "Incorrect footer");
         if (includeLocation) {
-            assertTrue("Incorrect multiline", list.get(50).equals(multiLine));
-            assertTrue("Missing location", html.contains("HtmlLayoutTest.java:"));
-            assertTrue("Incorrect body", list.get(71).equals(body));
+            assertEquals(list.get(50), multiLine, "Incorrect multiline");
+            assertTrue(html.contains("HtmlLayoutTest.java:"), "Missing location");
+            assertEquals(list.get(71), body, "Incorrect body");
         } else {
-            assertFalse("Location should not be in the output table", html.contains("<td>HtmlLayoutTest.java:"));
+            assertFalse(html.contains("<td>HtmlLayoutTest.java:"), "Location should not be in the output table");
         }
         for (final Appender app : appenders.values()) {
             root.addAppender(app);
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/Log4j2_2195_Test.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/Log4j2_2195_Test.java
index 5112e5d..ea2433e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/Log4j2_2195_Test.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/Log4j2_2195_Test.java
@@ -20,43 +20,38 @@ package org.apache.logging.log4j.core.layout;
 import java.io.Serializable;
 import java.util.List;
 
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer;
-import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
 import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class Log4j2_2195_Test {
-
-    @ClassRule
-    public static final LoggerContextRule loggerContextRule = new LoggerContextRule(
-            "src/test/resources/LOG4J-2195/log4j2.xml");
+import static org.junit.jupiter.api.Assertions.*;
 
-    private static final Logger logger = LogManager.getLogger(Log4j2_2195_Test.class);
+@LoggerContextSource("LOG4J-2195/log4j2.xml")
+public class Log4j2_2195_Test {
 
     @Test
-    public void test() {
-        logger.info("This is a test.", new Exception("Test exception!"));
-        final ListAppender listAppender = loggerContextRule.getListAppender("ListAppender");
-        Assert.assertNotNull(listAppender);
-        final List<String> events = listAppender.getMessages();
-        Assert.assertNotNull(events);
-        Assert.assertEquals(1, events.size());
-        final String logEvent = events.get(0);
-        Assert.assertNotNull(logEvent);
-        Assert.assertFalse("\"org.junit\" should not be here", logEvent.contains("org.junit"));
-        Assert.assertFalse("\"org.eclipse\" should not be here", logEvent.contains("org.eclipse"));
+    public void test(final LoggerContext context, @Named("ListAppender") final ListAppender listAppender) {
+        listAppender.clear();
+        context.getLogger(getClass()).info("This is a test.", new Exception("Test exception!"));
+        assertNotNull(listAppender);
+        List<String> events = listAppender.getMessages();
+        assertNotNull(events);
+        assertEquals(1, events.size());
+        String logEvent = events.get(0);
+        assertNotNull(logEvent);
+        assertFalse(logEvent.contains("org.junit"), "\"org.junit\" should not be here");
+        assertFalse(logEvent.contains("org.eclipse"), "\"org.eclipse\" should not be here");
         //
-        final Layout<? extends Serializable> layout = listAppender.getLayout();
-        final PatternLayout pLayout = (PatternLayout) layout;
-        Assert.assertNotNull(pLayout);
-        final Serializer eventSerializer = pLayout.getEventSerializer();
-        Assert.assertNotNull(eventSerializer);
+        Layout<? extends Serializable> layout = listAppender.getLayout();
+        PatternLayout pLayout = (PatternLayout) layout;
+        assertNotNull(pLayout);
+        Serializer eventSerializer = pLayout.getEventSerializer();
+        assertNotNull(eventSerializer);
         //
-        Assert.assertTrue("Missing \"|\"", logEvent.contains("|"));
+        assertTrue(logEvent.contains("|"), "Missing \"|\"");
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutLookupDateTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutLookupDateTest.java
index 402ea1b..d814d1d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutLookupDateTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutLookupDateTest.java
@@ -16,29 +16,29 @@
  */
 package org.apache.logging.log4j.core.layout;
 
-import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
 import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
 
 /**
  * See (LOG4J2-905) Ability to disable (date) lookup completely, compatibility issues with other libraries like camel.
  *
  * This shows the behavior this user wants to disable.
  */
+@LoggerContextSource("log4j-list.xml")
 public class PatternLayoutLookupDateTest {
 
-    @Rule
-    public final LoggerContextRule context = new LoggerContextRule("log4j-list.xml");
-
     @Test
-    public void testDateLookupInMessage() {
+    public void testDateLookupInMessage(final LoggerContext context, @Named("List") final ListAppender listAppender) {
+        listAppender.clear();
         final String template = "${date:YYYY-MM-dd}";
         context.getLogger(PatternLayoutLookupDateTest.class.getName()).info(template);
-        final ListAppender listAppender = context.getListAppender("List");
         final String string = listAppender.getMessages().get(0);
-        Assert.assertFalse(string, string.contains(template));
+        assertFalse(string.contains(template), string);
     }
 
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutMainMapLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutMainMapLookupTest.java
index 120af89..69b8aa3 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutMainMapLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutMainMapLookupTest.java
@@ -17,20 +17,26 @@
 
 package org.apache.logging.log4j.core.layout;
 
-import java.util.List;
-
 import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.FileAppender;
 import org.apache.logging.log4j.core.lookup.MainMapLookup;
-import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
+import org.apache.logging.log4j.junit.ReconfigurationPolicy;
 import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 
 /**
  * Tests LOG4j2-962.
  */
+@LoggerContextSource(value = "log4j2-962.xml", reconfigure = ReconfigurationPolicy.BEFORE_EACH)
 public class PatternLayoutMainMapLookupTest {
 
     static {
@@ -38,29 +44,25 @@ public class PatternLayoutMainMapLookupTest {
         MainMapLookup.setMainArguments("value0", "value1", "value2");
     }
 
-    @ClassRule
-    public static LoggerContextRule context = new LoggerContextRule("log4j2-962.xml");
-
     @Test
-    public void testFileName() {
-        final FileAppender fileApp = (FileAppender) context.getRequiredAppender("File");
+    public void testFileName(@Named("File") final FileAppender fileApp) {
         final String name = fileApp.getFileName();
-        Assert.assertEquals("target/value0.log", name);
+        assertEquals("target/value0.log", name);
     }
 
     @Test
-    public void testHeader() {
-        final ListAppender listApp = context.getListAppender("List");
-        final Logger logger = context.getLogger(this.getClass().getName());
+    public void testHeader(final LoggerContext context, @Named("List") final ListAppender listApp) {
+        final Logger logger = context.getLogger(getClass());
         logger.info("Hello World");
         final List<String> initialMessages = listApp.getMessages();
-        Assert.assertFalse(initialMessages.isEmpty());
+        assertFalse(initialMessages.isEmpty());
         final String messagesStr = initialMessages.toString();
-        Assert.assertEquals(messagesStr, "Header: value0", initialMessages.get(0));
+        assertEquals("Header: value0", initialMessages.get(0), messagesStr);
         listApp.stop();
         final List<String> finalMessages = listApp.getMessages();
-        Assert.assertEquals(3, finalMessages.size());
-        Assert.assertEquals("Footer: value1", finalMessages.get(2));
+        assertEquals(3, finalMessages.size());
+        assertEquals("Footer: value1", finalMessages.get(2));
+        listApp.clear();
     }
 
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutNoLookupDateTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutNoLookupDateTest.java
index 4dcd942..78ae6dc 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutNoLookupDateTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutNoLookupDateTest.java
@@ -16,27 +16,26 @@
  */
 package org.apache.logging.log4j.core.layout;
 
-import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
 import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
 
 /**
  * See (LOG4J2-905) Ability to disable (date) lookup completely, compatibility issues with other libraries like camel.
  */
+@LoggerContextSource("log4j-list-nolookups.xml")
 public class PatternLayoutNoLookupDateTest {
 
-    @Rule
-    public final LoggerContextRule context = new LoggerContextRule("log4j-list-nolookups.xml");
-
     @Test
-    public void testDateLookupInMessage() {
+    public void testDateLookupInMessage(final LoggerContext context, @Named("List") final ListAppender listAppender) {
+        listAppender.clear();
         final String template = "${date:YYYY-MM-dd}";
-        context.getLogger(PatternLayoutNoLookupDateTest.class.getName()).info(template);
-        final ListAppender listAppender = context.getListAppender("List");
+        context.getLogger(PatternLayoutNoLookupDateTest.class).info(template);
         final String string = listAppender.getMessages().get(0);
-        Assert.assertTrue(string, string.contains(template));
+        Assertions.assertTrue(string.contains(template), string);
     }
 
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
index 4749546..7f429c0 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
@@ -16,11 +16,6 @@
  */
 package org.apache.logging.log4j.core.layout;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
@@ -36,18 +31,17 @@ import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.lookup.MainMapLookup;
-import org.apache.logging.log4j.junit.ThreadContextRule;
+import org.apache.logging.log4j.junit.UsingAnyThreadContext;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.util.Strings;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
-/**
- *
- */
+import static org.junit.jupiter.api.Assertions.*;
+
+@UsingAnyThreadContext
 public class PatternLayoutTest {
-    public class FauxLogger {
+    public static class FauxLogger {
         public String formatEvent(final LogEvent event, final Layout<?> layout) {
             return new String(layout.toByteArray(event));
         }
@@ -63,7 +57,7 @@ public class PatternLayoutTest {
         ConfigurationFactory.removeConfigurationFactory(cf);
     }
 
-    @BeforeClass
+    @BeforeAll
     public static void setupClass() {
         ConfigurationFactory.setConfigurationFactory(cf);
         final LoggerContext ctx = LoggerContext.getContext();
@@ -74,9 +68,6 @@ public class PatternLayoutTest {
 
     Logger root = ctx.getRootLogger();
 
-    @Rule
-    public final ThreadContextRule threadContextRule = new ThreadContextRule();
-
     private static class Destination implements ByteBufferDestination {
         ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[2048]);
         @Override
@@ -145,24 +136,24 @@ public class PatternLayoutTest {
         final PatternLayout layout = PatternLayout.newBuilder().withConfiguration(ctx.getConfiguration())
                 .withHeader("Header: " + pattern).withFooter("Footer: " + pattern).build();
         final byte[] header = layout.getHeader();
-        assertNotNull("No header", header);
+        assertNotNull(header, "No header");
         final String headerStr = new String(header);
-        assertTrue(headerStr, headerStr.contains("Header: "));
-        assertTrue(headerStr, headerStr.contains("Java version "));
-        assertTrue(headerStr, headerStr.contains("(build "));
-        assertTrue(headerStr, headerStr.contains(" from "));
-        assertTrue(headerStr, headerStr.contains(" architecture: "));
-        assertFalse(headerStr, headerStr.contains("%d{UNIX}"));
+        assertTrue(headerStr.contains("Header: "), headerStr);
+        assertTrue(headerStr.contains("Java version "), headerStr);
+        assertTrue(headerStr.contains("(build "), headerStr);
+        assertTrue(headerStr.contains(" from "), headerStr);
+        assertTrue(headerStr.contains(" architecture: "), headerStr);
+        assertFalse(headerStr.contains("%d{UNIX}"), headerStr);
         //
         final byte[] footer = layout.getFooter();
-        assertNotNull("No footer", footer);
+        assertNotNull(footer, "No footer");
         final String footerStr = new String(footer);
-        assertTrue(footerStr, footerStr.contains("Footer: "));
-        assertTrue(footerStr, footerStr.contains("Java version "));
-        assertTrue(footerStr, footerStr.contains("(build "));
-        assertTrue(footerStr, footerStr.contains(" from "));
-        assertTrue(footerStr, footerStr.contains(" architecture: "));
-        assertFalse(footerStr, footerStr.contains("%d{UNIX}"));
+        assertTrue(footerStr.contains("Footer: "), footerStr);
+        assertTrue(footerStr.contains("Java version "), footerStr);
+        assertTrue(footerStr.contains("(build "), footerStr);
+        assertTrue(footerStr.contains(" from "), footerStr);
+        assertTrue(footerStr.contains(" architecture: "), footerStr);
+        assertFalse(footerStr.contains("%d{UNIX}"), footerStr);
     }
 
     /**
@@ -174,14 +165,14 @@ public class PatternLayoutTest {
         final PatternLayout layout = PatternLayout.newBuilder().withConfiguration(ctx.getConfiguration())
                 .withHeader("${main:0}").withFooter("${main:2}").build();
         final byte[] header = layout.getHeader();
-        assertNotNull("No header", header);
+        assertNotNull(header, "No header");
         final String headerStr = new String(header);
-        assertTrue(headerStr, headerStr.contains("value0"));
+        assertTrue(headerStr.contains("value0"), headerStr);
         //
         final byte[] footer = layout.getFooter();
-        assertNotNull("No footer", footer);
+        assertNotNull(footer, "No footer");
         final String footerStr = new String(footer);
-        assertTrue(footerStr, footerStr.contains("value2"));
+        assertTrue(footerStr.contains("value2"), footerStr);
     }
 
     @Test
@@ -192,9 +183,9 @@ public class PatternLayoutTest {
         ThreadContext.put("header", "Hello world Header");
         ThreadContext.put("footer", "Hello world Footer");
         final byte[] header = layout.getHeader();
-        assertNotNull("No header", header);
-        assertTrue("expected \"Hello world Header\", actual " + Strings.dquote(new String(header)),
-                new String(header).equals(new String("Hello world Header")));
+        assertNotNull(header, "No header");
+        assertEquals("Hello world Header", new String(header),
+                "expected \"Hello world Header\", actual " + Strings.dquote(new String(header)));
     }
 
     private void testMdcPattern(final String patternStr, final String expectedStr, final boolean useThreadContext)
@@ -258,14 +249,14 @@ public class PatternLayoutTest {
                 .setMessage(new SimpleMessage("entry")).build();
         final String result1 = new FauxLogger().formatEvent(event1, layout);
         final String expectPattern1 = String.format(".*====== PatternLayoutTest.testPatternSelector:\\d+ entry ======%n");
-        assertTrue("Unexpected result: " + result1, result1.matches(expectPattern1));
+        assertTrue(result1.matches(expectPattern1), "Unexpected result: " + result1);
         final LogEvent event2 = Log4jLogEvent.newBuilder() //
                 .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
                 .setLevel(Level.INFO) //
                 .setMessage(new SimpleMessage("Hello, world 1!")).build();
         final String result2 = new String(layout.toByteArray(event2));
         final String expectSuffix2 = String.format("Hello, world 1!%n");
-        assertTrue("Unexpected result: " + result2, result2.endsWith(expectSuffix2));
+        assertTrue(result2.endsWith(expectSuffix2), "Unexpected result: " + result2);
     }
 
     @Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternSelectorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternSelectorTest.java
index 67e2d4c..5c36c5e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternSelectorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternSelectorTest.java
@@ -16,8 +16,6 @@
  */
 package org.apache.logging.log4j.core.layout;
 
-import static org.junit.Assert.assertTrue;
-
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.core.Layout;
@@ -25,11 +23,13 @@ import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.message.SimpleMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
 
 public class PatternSelectorTest {
 
-    public class FauxLogger {
+    public static class FauxLogger {
         public String formatEvent(final LogEvent event, final Layout<?> layout) {
             return new String(layout.toByteArray(event));
         }
@@ -52,14 +52,14 @@ public class PatternSelectorTest {
                 .setMessage(new SimpleMessage("entry")).build();
         final String result1 = new FauxLogger().formatEvent(event1, layout);
         final String expectSuffix1 = String.format("====== PatternSelectorTest.testMarkerPatternSelector:53 entry ======%n");
-        assertTrue("Unexpected result: " + result1, result1.endsWith(expectSuffix1));
+        assertTrue(result1.endsWith(expectSuffix1), "Unexpected result: " + result1);
         final LogEvent event2 = Log4jLogEvent.newBuilder() //
                 .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
                 .setLevel(Level.INFO) //
                 .setMessage(new SimpleMessage("Hello, world 1!")).build();
         final String result2 = new String(layout.toByteArray(event2));
         final String expectSuffix2 = String.format("Hello, world 1!%n");
-        assertTrue("Unexpected result: " + result2, result2.endsWith(expectSuffix2));
+        assertTrue(result2.endsWith(expectSuffix2), "Unexpected result: " + result2);
     }
 
 
@@ -77,14 +77,14 @@ public class PatternSelectorTest {
                 .setMessage(new SimpleMessage("entry")).build();
         final String result1 = new FauxLogger().formatEvent(event1, layout);
         final String expectSuffix1 = String.format("====== PatternSelectorTest.testLevelPatternSelector:78 entry ======%n");
-        assertTrue("Unexpected result: " + result1, result1.endsWith(expectSuffix1));
+        assertTrue(result1.endsWith(expectSuffix1), "Unexpected result: " + result1);
         final LogEvent event2 = Log4jLogEvent.newBuilder() //
                 .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
                 .setLevel(Level.INFO) //
                 .setMessage(new SimpleMessage("Hello, world 1!")).build();
         final String result2 = new String(layout.toByteArray(event2));
         final String expectSuffix2 = String.format("Hello, world 1!%n");
-        assertTrue("Unexpected result: " + result2, result2.endsWith(expectSuffix2));
+        assertTrue(result2.endsWith(expectSuffix2), "Unexpected result: " + result2);
     }
 
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/Rfc5424LayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/Rfc5424LayoutTest.java
index 0b9b50d..9dece77 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/Rfc5424LayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/Rfc5424LayoutTest.java
@@ -31,21 +31,20 @@ import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.net.Facility;
 import org.apache.logging.log4j.core.util.KeyValuePair;
-import org.apache.logging.log4j.junit.ThreadContextRule;
+import org.apache.logging.log4j.junit.UsingAnyThreadContext;
 import org.apache.logging.log4j.message.StructuredDataCollectionMessage;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.test.appender.ListAppender;
 import org.apache.logging.log4j.util.ProcessIdUtil;
 import org.apache.logging.log4j.util.Strings;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
+@UsingAnyThreadContext
 public class Rfc5424LayoutTest {
     LoggerContext ctx = LoggerContext.getContext();
     Logger root = ctx.getRootLogger();
@@ -72,10 +71,7 @@ public class Rfc5424LayoutTest {
 
     static ConfigurationFactory cf = new BasicConfigurationFactory();
 
-    @Rule
-    public final ThreadContextRule threadContextRule = new ThreadContextRule();
-
-    @BeforeClass
+    @BeforeAll
     public static void setupClass() {
         StatusLogger.getLogger().setLevel(Level.OFF);
         ConfigurationFactory.setConfigurationFactory(cf);
@@ -83,7 +79,7 @@ public class Rfc5424LayoutTest {
         ctx.reconfigure();
     }
 
-    @AfterClass
+    @AfterAll
     public static void cleanupClass() {
         ConfigurationFactory.removeConfigurationFactory(cf);
     }
@@ -130,10 +126,10 @@ public class Rfc5424LayoutTest {
 
             List<String> list = appender.getMessages();
 
-            assertTrue("Expected line 1 to end with: " + line1 + " Actual " + list.get(0), list.get(0).endsWith(line1));
-            assertTrue("Expected line 2 to end with: " + line2 + " Actual " + list.get(1), list.get(1).endsWith(line2));
-            assertTrue("Expected line 3 to end with: " + line3 + " Actual " + list.get(2), list.get(2).endsWith(line3));
-            assertTrue("Expected line 4 to end with: " + line4 + " Actual " + list.get(3), list.get(3).endsWith(line4));
+            assertTrue(list.get(0).endsWith(line1), "Expected line 1 to end with: " + line1 + " Actual " + list.get(0));
+            assertTrue(list.get(1).endsWith(line2), "Expected line 2 to end with: " + line2 + " Actual " + list.get(1));
+            assertTrue(list.get(2).endsWith(line3), "Expected line 3 to end with: " + line3 + " Actual " + list.get(2));
+            assertTrue(list.get(3).endsWith(line4), "Expected line 4 to end with: " + line4 + " Actual " + list.get(3));
 
             for (final String frame : list) {
                 int length = -1;
@@ -146,7 +142,7 @@ public class Rfc5424LayoutTest {
                     assertEquals(frameLength, messageLength.length() + length);
                 }
                 catch (final NumberFormatException e) {
-                    assertTrue("Not a valid RFC 5425 frame", false);
+                    fail("Not a valid RFC 5425 frame");
                 }
             }
 
@@ -157,9 +153,8 @@ public class Rfc5424LayoutTest {
             root.debug("This is a test");
 
             list = appender.getMessages();
-            assertTrue("No messages expected, found " + list.size(), list.isEmpty());
+            assertTrue(list.isEmpty(), "No messages expected, found " + list.size());
         } finally {
-            ThreadContext.clearMap();
             root.removeAppender(appender);
             appender.stop();
         }
@@ -202,16 +197,17 @@ public class Rfc5424LayoutTest {
 
             root.info(MarkerManager.getMarker("EVENT"), collectionMessage);
 
-            final List<String> list = appender.getMessages();
-            final String result = list.get(0);
-            assertTrue("Expected line to contain " + collectionLine1 + ", Actual " + result,
-                    result.contains(collectionLine1));
-            assertTrue("Expected line to contain " + collectionLine2 + ", Actual " + result,
-                    result.contains(collectionLine2));
-            assertTrue("Expected line to contain " + collectionLine3 + ", Actual " + result,
-                    result.contains(collectionLine3));
-            assertTrue("Expected line to end with: " + collectionEndOfLine + " Actual " + result,
-                    result.endsWith(collectionEndOfLine));
+            List<String> list = appender.getMessages();
+            String result = list.get(0);
+            assertTrue(
+                    result.contains(collectionLine1), "Expected line to contain " + collectionLine1 + ", Actual " + result);
+            assertTrue(
+                    result.contains(collectionLine2), "Expected line to contain " + collectionLine2 + ", Actual " + result);
+            assertTrue(
+                    result.contains(collectionLine3), "Expected line to contain " + collectionLine3 + ", Actual " + result);
+            assertTrue(
+                    result.endsWith(collectionEndOfLine),
+                    "Expected line to end with: " + collectionEndOfLine + " Actual " + result);
 
             for (final String frame : list) {
                 int length = -1;
@@ -224,13 +220,12 @@ public class Rfc5424LayoutTest {
                     assertEquals(frameLength, messageLength.length() + length);
                 }
                 catch (final NumberFormatException e) {
-                    assertTrue("Not a valid RFC 5425 frame", false);
+                    fail("Not a valid RFC 5425 frame");
                 }
             }
 
             appender.clear();
         } finally {
-            ThreadContext.clearMap();
             root.removeAppender(appender);
             appender.stop();
         }
@@ -277,10 +272,12 @@ public class Rfc5424LayoutTest {
 
             List<String> list = appender.getMessages();
 
-            assertTrue("Expected line 1 to end with: " + line1 + " Actual " + list.get(0), list.get(0).endsWith(line1));
-            assertTrue("Expected line 2 to end with: " + line2 + " Actual " + list.get(1), list.get(1).endsWith(line2));
-            assertTrue("Expected line 3 to end with: " + lineEscaped3 + " Actual " + list.get(2), list.get(2).endsWith(lineEscaped3));
-            assertTrue("Expected line 4 to end with: " + lineEscaped4 + " Actual " + list.get(3), list.get(3).endsWith(lineEscaped4));
+            assertTrue(list.get(0).endsWith(line1), "Expected line 1 to end with: " + line1 + " Actual " + list.get(0));
+            assertTrue(list.get(1).endsWith(line2), "Expected line 2 to end with: " + line2 + " Actual " + list.get(1));
+            assertTrue(list.get(2).endsWith(lineEscaped3),
+                    "Expected line 3 to end with: " + lineEscaped3 + " Actual " + list.get(2));
+            assertTrue(list.get(3).endsWith(lineEscaped4),
+                    "Expected line 4 to end with: " + lineEscaped4 + " Actual " + list.get(3));
 
             appender.clear();
 
@@ -289,7 +286,7 @@ public class Rfc5424LayoutTest {
             root.debug("This is a test");
 
             list = appender.getMessages();
-            assertTrue("No messages expected, found " + list.size(), list.isEmpty());
+            assertTrue(list.isEmpty(), "No messages expected, found " + list.size());
         } finally {
             root.removeAppender(appender);
             appender.stop();
@@ -323,9 +320,9 @@ public class Rfc5424LayoutTest {
 
             final List<String> list = appender.getMessages();
 
-            assertTrue("Not enough list entries", list.size() > 1);
+            assertTrue(list.size() > 1, "Not enough list entries");
             final String string = list.get(1);
-			      assertTrue("No Exception in " + string, string.contains("IllegalArgumentException"));
+			      assertTrue(string.contains("IllegalArgumentException"), "No Exception in " + string);
 
             appender.clear();
         } finally {
@@ -364,8 +361,8 @@ public class Rfc5424LayoutTest {
         try {
 
             final List<String> list = appender.getMessages();
-            assertTrue("Not enough list entries", list.size() > 0);
-            assertTrue("No class/method", list.get(0).contains("Rfc5424LayoutTest.testMDCLoggerFields"));
+            assertTrue(list.size() > 0, "Not enough list entries");
+            assertTrue(list.get(0).contains("Rfc5424LayoutTest.testMDCLoggerFields"), "No class/method");
 
             appender.clear();
         } finally {
@@ -408,11 +405,11 @@ public class Rfc5424LayoutTest {
         try {
 
             final List<String> list = appender.getMessages();
-            assertTrue("Not enough list entries", list.size() > 0);
+            assertTrue(list.size() > 0, "Not enough list entries");
             final String message =  list.get(0);
-            assertTrue("No class/method", message.contains("Rfc5424LayoutTest.testLoggerFields"));
+            assertTrue(message.contains("Rfc5424LayoutTest.testLoggerFields"), "No class/method");
             for (final String value : expectedToContain) {
-                Assert.assertTrue("Message expected to contain " + value + " but did not", message.contains(value));
+                assertTrue(message.contains(value), "Message expected to contain " + value + " but did not");
             }
             appender.clear();
         } finally {
@@ -455,11 +452,11 @@ public class Rfc5424LayoutTest {
         try {
 
             final List<String> list = appender.getMessages();
-            assertTrue("Not enough list entries", list.size() > 0);
+            assertTrue(list.size() > 0, "Not enough list entries");
             final String message =  list.get(0);
-            Assert.assertTrue("SD-ID should have been discarded", !message.contains("SD-ID"));
-            Assert.assertTrue("BAZ should have been included", message.contains("BAZ"));
-            Assert.assertTrue(mdcId + "should have been included", message.contains(mdcId));
+            assertFalse(message.contains("SD-ID"), "SD-ID should have been discarded");
+            assertTrue(message.contains("BAZ"), "BAZ should have been included");
+            assertTrue(message.contains(mdcId), mdcId + "should have been included");
             appender.clear();
         } finally {
             root.removeAppender(appender);
@@ -489,9 +486,9 @@ public class Rfc5424LayoutTest {
 
         try {
             final List<String> list = appender.getMessages();
-            assertTrue("Not enough list entries", list.size() > 0);
+            assertTrue(list.size() > 0, "Not enough list entries");
             final String message =  list.get(0);
-            Assert.assertTrue("Not the expected message received", message.contains(expectedToContain));
+            assertTrue(message.contains(expectedToContain), "Not the expected message received");
             appender.clear();
         } finally {
             root.removeAppender(appender);
@@ -517,9 +514,10 @@ public class Rfc5424LayoutTest {
         root.info("Hello {}", "World");
         try {
             final List<String> list = appender.getMessages();
-            assertTrue("Not enough list entries", list.size() > 0);
+            assertTrue(list.size() > 0, "Not enough list entries");
             final String message =  list.get(0);
-            assertTrue("Incorrect message. Expected - Hello World, Actual - " + message, message.contains("Hello World"));
+            assertTrue(message.contains("Hello World"),
+                    "Incorrect message. Expected - Hello World, Actual - " + message);
         } finally {
             root.removeAppender(appender);
             appender.stop();
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/StringBuilderEncoderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/StringBuilderEncoderTest.java
index 51faed9..575f838 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/StringBuilderEncoderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/StringBuilderEncoderTest.java
@@ -19,9 +19,9 @@ import java.nio.CharBuffer;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
-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 TextEncoderHelper} class.
@@ -35,11 +35,11 @@ public class StringBuilderEncoderTest {
         final SpyByteBufferDestination destination = new SpyByteBufferDestination(17, 17);
         helper.encode(text, destination);
 
-        assertEquals("drained", 0, destination.drainPoints.size());
-        assertEquals("destination.buf.pos", text.length(), destination.buffer.position());
+        assertEquals(0, destination.drainPoints.size(), "drained");
+        assertEquals(text.length(), destination.buffer.position(), "destination.buf.pos");
 
         for (int i = 0; i < text.length(); i++) {
-            assertEquals("char at " + i, (byte) text.charAt(i), destination.buffer.get(i));
+            assertEquals((byte) text.charAt(i), destination.buffer.get(i), "char at " + i);
         }
     }
 
@@ -50,19 +50,19 @@ public class StringBuilderEncoderTest {
         final SpyByteBufferDestination destination = new SpyByteBufferDestination(14, 15);
         helper.encode(text, destination);
 
-        assertEquals("drained", 1, destination.drainPoints.size());
-        assertEquals("drained[0].from", 0, destination.drainPoints.get(0).position);
-        assertEquals("drained[0].to", destination.buffer.capacity(), destination.drainPoints.get(0).limit);
-        assertEquals("drained[0].length", destination.buffer.capacity(), destination.drainPoints.get(0).length());
-        assertEquals("destination.buf.pos", text.length() - destination.buffer.capacity(),
-                destination.buffer.position());
+        assertEquals(1, destination.drainPoints.size(), "drained");
+        assertEquals(0, destination.drainPoints.get(0).position, "drained[0].from");
+        assertEquals(destination.buffer.capacity(), destination.drainPoints.get(0).limit, "drained[0].to");
+        assertEquals(destination.buffer.capacity(), destination.drainPoints.get(0).length(), "drained[0].length");
+        assertEquals(text.length() - destination.buffer.capacity(),
+                destination.buffer.position(), "destination.buf.pos");
 
         for (int i = 0; i < destination.buffer.capacity(); i++) {
-            assertEquals("char at " + i, (byte) text.charAt(i), destination.drained.get(i));
+            assertEquals((byte) text.charAt(i), destination.drained.get(i), "char at " + i);
         }
         for (int i = destination.buffer.capacity(); i < text.length(); i++) {
             final int bufIx = i - destination.buffer.capacity();
-            assertEquals("char at " + i, (byte) text.charAt(i), destination.buffer.get(bufIx));
+            assertEquals((byte) text.charAt(i), destination.buffer.get(bufIx), "char at " + i);
         }
     }
 
@@ -73,25 +73,25 @@ public class StringBuilderEncoderTest {
         final SpyByteBufferDestination destination = new SpyByteBufferDestination(4, 20);
         helper.encode(text, destination);
 
-        assertEquals("drained", 3, destination.drainPoints.size());
-        assertEquals("drained[0].from", 0, destination.drainPoints.get(0).position);
-        assertEquals("drained[0].to", destination.buffer.capacity(), destination.drainPoints.get(0).limit);
-        assertEquals("drained[0].length", destination.buffer.capacity(), destination.drainPoints.get(0).length());
-        assertEquals("drained[1].from", 0, destination.drainPoints.get(1).position);
-        assertEquals("drained[1].to", destination.buffer.capacity(), destination.drainPoints.get(1).limit);
-        assertEquals("drained[1].length", destination.buffer.capacity(), destination.drainPoints.get(1).length());
-        assertEquals("drained[2].from", 0, destination.drainPoints.get(2).position);
-        assertEquals("drained[2].to", destination.buffer.capacity(), destination.drainPoints.get(2).limit);
-        assertEquals("drained[2].length", destination.buffer.capacity(), destination.drainPoints.get(2).length());
-        assertEquals("destination.buf.pos", text.length() - 3 * destination.buffer.capacity(),
-                destination.buffer.position());
+        assertEquals(3, destination.drainPoints.size(), "drained");
+        assertEquals(0, destination.drainPoints.get(0).position, "drained[0].from");
+        assertEquals(destination.buffer.capacity(), destination.drainPoints.get(0).limit, "drained[0].to");
+        assertEquals(destination.buffer.capacity(), destination.drainPoints.get(0).length(), "drained[0].length");
+        assertEquals(0, destination.drainPoints.get(1).position, "drained[1].from");
+        assertEquals(destination.buffer.capacity(), destination.drainPoints.get(1).limit, "drained[1].to");
+        assertEquals(destination.buffer.capacity(), destination.drainPoints.get(1).length(), "drained[1].length");
+        assertEquals(0, destination.drainPoints.get(2).position, "drained[2].from");
+        assertEquals(destination.buffer.capacity(), destination.drainPoints.get(2).limit, "drained[2].to");
+        assertEquals(destination.buffer.capacity(), destination.drainPoints.get(2).length(), "drained[2].length");
+        assertEquals(text.length() - 3 * destination.buffer.capacity(),
+                destination.buffer.position(), "destination.buf.pos");
 
         for (int i = 0; i < 3 * destination.buffer.capacity(); i++) {
-            assertEquals("char at " + i, (byte) text.charAt(i), destination.drained.get(i));
+            assertEquals((byte) text.charAt(i), destination.drained.get(i), "char at " + i);
         }
         for (int i = 3 * destination.buffer.capacity(); i < text.length(); i++) {
             final int bufIx = i - 3 * destination.buffer.capacity();
-            assertEquals("char at " + i, (byte) text.charAt(i), destination.buffer.get(bufIx));
+            assertEquals((byte) text.charAt(i), destination.buffer.get(bufIx), "char at " + i);
         }
     }
 
@@ -102,11 +102,11 @@ public class StringBuilderEncoderTest {
         final SpyByteBufferDestination destination = new SpyByteBufferDestination(17, 17);
         helper.encode(text, destination);
 
-        assertEquals("drained", 0, destination.drainPoints.size());
-        assertEquals("destination.buf.pos", text.length(), destination.buffer.position());
+        assertEquals(0, destination.drainPoints.size(), "drained");
+        assertEquals(text.length(), destination.buffer.position(), "destination.buf.pos");
 
         for (int i = 0; i < text.length(); i++) {
-            assertEquals("char at " + i, (byte) text.charAt(i), destination.buffer.get(i));
+            assertEquals((byte) text.charAt(i), destination.buffer.get(i), "char at " + i);
         }
     }
 
@@ -118,12 +118,12 @@ public class StringBuilderEncoderTest {
         final SpyByteBufferDestination destination = new SpyByteBufferDestination(50, 50);
         helper.encode(text, destination);
 
-        assertEquals("drained", 0, destination.drainPoints.size());
+        assertEquals(0, destination.drainPoints.size(), "drained");
         destination.drain(destination.getByteBuffer());
 
         final byte[] utf8 = text.toString().getBytes(StandardCharsets.UTF_8);
         for (int i = 0; i < utf8.length; i++) {
-            assertEquals("byte at " + i, utf8[i], destination.drained.get(i));
+            assertEquals(utf8[i], destination.drained.get(i), "byte at " + i);
         }
     }
 
@@ -136,12 +136,12 @@ public class StringBuilderEncoderTest {
         final SpyByteBufferDestination destination = new SpyByteBufferDestination(50, 50);
         helper.encode(text, destination);
 
-        assertEquals("drained", 0, destination.drainPoints.size());
+        assertEquals(0, destination.drainPoints.size(), "drained");
         destination.drain(destination.getByteBuffer());
 
         final byte[] bytes = text.toString().getBytes(SHIFT_JIS);
         for (int i = 0; i < bytes.length; i++) {
-            assertEquals("byte at " + i, bytes[i], destination.drained.get(i));
+            assertEquals(bytes[i], destination.drained.get(i), "byte at " + i);
         }
     }
 
@@ -152,14 +152,14 @@ public class StringBuilderEncoderTest {
         final SpyByteBufferDestination destination = new SpyByteBufferDestination(3, 17);
         helper.encode(text, destination);
 
-        assertEquals("drained", 4, destination.drainPoints.size());
-        assertEquals("destination.buf.pos", 3, destination.buffer.position());
+        assertEquals(4, destination.drainPoints.size(), "drained");
+        assertEquals(3, destination.buffer.position(), "destination.buf.pos");
 
         for (int i = 0; i < text.length() - 3; i++) {
-            assertEquals("char at " + i, (byte) text.charAt(i), destination.drained.get(i));
+            assertEquals((byte) text.charAt(i), destination.drained.get(i), "char at " + i);
         }
         for (int i = 0; i < 3; i++) {
-            assertEquals("char at " + (12 + i), (byte) text.charAt(12 + i), destination.buffer.get(i));
+            assertEquals((byte) text.charAt(12 + i), destination.buffer.get(i), "char at " + (12 + i));
         }
     }
 
@@ -171,12 +171,12 @@ public class StringBuilderEncoderTest {
         final SpyByteBufferDestination destination = new SpyByteBufferDestination(3, 50);
         helper.encode(text, destination);
 
-        assertEquals("drained", 7, destination.drainPoints.size());
+        assertEquals(7, destination.drainPoints.size(), "drained");
         destination.drain(destination.getByteBuffer());
 
         final byte[] utf8 = text.toString().getBytes(StandardCharsets.UTF_8);
         for (int i = 0; i < utf8.length; i++) {
-            assertEquals("byte at " + i, utf8[i], destination.drained.get(i));
+            assertEquals(utf8[i], destination.drained.get(i), "byte at " + i);
         }
     }
 
@@ -188,12 +188,12 @@ public class StringBuilderEncoderTest {
         final SpyByteBufferDestination destination = new SpyByteBufferDestination(3, 50);
         helper.encode(text, destination);
 
-        assertEquals("drained", 15, destination.drainPoints.size());
+        assertEquals(15, destination.drainPoints.size(), "drained");
         destination.drain(destination.getByteBuffer());
 
         final byte[] utf8 = text.toString().getBytes(StandardCharsets.UTF_8);
         for (int i = 0; i < utf8.length; i++) {
-            assertEquals("byte at " + i, utf8[i], destination.drained.get(i));
+            assertEquals(utf8[i], destination.drained.get(i), "byte at " + i);
         }
     }
 
@@ -210,7 +210,7 @@ public class StringBuilderEncoderTest {
 
         final byte[] bytes = text.toString().getBytes(SHIFT_JIS);
         for (int i = 0; i < bytes.length; i++) {
-            assertEquals("byte at " + i, bytes[i], destination.drained.get(i));
+            assertEquals(bytes[i], destination.drained.get(i), "byte at " + i);
         }
     }
 
@@ -227,7 +227,7 @@ public class StringBuilderEncoderTest {
 
         final byte[] bytes = text.toString().getBytes(SHIFT_JIS);
         for (int i = 0; i < bytes.length; i++) {
-            assertEquals("byte at " + i, bytes[i], destination.drained.get(i));
+            assertEquals(bytes[i], destination.drained.get(i), "byte at " + i);
         }
     }
 
@@ -236,11 +236,11 @@ public class StringBuilderEncoderTest {
         final CharBuffer buff = CharBuffer.wrap(new char[16]);
         final StringBuilder text = createText(15);
         final int length = TextEncoderHelper.copy(text, 0, buff);
-        assertEquals("everything fits", text.length(), length);
+        assertEquals(text.length(), length, "everything fits");
         for (int i = 0; i < length; i++) {
-            assertEquals("char at " + i, text.charAt(i), buff.get(i));
+            assertEquals(text.charAt(i), buff.get(i), "char at " + i);
         }
-        assertEquals("position moved by length", text.length(), buff.position());
+        assertEquals(text.length(), buff.position(), "position moved by length");
     }
 
     @Test
@@ -248,27 +248,27 @@ public class StringBuilderEncoderTest {
         final CharBuffer buff = CharBuffer.wrap(new char[3]);
         final StringBuilder text = createText(15);
         final int length = TextEncoderHelper.copy(text, 0, buff);
-        assertEquals("partial copy", buff.capacity(), length);
+        assertEquals(buff.capacity(), length, "partial copy");
         for (int i = 0; i < length; i++) {
-            assertEquals("char at " + i, text.charAt(i), buff.get(i));
+            assertEquals(text.charAt(i), buff.get(i), "char at " + i);
         }
-        assertEquals("no space remaining", 0, buff.remaining());
-        assertEquals("position at end", buff.capacity(), buff.position());
+        assertEquals(0, buff.remaining(), "no space remaining");
+        assertEquals(buff.capacity(), buff.position(), "position at end");
     }
 
     @Test
     public void testCopyDoesNotWriteBeyondStringText() throws Exception {
         final CharBuffer buff = CharBuffer.wrap(new char[5]);
-        assertEquals("initial buffer position", 0, buff.position());
+        assertEquals(0, buff.position(), "initial buffer position");
         final StringBuilder text = createText(2);
         final int length = TextEncoderHelper.copy(text, 0, buff);
-        assertEquals("full copy", text.length(), length);
+        assertEquals(text.length(), length, "full copy");
         for (int i = 0; i < length; i++) {
-            assertEquals("char at " + i, text.charAt(i), buff.get(i));
+            assertEquals(text.charAt(i), buff.get(i), "char at " + i);
         }
-        assertEquals("resulting buffer position", text.length(), buff.position());
+        assertEquals(text.length(), buff.position(), "resulting buffer position");
         for (int i = length; i < buff.capacity(); i++) {
-            assertEquals("unset char at " + i, 0, buff.get(i));
+            assertEquals(0, buff.get(i), "unset char at " + i);
         }
     }
 
@@ -279,11 +279,11 @@ public class StringBuilderEncoderTest {
         buff.position(START_POSITION); // set start position
         final StringBuilder text = createText(15);
         final int length = TextEncoderHelper.copy(text, 0, buff);
-        assertEquals("partial copy", buff.capacity() - START_POSITION, length);
+        assertEquals(buff.capacity() - START_POSITION, length, "partial copy");
         for (int i = 0; i < length; i++) {
-            assertEquals("char at " + i, text.charAt(i), buff.get(START_POSITION + i));
+            assertEquals(text.charAt(i), buff.get(START_POSITION + i), "char at " + i);
         }
-        assertEquals("buffer position at end", buff.capacity(), buff.position());
+        assertEquals(buff.capacity(), buff.position(), "buffer position at end");
     }
 
     @Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/SyslogLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/SyslogLayoutTest.java
index d9bd5b0..fd710b8 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/SyslogLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/SyslogLayoutTest.java
@@ -28,19 +28,16 @@ import org.apache.logging.log4j.core.Logger;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.net.Facility;
-import org.apache.logging.log4j.junit.ThreadContextRule;
+import org.apache.logging.log4j.junit.UsingAnyThreadContext;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-/**
- *
- */
+@UsingAnyThreadContext
 public class SyslogLayoutTest {
     LoggerContext ctx = LoggerContext.getContext();
     Logger root = ctx.getRootLogger();
@@ -54,17 +51,14 @@ public class SyslogLayoutTest {
 
     static ConfigurationFactory cf = new BasicConfigurationFactory();
 
-    @Rule
-    public final ThreadContextRule threadContextRule = new ThreadContextRule();
-
-    @BeforeClass
+    @BeforeAll
     public static void setupClass() {
         ConfigurationFactory.setConfigurationFactory(cf);
         final LoggerContext ctx = LoggerContext.getContext();
         ctx.reconfigure();
     }
 
-    @AfterClass
+    @AfterAll
     public static void cleanupClass() {
         ConfigurationFactory.removeConfigurationFactory(cf);
     }
@@ -115,9 +109,9 @@ public class SyslogLayoutTest {
 
         final List<String> list = appender.getMessages();
 
-        assertTrue("Expected line 1 to end with: " + line1 + " Actual " + list.get(0), list.get(0).endsWith(line1));
-        assertTrue("Expected line 2 to end with: " + line2 + " Actual " + list.get(1), list.get(1).endsWith(line2));
-        assertTrue("Expected line 3 to end with: " + line3 + " Actual " + list.get(2), list.get(2).endsWith(line3));
-        assertTrue("Expected line 4 to end with: " + line4 + " Actual " + list.get(3), list.get(3).endsWith(line4));
+        assertTrue(list.get(0).endsWith(line1), "Expected line 1 to end with: " + line1 + " Actual " + list.get(0));
+        assertTrue(list.get(1).endsWith(line2), "Expected line 2 to end with: " + line2 + " Actual " + list.get(1));
+        assertTrue(list.get(2).endsWith(line3), "Expected line 3 to end with: " + line3 + " Actual " + list.get(2));
+        assertTrue(list.get(3).endsWith(line4), "Expected line 4 to end with: " + line4 + " Actual " + list.get(3));
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
index b984253..2a94e47 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
@@ -18,34 +18,26 @@ package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.ThreadContextHolder;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.junit.UsingThreadContextMap;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.SimpleMessage;
-import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.*;
 
+@UsingThreadContextMap
 public class MdcPatternConverterTest {
 
-    private final ThreadContextHolder threadContextHolder = new ThreadContextHolder(true, false);
-
     @BeforeEach
     public void setup() {
-        ThreadContext.clearMap();
         ThreadContext.put("subject", "I");
         ThreadContext.put("verb", "love");
         ThreadContext.put("object", "Log4j");
     }
 
-    @AfterEach
-    public void tearDown() {
-        threadContextHolder.restore();
-    }
-
     @Test
     public void testConverter() {
         final Message msg = new SimpleMessage("Hello");
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NdcPatternConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NdcPatternConverterTest.java
index 4af2ad9..7ed39b7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NdcPatternConverterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NdcPatternConverterTest.java
@@ -18,31 +18,18 @@ package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.ThreadContextHolder;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.junit.UsingThreadContextStack;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.SimpleMessage;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.*;
 
+@UsingThreadContextStack
 public class NdcPatternConverterTest {
 
-    private final ThreadContextHolder holder = new ThreadContextHolder(false, true);
-
-    @BeforeEach
-    void setUp() {
-        ThreadContext.clearStack();
-    }
-
-    @AfterEach
-    void tearDown() {
-        holder.restore();
-    }
-
     @Test
     public void testEmpty() {
         testConverter("[]");
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RegexReplacementTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RegexReplacementTest.java
index 7d4e76d..541ae19 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RegexReplacementTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RegexReplacementTest.java
@@ -17,13 +17,12 @@
 package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.ThreadContextHolder;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.junit.LoggerContextSource;
 import org.apache.logging.log4j.junit.Named;
+import org.apache.logging.log4j.junit.UsingThreadContextMap;
 import org.apache.logging.log4j.test.appender.ListAppender;
 import org.apache.logging.log4j.util.Strings;
-import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Test;
 
 import java.util.List;
@@ -31,8 +30,8 @@ import java.util.List;
 import static org.junit.jupiter.api.Assertions.*;
 
 @LoggerContextSource("log4j-replace.xml")
+@UsingThreadContextMap
 public class RegexReplacementTest {
-    private final ThreadContextHolder holder = new ThreadContextHolder(true, false);
     private final ListAppender app;
     private final ListAppender app2;
     private final org.apache.logging.log4j.Logger logger;
@@ -46,12 +45,6 @@ public class RegexReplacementTest {
         logger2 = context.getLogger("ReplacementTest");
         this.app = app.clear();
         this.app2 = app2.clear();
-        ThreadContext.clearMap();
-    }
-
-    @AfterEach
-    void tearDown() {
-        holder.restore();
     }
 
     @Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextResolver.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextResolver.java
index 0859bbd..fb0f367 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextResolver.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextResolver.java
@@ -35,10 +35,10 @@ class LoggerContextResolver extends TypeBasedParameterResolver<LoggerContext> im
     @Override
     public void beforeAll(ExtensionContext context) throws Exception {
         final Class<?> testClass = context.getRequiredTestClass();
-        final LoggerContextSource source = testClass.getAnnotation(LoggerContextSource.class);
-        if (source != null) {
+        final LoggerContextSource testSource = testClass.getAnnotation(LoggerContextSource.class);
+        if (testSource != null) {
             final LoggerContext loggerContext =
-                    Configurator.initialize(context.getDisplayName(), testClass.getClassLoader(), source.value());
+                    Configurator.initialize(context.getDisplayName(), testClass.getClassLoader(), testSource.value());
             getTestClassStore(context).put(LoggerContext.class, loggerContext);
         }
     }
@@ -53,10 +53,21 @@ class LoggerContextResolver extends TypeBasedParameterResolver<LoggerContext> im
 
     @Override
     public void beforeEach(ExtensionContext context) throws Exception {
+        final Class<?> testClass = context.getRequiredTestClass();
+        final LoggerContextSource testSource = testClass.getAnnotation(LoggerContextSource.class);
+        if (testSource != null && testSource.reconfigure() == ReconfigurationPolicy.BEFORE_EACH) {
+            final LoggerContext loggerContext = getTestClassStore(context).get(LoggerContext.class, LoggerContext.class);
+            if (loggerContext == null) {
+                throw new IllegalStateException(
+                        "Specified test class reconfiguration policy of BEFORE_EACH, but no LoggerContext found for test class " +
+                                testClass.getCanonicalName());
+            }
+            loggerContext.reconfigure();
+        }
         final LoggerContextSource source = context.getRequiredTestMethod().getAnnotation(LoggerContextSource.class);
         if (source != null) {
             final LoggerContext loggerContext = Configurator
-                    .initialize(context.getDisplayName(), context.getRequiredTestClass().getClassLoader(), source.value());
+                    .initialize(context.getDisplayName(), testClass.getClassLoader(), source.value());
             getTestInstanceStore(context).put(LoggerContext.class, loggerContext);
         }
     }
@@ -71,11 +82,14 @@ class LoggerContextResolver extends TypeBasedParameterResolver<LoggerContext> im
         // reloadable variant
         final Class<?> testClass = context.getRequiredTestClass();
         final LoggerContextSource source = testClass.getAnnotation(LoggerContextSource.class);
-        if (source != null && source.reconfigure()) {
+        if (source != null && source.reconfigure() == ReconfigurationPolicy.AFTER_EACH) {
             final LoggerContext loggerContext = getTestClassStore(context).get(LoggerContext.class, LoggerContext.class);
-            if (loggerContext != null) {
-                loggerContext.reconfigure();
+            if (loggerContext == null) {
+                throw new IllegalStateException(
+                        "Specified test class reconfiguration policy of AFTER_EACH, but no LoggerContext found for test class " +
+                                testClass.getCanonicalName());
             }
+            loggerContext.reconfigure();
         }
     }
 
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextSource.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextSource.java
index baf9eb8..a6cedfb 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextSource.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextSource.java
@@ -17,7 +17,9 @@
 
 package org.apache.logging.log4j.junit;
 
+import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
 import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.extension.ExtendWith;
 
@@ -30,10 +32,20 @@ import java.lang.annotation.Target;
 
 /**
  * Specifies a configuration file to use for unit tests. This configuration file will be loaded once and used for all tests
- * executed in the annotated test class unless otherwise specified by {@link #reconfigure()}. When annotated on a test method, this
- * will override the class-level configuration if provided for that method.
+ * executed in the annotated test class unless otherwise specified by {@link #reconfigure()}. When annotated on a test method,
+ * this will override the class-level configuration if provided for that method. By using this JUnit 5 extension, the following
+ * types can be injected into tests via constructor or method parameters:
  *
- * @since 3.0.0
+ * <ul>
+ *     <li>{@link LoggerContext};</li>
+ *     <li>{@link Configuration};</li>
+ *     <li>any subclass of {@link Appender} paired with a {@link Named} annotation to select the appender by name.</li>
+ * </ul>
+ *
+ * Tests using this extension will automatically be tagged as {@code functional} to indicate they perform functional tests that
+ * rely on configuration files and production code.
+ *
+ * @since 2.14.0
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target({ElementType.TYPE, ElementType.METHOD})
@@ -50,7 +62,7 @@ public @interface LoggerContextSource {
     String value();
 
     /**
-     * Specifies whether or not to {@linkplain LoggerContext#reconfigure() reconfigure} after each test.
+     * Specifies when to {@linkplain LoggerContext#reconfigure() reconfigure} the logging system.
      */
-    boolean reconfigure() default false;
+    ReconfigurationPolicy reconfigure() default ReconfigurationPolicy.NEVER;
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java
index fd3e4f4..fe776d7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/Named.java
@@ -23,6 +23,13 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+/**
+ * Specifies the name of an {@link org.apache.logging.log4j.core.Appender} to inject into JUnit 5 tests from the specified
+ * configuration.
+ *
+ * @see LoggerContextSource
+ * @since 2.14.0
+ */
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.PARAMETER)
 @Documented
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextMapRule.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/ReconfigurationPolicy.java
similarity index 60%
copy from log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextMapRule.java
copy to log4j-core/src/test/java/org/apache/logging/log4j/junit/ReconfigurationPolicy.java
index 4066303..3b872bd 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/ThreadContextMapRule.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/ReconfigurationPolicy.java
@@ -14,24 +14,22 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
+
 package org.apache.logging.log4j.junit;
 
+import org.apache.logging.log4j.core.LoggerContext;
+
 /**
- * Restores the ThreadContext to it's initial map values after a JUnit test.
- * 
- * Usage:
- * 
- * <pre>
- * &#64;Rule
- * public final ThreadContextMapRule threadContextRule = new ThreadContextMapRule();
- * </pre>
+ * Indicates when to {@linkplain LoggerContext#reconfigure() reconfigure} the logging system during unit tests.
+ *
+ * @see LoggerContextSource
+ * @since 2.14.0
  */
-public class ThreadContextMapRule extends ThreadContextRule {
-
-    /**
-     * Constructs an initialized instance.
-     */
-    public ThreadContextMapRule() {
-        super(true, false);
-    }
+public enum ReconfigurationPolicy {
+    /** Performs no reconfiguration of the logging system for the entire run of tests in a test class. This is the default. */
+    NEVER,
+    /** Performs a reconfiguration before executing each test. */
+    BEFORE_EACH,
+    /** Performs a reconfiguration after executing each test. */
+    AFTER_EACH
 }


[logging-log4j2] 01/02: [LOG4J2-2653] Migrate lookup and net tests to JUnit 5

Posted by ma...@apache.org.
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 f8c68d1cfb442632530f5e13b9a15360b51c678d
Author: Matt Sicker <bo...@gmail.com>
AuthorDate: Sun Aug 23 19:43:13 2020 -0500

    [LOG4J2-2653] Migrate lookup and net tests to JUnit 5
    
    Backported from 3.x.
    
    Signed-off-by: Matt Sicker <bo...@gmail.com>
---
 log4j-core/pom.xml                                 |  5 +-
 .../logging/log4j/core/lookup/CaseLookupTest.java  | 12 +----
 .../log4j/core/lookup/ContextMapLookupTest.java    | 36 +++++--------
 .../logging/log4j/core/lookup/DateLookupTest.java  | 11 ++--
 .../log4j/core/lookup/EnvironmentLookupTest.java   |  8 +--
 .../logging/log4j/core/lookup/EventLookupTest.java |  7 ++-
 .../logging/log4j/core/lookup/Log4jLookupTest.java | 28 +++++-----
 .../core/lookup/Log4jLookupWithSpacesTest.java     | 29 +++++------
 .../lookup/MainInputArgumentsJmxLookupTest.java    | 14 ++---
 .../logging/log4j/core/lookup/MainLookupTest.java  | 30 +++++------
 .../logging/log4j/core/lookup/MapLookupTest.java   | 26 +++++-----
 .../log4j/core/lookup/MarkerLookupConfigTest.java  | 45 ++++++++--------
 .../log4j/core/lookup/MarkerLookupTest.java        |  7 ++-
 .../core/lookup/ResourceBundleLookupTest.java      | 17 +++---
 .../log4j/core/lookup/StrSubstitutorTest.java      | 15 +++---
 .../core/lookup/StructuredDataLookupTest.java      |  7 +--
 .../core/lookup/SystemPropertiesLookupTest.java    | 15 +++---
 .../message/ExtendedThreadInformationTest.java     |  6 +--
 .../logging/log4j/core/net/PriorityTest.java       |  9 ++--
 .../log4j/core/net/SocketMessageLossTest.java      | 24 ++++-----
 .../log4j/core/net/SocketReconnectTest.java        | 28 +++++-----
 .../apache/logging/log4j/core/net/SocketTest.java  | 37 ++++---------
 .../net/ssl/EnvironmentPasswordProviderTest.java   |  8 +--
 .../core/net/ssl/FilePasswordProviderTest.java     | 13 ++---
 .../core/net/ssl/KeyStoreConfigurationTest.java    | 60 ++++++++++++----------
 .../core/net/ssl/MemoryPasswordProviderTest.java   |  6 +--
 .../log4j/core/net/ssl/SslConfigurationTest.java   | 41 ++++++++-------
 .../log4j/core/net/ssl/StoreConfigurationTest.java | 16 +++---
 .../core/net/ssl/TrustStoreConfigurationTest.java  | 54 ++++++++++---------
 pom.xml                                            |  6 +++
 30 files changed, 282 insertions(+), 338 deletions(-)

diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml
index b2931ba..91333f3 100644
--- a/log4j-core/pom.xml
+++ b/log4j-core/pom.xml
@@ -212,7 +212,10 @@
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
-      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-junit-jupiter</artifactId>
     </dependency>
     <!-- Embedded JDBC drivers for database appender tests -->
     <dependency>
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/CaseLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/CaseLookupTest.java
index ae7d5ac..16d5f37 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/CaseLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/CaseLookupTest.java
@@ -16,18 +16,10 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import java.util.Calendar;
+import org.junit.jupiter.api.Test;
 
-import org.apache.logging.log4j.core.AbstractLogEvent;
-import org.apache.logging.log4j.core.LogEvent;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-/**
- *
- */
 public class CaseLookupTest {
 
 
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ContextMapLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ContextMapLookupTest.java
index b80491e..f35c8b1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ContextMapLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ContextMapLookupTest.java
@@ -31,9 +31,6 @@ import org.junit.runners.model.Statement;
 
 import static org.junit.Assert.*;
 
-/**
- *
- */
 public class ContextMapLookupTest {
 
     private static final String TESTKEY = "TestKey";
@@ -42,27 +39,22 @@ public class ContextMapLookupTest {
     private final LoggerContextRule context = new LoggerContextRule("ContextMapLookupTest.xml");
 
     @Rule
-    public RuleChain chain = RuleChain.outerRule(new TestRule() {
+    public RuleChain chain = RuleChain.outerRule((base, description) -> new Statement() {
         @Override
-        public Statement apply(final Statement base, final Description description) {
-            return new Statement() {
-                @Override
-                public void evaluate() throws Throwable {
-                    final File logFile = new File("target",
-                        description.getClassName() + '.' + description.getMethodName() + ".log");
-                    ThreadContext.put("testClassName", description.getClassName());
-                    ThreadContext.put("testMethodName", description.getMethodName());
-                    try {
-                        base.evaluate();
-                    } finally {
-                        ThreadContext.remove("testClassName");
-                        ThreadContext.remove("testMethodName");
-                        if (logFile.exists()) {
-                            logFile.deleteOnExit();
-                        }
-                    }
+        public void evaluate() throws Throwable {
+            final File logFile = new File("target",
+                description.getClassName() + '.' + description.getMethodName() + ".log");
+            ThreadContext.put("testClassName", description.getClassName());
+            ThreadContext.put("testMethodName", description.getMethodName());
+            try {
+                base.evaluate();
+            } finally {
+                ThreadContext.remove("testClassName");
+                ThreadContext.remove("testMethodName");
+                if (logFile.exists()) {
+                    logFile.deleteOnExit();
                 }
-            };
+            }
         }
     }).around(context);
 
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/DateLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/DateLookupTest.java
index 09794e2..a90a6e7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/DateLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/DateLookupTest.java
@@ -20,13 +20,10 @@ import java.util.Calendar;
 
 import org.apache.logging.log4j.core.AbstractLogEvent;
 import org.apache.logging.log4j.core.LogEvent;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-/**
- *
- */
 public class DateLookupTest {
 
 
@@ -39,7 +36,7 @@ public class DateLookupTest {
         assertEquals("12/30/2011", value);
     }
 
-    private class MyLogEvent extends AbstractLogEvent {
+    private static class MyLogEvent extends AbstractLogEvent {
         /**
          * Generated serial version ID.
          */
@@ -48,7 +45,7 @@ public class DateLookupTest {
         @Override
         public long getTimeMillis() {
             final Calendar cal = Calendar.getInstance();
-            cal.set(2011, 11, 30, 10, 56, 35);
+            cal.set(2011, Calendar.DECEMBER, 30, 10, 56, 35);
             return cal.getTimeInMillis();
         }
 
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EnvironmentLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EnvironmentLookupTest.java
index 5cae1b1..7636a1f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EnvironmentLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EnvironmentLookupTest.java
@@ -16,16 +16,12 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-/**
- *
- */
 public class EnvironmentLookupTest {
 
-
     @Test
     public void testLookup() {
         final StrLookup lookup = new EnvironmentLookup();
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EventLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EventLookupTest.java
index 96f6027..25006d2 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EventLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EventLookupTest.java
@@ -22,10 +22,9 @@ import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.message.SimpleMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests {@link MarkerLookup}.
@@ -114,4 +113,4 @@ public class EventLookupTest {
         assertEquals("Main", value);
     }
 
-}
\ No newline at end of file
+}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupTest.java
index 0db5db0..0ee103d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupTest.java
@@ -15,30 +15,26 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import java.io.File;
-import java.net.URISyntaxException;
-
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationAware;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.impl.ContextAnchor;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.io.File;
 
 import static org.apache.logging.log4j.core.lookup.Log4jLookup.KEY_CONFIG_LOCATION;
 import static org.apache.logging.log4j.core.lookup.Log4jLookup.KEY_CONFIG_PARENT_LOCATION;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.BDDMockito.given;
 
-/**
- *
- */
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
 public class Log4jLookupTest {
 
     private final static File EXPECT = new File(System.getProperty("user.home"), "/a/b/c/d/e/log4j2.xml");
@@ -50,14 +46,14 @@ public class Log4jLookupTest {
     @Mock
     private ConfigurationSource configSrc;
 
-    @Before
-    public void setup() throws URISyntaxException {
+    @BeforeEach
+    public void setup() {
         ContextAnchor.THREAD_CONTEXT.set(mockCtx);
         given(config.getConfigurationSource()).willReturn(configSrc);
         given(configSrc.getFile()).willReturn(EXPECT);
     }
 
-    @After
+    @AfterEach
     public void cleanup() {
         ContextAnchor.THREAD_CONTEXT.set(null);
     }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupWithSpacesTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupWithSpacesTest.java
index e5ecb49..94ff966 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupWithSpacesTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupWithSpacesTest.java
@@ -15,31 +15,26 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationAware;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.impl.ContextAnchor;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.io.File;
 
 import static org.apache.logging.log4j.core.lookup.Log4jLookup.KEY_CONFIG_LOCATION;
 import static org.apache.logging.log4j.core.lookup.Log4jLookup.KEY_CONFIG_PARENT_LOCATION;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.BDDMockito.given;
 
-/**
- *
- */
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
 public class Log4jLookupWithSpacesTest {
 
     private final static File EXPECT = new File(System.getProperty("user.home"), "/a a/b b/c c/d d/e e/log4j2 file.xml");
@@ -50,14 +45,14 @@ public class Log4jLookupWithSpacesTest {
     @Mock
     private ConfigurationSource configSrc;
 
-    @Before
-    public void setup() throws URISyntaxException, MalformedURLException {
+    @BeforeEach
+    public void setup() {
         ContextAnchor.THREAD_CONTEXT.set(mockCtx);
         given(config.getConfigurationSource()).willReturn(configSrc);
         given(configSrc.getFile()).willReturn(EXPECT);
     }
 
-    @After
+    @AfterEach
     public void cleanup() {
         ContextAnchor.THREAD_CONTEXT.set(null);
     }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java
index 22583d3..a3106a1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java
@@ -16,9 +16,9 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Test;
 
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests {@link JmxRuntimeInputArgumentsLookup} from the command line, not a JUnit test.
@@ -36,15 +36,15 @@ public class MainInputArgumentsJmxLookupTest {
     @Test
     public void testMap() {
         final JmxRuntimeInputArgumentsLookup lookup = JmxRuntimeInputArgumentsLookup.JMX_SINGLETON;
-        assertEquals(null, lookup.lookup(null));
-        assertEquals(null, lookup.lookup("X"));
-        assertEquals(null, lookup.lookup("foo.txt"));
+        assertNull(lookup.lookup(null));
+        assertNull(lookup.lookup("X"));
+        assertNull(lookup.lookup("foo.txt"));
     }
 
     public void callFromMain() {
         final JmxRuntimeInputArgumentsLookup lookup = JmxRuntimeInputArgumentsLookup.JMX_SINGLETON;
-        assertEquals(null, lookup.lookup(null));
-        assertEquals(null, lookup.lookup("X"));
+        assertNull(lookup.lookup(null));
+        assertNull(lookup.lookup("X"));
         // Eclipse adds -Dfile.encoding=Cp1252
         // assertEquals("--file", lookup.lookup("0"));
         // assertEquals("foo.txt", lookup.lookup("1"));
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java
index b019c2a..9c45774 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java
@@ -16,12 +16,12 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.util.HashMap;
 import java.util.Map;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests MainLookup.
@@ -39,18 +39,18 @@ public class MainLookupTest {
         StrSubstitutor substitutor = new StrSubstitutor(lookup);
         String replacedValue = substitutor.replace(null, str);
         String[] values = replacedValue.split(" ");
-        assertEquals("Item 0 is incorrect ", "value", values[0]);
-        assertEquals("Item 1 is incorrect ", "1", values[1]);
-        assertEquals("Item 2 is incorrect", "--file", values[2]);
-        assertEquals("Item 3 is incorrect", "foo.txt", values[3]);
-        assertEquals("Item 4 is incorrect", "--verbose", values[4]);
-        assertEquals("Item 5 is incorrect", "-x", values[5]);
-        assertEquals("Iten 6 is incorrect", "bar", values[6]);
-        assertEquals("Item 7 is incorrect", "foo.txt", values[7]);
-        assertEquals("Item 8 is incorrect", "--verbose", values[8]);
-        assertEquals("Item 9 is incorrect", "-x", values[9]);
-        assertEquals("Item 10 is incorrect", "bar", values[10]);
-        assertEquals("Item 11 is incorrect", "default_bar_value", values[11]);
-        assertEquals("Item 12 is incorrect", "true", values[12]);
+        assertEquals("value", values[0], "Item 0 is incorrect ");
+        assertEquals("1", values[1], "Item 1 is incorrect ");
+        assertEquals("--file", values[2], "Item 2 is incorrect");
+        assertEquals("foo.txt", values[3], "Item 3 is incorrect");
+        assertEquals("--verbose", values[4], "Item 4 is incorrect");
+        assertEquals("-x", values[5], "Item 5 is incorrect");
+        assertEquals("bar", values[6], "Iten 6 is incorrect");
+        assertEquals("foo.txt", values[7], "Item 7 is incorrect");
+        assertEquals("--verbose", values[8], "Item 8 is incorrect");
+        assertEquals("-x", values[9], "Item 9 is incorrect");
+        assertEquals("bar", values[10], "Item 10 is incorrect");
+        assertEquals("default_bar_value", values[11], "Item 11 is incorrect");
+        assertEquals("true", values[12], "Item 12 is incorrect");
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
index 4298d98..2804e97 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
@@ -16,15 +16,15 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import static org.junit.Assert.assertEquals;
-
 import java.util.HashMap;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.message.MapMessage;
 import org.apache.logging.log4j.message.StringMapMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests {@link MapLookup}.
@@ -34,8 +34,8 @@ public class MapLookupTest {
     @Test
     public void testEmptyMap() {
         final MapLookup lookup = new MapLookup(new HashMap<String, String>());
-        assertEquals(null, lookup.lookup(null));
-        assertEquals(null, lookup.lookup("X"));
+        assertNull(lookup.lookup(null));
+        assertNull(lookup.lookup("X"));
     }
 
     @Test
@@ -43,29 +43,27 @@ public class MapLookupTest {
         final HashMap<String, String> map = new HashMap<>();
         map.put("A", "B");
         final MapLookup lookup = new MapLookup(map);
-        assertEquals(null, lookup.lookup(null));
+        assertNull(lookup.lookup(null));
         assertEquals("B", lookup.lookup("A"));
     }
 
     @Test
     public void testNullMap() {
         final MapLookup lookup = new MapLookup();
-        assertEquals(null, lookup.lookup(null));
-        assertEquals(null, lookup.lookup("X"));
+        assertNull(lookup.lookup(null));
+        assertNull(lookup.lookup("X"));
     }
 
     @Test
     public void testMainMap() {
-        MapLookup.setMainArguments(new String[] {
-                "--file",
-                "foo.txt" });
+        MainMapLookup.setMainArguments("--file", "foo.txt");
         final MapLookup lookup = MainMapLookup.MAIN_SINGLETON;
-        assertEquals(null, lookup.lookup(null));
-        assertEquals(null, lookup.lookup("X"));
+        assertNull(lookup.lookup(null));
+        assertNull(lookup.lookup("X"));
         assertEquals("--file", lookup.lookup("0"));
         assertEquals("foo.txt", lookup.lookup("1"));
         assertEquals("foo.txt", lookup.lookup("--file"));
-        assertEquals(null, lookup.lookup("foo.txt"));
+        assertNull(lookup.lookup("foo.txt"));
     }
 
     @Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupConfigTest.java
index e3ce8d4..33f1f26 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupConfigTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupConfigTest.java
@@ -16,28 +16,31 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import java.io.File;
-import java.io.IOException;
-
 import org.apache.commons.io.FileUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.MarkerManager;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * Tests {@link MarkerLookup} with a configuration file.
  *
  * @since 2.4
  */
+@LoggerContextSource("log4j-marker-lookup.yaml")
+@Tag("yaml")
 public class MarkerLookupConfigTest {
 
-    @ClassRule
-    public static LoggerContextRule context = new LoggerContextRule("log4j-marker-lookup.yaml");
     public static final Marker PAYLOAD = MarkerManager.getMarker("PAYLOAD");
     private static final String PAYLOAD_LOG = "Message in payload.log";
 
@@ -54,22 +57,22 @@ public class MarkerLookupConfigTest {
         logger.info(PAYLOAD, PAYLOAD_LOG);
         logger.info(PERFORMANCE, PERFORMANCE_LOG);
         {
-            final String log = FileUtils.readFileToString(new File("target/logs/sql.log"));
-            Assert.assertTrue(log.contains(SQL_LOG));
-            Assert.assertFalse(log.contains(PAYLOAD_LOG));
-            Assert.assertFalse(log.contains(PERFORMANCE_LOG));
+            final String log = FileUtils.readFileToString(new File("target/logs/sql.log"), StandardCharsets.UTF_8);
+            assertTrue(log.contains(SQL_LOG));
+            assertFalse(log.contains(PAYLOAD_LOG));
+            assertFalse(log.contains(PERFORMANCE_LOG));
         }
         {
-            final String log = FileUtils.readFileToString(new File("target/logs/payload.log"));
-            Assert.assertFalse(log.contains(SQL_LOG));
-            Assert.assertTrue(log.contains(PAYLOAD_LOG));
-            Assert.assertFalse(log.contains(PERFORMANCE_LOG));
+            final String log = FileUtils.readFileToString(new File("target/logs/payload.log"), StandardCharsets.UTF_8);
+            assertFalse(log.contains(SQL_LOG));
+            assertTrue(log.contains(PAYLOAD_LOG));
+            assertFalse(log.contains(PERFORMANCE_LOG));
         }
         {
-            final String log = FileUtils.readFileToString(new File("target/logs/performance.log"));
-            Assert.assertFalse(log.contains(SQL_LOG));
-            Assert.assertFalse(log.contains(PAYLOAD_LOG));
-            Assert.assertTrue(log.contains(PERFORMANCE_LOG));
+            final String log = FileUtils.readFileToString(new File("target/logs/performance.log"), StandardCharsets.UTF_8);
+            assertFalse(log.contains(SQL_LOG));
+            assertFalse(log.contains(PAYLOAD_LOG));
+            assertTrue(log.contains(PERFORMANCE_LOG));
         }
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java
index fac33d4..3b27047 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java
@@ -16,16 +16,15 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.message.SimpleMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests {@link MarkerLookup}.
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookupTest.java
index f1aa6bf..6bd8838 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookupTest.java
@@ -16,36 +16,35 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
 
-/**
- *
- */
 public class ResourceBundleLookupTest {
 
     @Test
     public void testLookup() {
         final StrLookup lookup = new ResourceBundleLookup();
         lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle_en:KeyA");
-        Assert.assertEquals("ValueA", lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyA"));
+        assertEquals("ValueA", lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyA"));
     }
 
     @Test
     public void testLookupWithLocale() {
         final StrLookup lookup = new ResourceBundleLookup();
         lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyA");
-        Assert.assertEquals("ValueA", lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyA"));
+        assertEquals("ValueA", lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyA"));
     }
 
     public void testMissingKey() {
         final StrLookup lookup = new ResourceBundleLookup();
-        Assert.assertNull(lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyUnkown"));
+        assertNull(lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyUnkown"));
     }
 
     @Test
     public void testBadFormatBundleOnly() {
         final StrLookup lookup = new ResourceBundleLookup();
-        Assert.assertNull(lookup.lookup("X"));
+        assertNull(lookup.lookup("X"));
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StrSubstitutorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StrSubstitutorTest.java
index 41b7979..4edbd4e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StrSubstitutorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StrSubstitutorTest.java
@@ -20,27 +20,24 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.logging.log4j.ThreadContext;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-/**
- *
- */
 public class StrSubstitutorTest {
 
     private static final String TESTKEY = "TestKey";
     private static final String TESTVAL = "TestValue";
 
 
-    @BeforeClass
+    @BeforeAll
     public static void before() {
         System.setProperty(TESTKEY, TESTVAL);
     }
 
-    @AfterClass
+    @AfterAll
     public static void after() {
         System.clearProperty(TESTKEY);
     }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StructuredDataLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StructuredDataLookupTest.java
index 09081dd..737ff41 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StructuredDataLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StructuredDataLookupTest.java
@@ -21,13 +21,10 @@ import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.StructuredDataMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-/**
- *
- */
 public class StructuredDataLookupTest {
 
     private static final String TESTKEY = "type";
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookupTest.java
index 5749548..e4db4cb 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookupTest.java
@@ -16,26 +16,23 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-/**
- *
- */
 public class SystemPropertiesLookupTest {
 
     private static final String TESTKEY = "TestKey";
     private static final String TESTVAL = "TestValue";
 
-    @BeforeClass
+    @BeforeAll
     public static void before() {
         System.setProperty(TESTKEY, TESTVAL);
     }
 
-    @AfterClass
+    @AfterAll
     public static void after() {
         System.clearProperty(TESTKEY);
     }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/message/ExtendedThreadInformationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/message/ExtendedThreadInformationTest.java
index 8333f19..bc2b2df 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/message/ExtendedThreadInformationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/message/ExtendedThreadInformationTest.java
@@ -17,9 +17,9 @@
 package org.apache.logging.log4j.core.message;
 
 import org.apache.logging.log4j.message.ThreadDumpMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * Tests that ThreadDumpMessage uses ExtendedThreadInformation when available.
@@ -31,6 +31,6 @@ public class ExtendedThreadInformationTest {
 
         final String message = msg.getFormattedMessage();
         //System.out.print(message);
-        assertTrue("No header", message.contains(" Id="));
+        assertTrue(message.contains(" Id="), "No header");
     }
 }
\ No newline at end of file
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/PriorityTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/PriorityTest.java
index 234bf6b..83eb42f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/PriorityTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/PriorityTest.java
@@ -17,18 +17,15 @@
 package org.apache.logging.log4j.core.net;
 
 import org.apache.logging.log4j.Level;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-/**
- *
- */
 public class PriorityTest {
 
     @Test
     public void testP1() {
         final int p = Priority.getPriority(Facility.AUTH, Level.INFO);
-        assertTrue("Expected priority value is 38, got "+ p, p == 38);
+        assertEquals(38, p, "Expected priority value is 38, got " + p);
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketMessageLossTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketMessageLossTest.java
index 70ab122..27b4754 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketMessageLossTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketMessageLossTest.java
@@ -28,26 +28,22 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 
 import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.AppenderLoggingException;
-import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.junit.LoggerContextSource;
 import org.apache.logging.log4j.test.AvailablePortFinder;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-@Ignore("Currently needs better port choosing support")
+@Disabled("Currently needs better port choosing support")
+@LoggerContextSource("log4j-socket2.xml")
 public class SocketMessageLossTest {
     private static final int SOCKET_PORT = AvailablePortFinder.getNextAvailable();
 
-    private static final String CONFIG = "log4j-socket2.xml";
-
-    @ClassRule
-    public static LoggerContextRule context = new LoggerContextRule(CONFIG);
-
     @Test
-    public void testSocket() throws Exception {
+    public void testSocket(final LoggerContext context) throws Exception {
         TestSocketServer testServer;
         ExecutorService executor = null;
         Future<InputStream> futureIn;
@@ -59,7 +55,7 @@ public class SocketMessageLossTest {
             futureIn = executor.submit(testServer);
 
             //System.err.println("Initializing logger");
-            final Logger logger = context.getLogger();
+            final Logger logger = context.getLogger(getClass().getName());
 
             String message = "Log #1";
             logger.error(message);
@@ -69,7 +65,7 @@ public class SocketMessageLossTest {
 
             //System.err.println("Closing server");
             closeQuietly(testServer);
-            assertTrue("Server not shutdown", testServer.server.isClosed());
+            assertTrue(testServer.server.isClosed(), "Server not shutdown");
 
             //System.err.println("Sleeping to ensure no race conditions");
             Thread.sleep(1000);
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java
index 2edc1f3..918da60 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java
@@ -23,10 +23,10 @@ import org.apache.logging.log4j.core.appender.AppenderLoggingException;
 import org.apache.logging.log4j.core.config.Configurator;
 import org.apache.logging.log4j.test.AvailablePortFinder;
 import org.apache.logging.log4j.util.Strings;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -40,9 +40,9 @@ import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-//@Ignore("Currently needs better port choosing support")
+//@Disabled("Currently needs better port choosing support")
 public class SocketReconnectTest {
     private static final int SOCKET_PORT1 = AvailablePortFinder.getNextAvailable();
     private static final int SOCKET_PORT2 = AvailablePortFinder.getNextAvailable();
@@ -66,7 +66,7 @@ public class SocketReconnectTest {
     private static Logger logger;
 
 
-    @BeforeClass
+    @BeforeAll
     public static void beforeClass() throws IOException, InterruptedException {
         server1 = new TestSocketServer(0);
         server2 = new TestSocketServer(0);
@@ -89,12 +89,12 @@ public class SocketReconnectTest {
         list.clear();
     }
 
-    @AfterClass
+    @AfterAll
     public static void afterClass() {
         Configurator.shutdown(loggerContext);
     }
 
-    @After
+    @AfterEach
     public void after() throws InterruptedException {
         if (server1 != null) {
             server1.shutdown();
@@ -128,7 +128,7 @@ public class SocketReconnectTest {
                 }
             }
         }
-        assertNotNull("No message", msg);
+        assertNotNull(msg, "No message");
         assertEquals(message, msg);
 
         logger.error(SHUTDOWN);
@@ -148,7 +148,7 @@ public class SocketReconnectTest {
                 // System.err.println("Caught expected exception");
             }
         }
-        assertTrue("No Exception thrown", exceptionCaught);
+        assertTrue(exceptionCaught, "No Exception thrown");
         message = "Log #3";
 
 
@@ -167,7 +167,7 @@ public class SocketReconnectTest {
                 }
             }
         }
-        assertNotNull("No message", msg);
+        assertNotNull(msg, "No message");
         assertEquals(message, msg);
         logger.error(SHUTDOWN);
         server1.join();
@@ -196,7 +196,7 @@ public class SocketReconnectTest {
                 }
             }
         }
-        assertNotNull("No message", msg);
+        assertNotNull(msg, "No message");
         assertEquals(message, msg);
 
         server1.shutdown();
@@ -215,7 +215,7 @@ public class SocketReconnectTest {
                 }
             }
         }
-        assertNotNull("No message", msg);
+        assertNotNull(msg, "No message");
         assertEquals(message, msg);
 
         server2.shutdown();
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
index bcc207c..a50334a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
@@ -23,42 +23,25 @@ import java.net.Socket;
 import java.util.concurrent.Callable;
 
 import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.AppenderLoggingException;
-import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.junit.LoggerContextSource;
 import org.apache.logging.log4j.test.AvailablePortFinder;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-@Ignore("Currently needs better port choosing support")
+@Disabled("Currently needs better port choosing support")
+@LoggerContextSource("log4j-socket.xml")
 public class SocketTest {
     private static final int SOCKET_PORT = AvailablePortFinder.getNextAvailable();
 
-    private static final String CONFIG = "log4j-socket.xml";
-
-    @ClassRule
-    public static LoggerContextRule context = new LoggerContextRule(CONFIG);
-
     @Test
-    public void testConnect() throws Exception {
-        // TODO: there's a JUnit rule that simplifies this (matt)
+    public void testConnect(final LoggerContext context) {
         System.err.println("Initializing logger");
-        Logger logger = null;
-        try {
-            logger = context.getLogger();
-        } catch (final NullPointerException e) {
-            fail("Unexpected exception; should not occur until first logging statement " + e.getMessage());
-        }
-
-        final String message = "Log #1";
-        try {
-            logger.error(message);
-            fail("Expected exception not thrown");
-        } catch (final AppenderLoggingException e) {
-            //System.err.println("Expected exception here, but already errored out when initializing logger");
-        }
+        Logger logger = assertDoesNotThrow(() -> context.getLogger(getClass().getName()));
+        assertThrows(AppenderLoggingException.class, () -> logger.error("Log #1"));
     }
 
     private static class TestSocketServer implements Callable<InputStream> {
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/EnvironmentPasswordProviderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/EnvironmentPasswordProviderTest.java
index a9b266f..61afab6 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/EnvironmentPasswordProviderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/EnvironmentPasswordProviderTest.java
@@ -15,15 +15,15 @@ package org.apache.logging.log4j.core.net.ssl;/*
  * limitations under the license.
  */
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 public class EnvironmentPasswordProviderTest {
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testConstructorDisallowsNull() {
-        new EnvironmentPasswordProvider(null);
+        assertThrows(NullPointerException.class, () -> new EnvironmentPasswordProvider(null));
     }
 
     @Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/FilePasswordProviderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/FilePasswordProviderTest.java
index 13ca8a4..cfe03cc 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/FilePasswordProviderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/FilePasswordProviderTest.java
@@ -19,9 +19,10 @@ import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;
-import org.junit.Test;
 
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
 
 public class FilePasswordProviderTest {
 
@@ -36,13 +37,13 @@ public class FilePasswordProviderTest {
         assertArrayEquals(PASSWORD.toCharArray(), actual);
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testConstructorDisallowsNull() throws Exception {
-        new FilePasswordProvider(null);
+        assertThrows(NullPointerException.class, () -> new FilePasswordProvider(null));
     }
 
-    @Test(expected = NoSuchFileException.class)
+    @Test
     public void testConstructorFailsIfFileDoesNotExist() throws Exception {
-        new FilePasswordProvider("nosuchfile");
+        assertThrows(NoSuchFileException.class, () -> new FilePasswordProvider("nosuchfile"));
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationTest.java
index d5761ac..cb76930 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationTest.java
@@ -16,31 +16,33 @@
  */
 package org.apache.logging.log4j.core.net.ssl;
 
+import org.junit.jupiter.api.Test;
+
 import java.security.KeyStore;
 
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
 
 public class KeyStoreConfigurationTest {
-    @Test(expected = StoreConfigurationException.class)
-    public void loadEmptyConfigurationDeprecated() throws StoreConfigurationException {
-        final KeyStoreConfiguration ksc = new KeyStoreConfiguration(null, TestConstants.NULL_PWD, null, null);
-        final KeyStore ks = ksc.getKeyStore();
-        Assert.assertTrue(ks == null);
+    @SuppressWarnings("deprecation")
+    @Test
+    public void loadEmptyConfigurationDeprecated() {
+        assertThrows(StoreConfigurationException.class,
+                () -> new KeyStoreConfiguration(null, TestConstants.NULL_PWD, null, null));
     }
-    @Test(expected = StoreConfigurationException.class)
-    public void loadEmptyConfiguration() throws StoreConfigurationException {
-        final KeyStoreConfiguration ksc = new KeyStoreConfiguration(null, new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null);
-        final KeyStore ks = ksc.getKeyStore();
-        Assert.assertTrue(ks == null);
+
+    @Test
+    public void loadEmptyConfiguration() {
+        assertThrows(StoreConfigurationException.class,
+                () -> new KeyStoreConfiguration(null, new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null));
     }
 
     @Test
     public void loadNotEmptyConfigurationDeprecated() throws StoreConfigurationException {
-        final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD(),
-                TestConstants.KEYSTORE_TYPE, null);
+        @SuppressWarnings("deprecation") final KeyStoreConfiguration ksc =
+                new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD(),
+                        TestConstants.KEYSTORE_TYPE, null);
         final KeyStore ks = ksc.getKeyStore();
-        Assert.assertTrue(ks != null);
+        assertNotNull(ks);
     }
 
     @Test
@@ -48,16 +50,17 @@ public class KeyStoreConfigurationTest {
         final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, new MemoryPasswordProvider(TestConstants.KEYSTORE_PWD()),
                 TestConstants.KEYSTORE_TYPE, null);
         final KeyStore ks = ksc.getKeyStore();
-        Assert.assertTrue(ks != null);
+        assertNotNull(ks);
     }
 
     @Test
     public void returnTheSameKeyStoreAfterMultipleLoadsDeprecated() throws StoreConfigurationException {
-        final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD(),
-                TestConstants.KEYSTORE_TYPE, null);
+        @SuppressWarnings("deprecation") final KeyStoreConfiguration ksc =
+                new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD(),
+                        TestConstants.KEYSTORE_TYPE, null);
         final KeyStore ks = ksc.getKeyStore();
         final KeyStore ks2 = ksc.getKeyStore();
-        Assert.assertTrue(ks == ks2);
+        assertSame(ks, ks2);
     }
 
     @Test
@@ -66,18 +69,19 @@ public class KeyStoreConfigurationTest {
                 TestConstants.KEYSTORE_TYPE, null);
         final KeyStore ks = ksc.getKeyStore();
         final KeyStore ks2 = ksc.getKeyStore();
-        Assert.assertTrue(ks == ks2);
+        assertSame(ks, ks2);
     }
 
-    @Test(expected = StoreConfigurationException.class)
-    public void wrongPasswordDeprecated() throws StoreConfigurationException {
-        final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, "wrongPassword!", null, null);
-        ksc.getKeyStore();
+    @SuppressWarnings("deprecation")
+    @Test
+    public void wrongPasswordDeprecated() {
+        assertThrows(StoreConfigurationException.class,
+                () -> new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, "wrongPassword!", null, null));
     }
 
-    @Test(expected = StoreConfigurationException.class)
-    public void wrongPassword() throws StoreConfigurationException {
-        final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, new MemoryPasswordProvider("wrongPassword!".toCharArray()), null, null);
-        ksc.getKeyStore();
+    @Test
+    public void wrongPassword() {
+        assertThrows(StoreConfigurationException.class, () -> new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE,
+                new MemoryPasswordProvider("wrongPassword!".toCharArray()), null, null));
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/MemoryPasswordProviderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/MemoryPasswordProviderTest.java
index 99b3097..be9d27c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/MemoryPasswordProviderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/MemoryPasswordProviderTest.java
@@ -17,14 +17,14 @@ package org.apache.logging.log4j.core.net.ssl;/*
 
 import java.util.Arrays;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
 public class MemoryPasswordProviderTest {
     @Test
     public void testConstructorAllowsNull() {
-        assertEquals(null, new MemoryPasswordProvider(null).getPassword());
+        assertNull(new MemoryPasswordProvider(null).getPassword());
     }
 
     @Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java
index 41349a0..091f08c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java
@@ -23,14 +23,16 @@ import java.net.UnknownHostException;
 import javax.net.ssl.SSLSocket;
 import javax.net.ssl.SSLSocketFactory;
 
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
 
 public class SslConfigurationTest {
 
     private static final String TLS_TEST_HOST = "login.yahoo.com";
     private static final int TLS_TEST_PORT = 443;
 
+    @SuppressWarnings("deprecation")
     public static SslConfiguration createTestSslConfigurationResourcesDeprecated() throws StoreConfigurationException {
         final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE_RESOURCE,
                 TestConstants.KEYSTORE_PWD(), TestConstants.KEYSTORE_TYPE, null);
@@ -47,6 +49,7 @@ public class SslConfigurationTest {
         return SslConfiguration.createSSLConfiguration(null, ksc, tsc);
     }
 
+    @SuppressWarnings("deprecation")
     public static SslConfiguration createTestSslConfigurationFilesDeprecated() throws StoreConfigurationException {
         final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE,
                 TestConstants.KEYSTORE_PWD(), TestConstants.KEYSTORE_TYPE, null);
@@ -65,32 +68,32 @@ public class SslConfigurationTest {
 
     @Test
     public void testGettersFromScratchFiles() throws StoreConfigurationException {
-        Assert.assertNotNull(createTestSslConfigurationFiles().getProtocol());
-        Assert.assertNotNull(createTestSslConfigurationFiles().getKeyStoreConfig());
-        Assert.assertNotNull(createTestSslConfigurationFiles().getSslContext());
-        Assert.assertNotNull(createTestSslConfigurationFiles().getSslSocketFactory());
-        Assert.assertNotNull(createTestSslConfigurationFiles().getTrustStoreConfig());
+        assertNotNull(createTestSslConfigurationFiles().getProtocol());
+        assertNotNull(createTestSslConfigurationFiles().getKeyStoreConfig());
+        assertNotNull(createTestSslConfigurationFiles().getSslContext());
+        assertNotNull(createTestSslConfigurationFiles().getSslSocketFactory());
+        assertNotNull(createTestSslConfigurationFiles().getTrustStoreConfig());
     }
 
     @Test
     public void testGettersFromScratchResources() throws StoreConfigurationException {
-        Assert.assertNotNull(createTestSslConfigurationResources().getProtocol());
-        Assert.assertNotNull(createTestSslConfigurationResources().getKeyStoreConfig());
-        Assert.assertNotNull(createTestSslConfigurationResources().getSslContext());
-        Assert.assertNotNull(createTestSslConfigurationResources().getSslSocketFactory());
-        Assert.assertNotNull(createTestSslConfigurationResources().getTrustStoreConfig());
+        assertNotNull(createTestSslConfigurationResources().getProtocol());
+        assertNotNull(createTestSslConfigurationResources().getKeyStoreConfig());
+        assertNotNull(createTestSslConfigurationResources().getSslContext());
+        assertNotNull(createTestSslConfigurationResources().getSslSocketFactory());
+        assertNotNull(createTestSslConfigurationResources().getTrustStoreConfig());
     }
 
     @Test
     public void equals() {
-        Assert.assertEquals(SslConfiguration.createSSLConfiguration(null, null, null), SslConfiguration.createSSLConfiguration(null, null, null));
+        assertEquals(SslConfiguration.createSSLConfiguration(null, null, null), SslConfiguration.createSSLConfiguration(null, null, null));
     }
 
     @Test
         public void emptyConfigurationDoesntCauseNullSSLSocketFactory() {
         final SslConfiguration sc = SslConfiguration.createSSLConfiguration(null, null, null);
         final SSLSocketFactory factory = sc.getSslSocketFactory();
-        Assert.assertNotNull(factory);
+        assertNotNull(factory);
     }
 
     @Test
@@ -99,8 +102,7 @@ public class SslConfigurationTest {
         final SSLSocketFactory factory = sc.getSslSocketFactory();
         try {
             try (final SSLSocket clientSocket = (SSLSocket) factory.createSocket(TLS_TEST_HOST, TLS_TEST_PORT)) {
-                Assert.assertNotNull(clientSocket);
-                clientSocket.close();
+                assertNotNull(clientSocket);
             }
         } catch (final UnknownHostException offline) {
             // this exception is thrown on Windows when offline
@@ -116,10 +118,7 @@ public class SslConfigurationTest {
         try {
             try (final SSLSocket clientSocket = (SSLSocket) factory.createSocket(TLS_TEST_HOST, TLS_TEST_PORT)) {
                 try (final OutputStream os = clientSocket.getOutputStream()) {
-                    os.write("GET config/login_verify2?".getBytes());
-                    Assert.fail("Expected IOException");
-                } catch (final IOException e) {
-                    // Expected, do nothing.
+                    assertThrows(IOException.class, () -> os.write("GET config/login_verify2?".getBytes()));
                 }
             }
         } catch (final UnknownHostException offline) {
@@ -133,6 +132,6 @@ public class SslConfigurationTest {
                 new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null);
         final SslConfiguration sslConf = SslConfiguration.createSSLConfiguration(null, ksc, null);
         final SSLSocketFactory factory = sslConf.getSslSocketFactory();
-        Assert.assertNotNull(factory);
+        assertNotNull(factory);
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationTest.java
index 2224ab6..cf73ea4 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationTest.java
@@ -16,12 +16,12 @@
  */
 package org.apache.logging.log4j.core.net.ssl;
 
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
 
-@Ignore
+@Disabled
 public class StoreConfigurationTest<T extends StoreConfiguration<?>> {
 
     @Test
@@ -31,8 +31,8 @@ public class StoreConfigurationTest<T extends StoreConfiguration<?>> {
         final StoreConfiguration<Object> a = new StoreConfiguration<>(location, password);
         final StoreConfiguration<Object> b = new StoreConfiguration<>(location, password);
 
-        assertTrue(a.equals(b));
-        assertTrue(b.equals(a));
+        assertEquals(b, a);
+        assertEquals(a, b);
     }
 
     @Test
@@ -51,7 +51,7 @@ public class StoreConfigurationTest<T extends StoreConfiguration<?>> {
         final StoreConfiguration<Object> a = new StoreConfiguration<>(null, new MemoryPasswordProvider(null));
         final StoreConfiguration<Object> b = new StoreConfiguration<>(null, new MemoryPasswordProvider(null));
 
-        assertTrue(a.equals(b));
-        assertTrue(b.equals(a));
+        assertEquals(b, a);
+        assertEquals(a, b);
     }
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationTest.java
index d27a1fd..e5777a4 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationTest.java
@@ -16,45 +16,46 @@
  */
 package org.apache.logging.log4j.core.net.ssl;
 
+import org.junit.jupiter.api.Test;
+
 import java.security.KeyStore;
 
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
 
 public class TrustStoreConfigurationTest {
-    @Test(expected = StoreConfigurationException.class)
-    public void loadEmptyConfigurationDeprecated() throws StoreConfigurationException {
-        final TrustStoreConfiguration ksc = new TrustStoreConfiguration(null, TestConstants.NULL_PWD, null, null);
-        final KeyStore ks = ksc.getKeyStore();
-        Assert.assertTrue(ks == null);
+    @SuppressWarnings("deprecation")
+    @Test
+    public void loadEmptyConfigurationDeprecated() {
+        assertThrows(StoreConfigurationException.class, () -> new TrustStoreConfiguration(null, TestConstants.NULL_PWD, null, null));
     }
-    @Test(expected = StoreConfigurationException.class)
-    public void loadEmptyConfiguration() throws StoreConfigurationException {
-        final TrustStoreConfiguration ksc = new TrustStoreConfiguration(null, new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null);
-        final KeyStore ks = ksc.getKeyStore();
-        Assert.assertTrue(ks == null);
+
+    @Test
+    public void loadEmptyConfiguration() {
+        assertThrows(StoreConfigurationException.class, () -> new TrustStoreConfiguration(null, new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null));
     }
 
     @Test
     public void loadConfigurationDeprecated() throws StoreConfigurationException {
-        final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD(), null, null);
+        @SuppressWarnings("deprecation") final TrustStoreConfiguration ksc =
+                new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD(), null, null);
         final KeyStore ks = ksc.getKeyStore();
-        Assert.assertNotNull(ks);
+        assertNotNull(ks);
     }
 
     @Test
     public void loadConfiguration() throws StoreConfigurationException {
         final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, new MemoryPasswordProvider(TestConstants.TRUSTSTORE_PWD()), null, null);
         final KeyStore ks = ksc.getKeyStore();
-        Assert.assertNotNull(ks);
+        assertNotNull(ks);
     }
 
     @Test
     public void returnTheSameKeyStoreAfterMultipleLoadsDeprecated() throws StoreConfigurationException {
-        final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD(), null, null);
+        @SuppressWarnings("deprecation") final TrustStoreConfiguration ksc =
+                new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD(), null, null);
         final KeyStore ks = ksc.getKeyStore();
         final KeyStore ks2 = ksc.getKeyStore();
-        Assert.assertTrue(ks == ks2);
+        assertSame(ks, ks2);
     }
 
     @Test
@@ -62,20 +63,17 @@ public class TrustStoreConfigurationTest {
         final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, new MemoryPasswordProvider(TestConstants.TRUSTSTORE_PWD()), null, null);
         final KeyStore ks = ksc.getKeyStore();
         final KeyStore ks2 = ksc.getKeyStore();
-        Assert.assertTrue(ks == ks2);
+        assertSame(ks, ks2);
     }
 
-    @Test(expected = StoreConfigurationException.class)
-    public void wrongPasswordDeprecated() throws StoreConfigurationException {
-        final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, "wrongPassword!".toCharArray(), null, null);
-        ksc.getKeyStore();
-        Assert.assertTrue(false);
+    @SuppressWarnings("deprecation")
+    @Test
+    public void wrongPasswordDeprecated() {
+        assertThrows(StoreConfigurationException.class, () -> new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, "wrongPassword!".toCharArray(), null, null));
     }
 
-    @Test(expected = StoreConfigurationException.class)
-    public void wrongPassword() throws StoreConfigurationException {
-        final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, new MemoryPasswordProvider("wrongPassword!".toCharArray()), null, null);
-        ksc.getKeyStore();
-        Assert.assertTrue(false);
+    @Test
+    public void wrongPassword() {
+        assertThrows(StoreConfigurationException.class, () -> new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, new MemoryPasswordProvider("wrongPassword!".toCharArray()), null, null));
     }
 }
diff --git a/pom.xml b/pom.xml
index 9e5247c..a4fb263 100644
--- a/pom.xml
+++ b/pom.xml
@@ -736,6 +736,12 @@
         <scope>test</scope>
       </dependency>
       <dependency>
+        <groupId>org.mockito</groupId>
+        <artifactId>mockito-junit-jupiter</artifactId>
+        <version>${mockitoVersion}</version>
+        <scope>test</scope>
+      </dependency>
+      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-aop</artifactId>
         <version>${springVersion}</version>