Use a ThreadContextRule to clean up tests.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c29ce4bb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c29ce4bb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c29ce4bb

Branch: 
refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: c29ce4bb92cea8350ba397d8b1c2a6dda557dcdb
Parents: 5ae77a9
Author: Gary Gregory <ggreg...@apache.org>
Authored: Mon Aug 15 13:27:14 2016 -0700
Committer: Gary Gregory <ggreg...@apache.org>
Committed: Mon Aug 15 13:27:14 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/pattern/MdcPatternConverterTest.java   | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c29ce4bb/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
----------------------------------------------------------------------
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 c96f200..caa130d 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
@@ -16,23 +16,29 @@
  */
 package org.apache.logging.log4j.core.pattern;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.junit.ThreadContextMapRule;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
-
 /**
  *
  */
 public class MdcPatternConverterTest {
 
+    @Rule
+    public final ThreadContextMapRule threadContextRule = new 
ThreadContextMapRule(); 
+
     @Before
     public void setup() {
         ThreadContext.put("subject", "I");
@@ -90,9 +96,5 @@ public class MdcPatternConverterTest {
         assertEquals(expected, str);
     }
 
-    @After
-    public void tearDown() {
-        ThreadContext.clearMap();
-    }
 }
 

Reply via email to