logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject svn commit: r1582160 - /logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowableTest.java
Date Thu, 27 Mar 2014 02:49:52 GMT
Author: mattsicker
Date: Thu Mar 27 02:49:52 2014
New Revision: 1582160

URL: http://svn.apache.org/r1582160
Log:
Updated to use InitialLoggerContext rule.

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowableTest.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowableTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowableTest.java?rev=1582160&r1=1582159&r2=1582160&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowableTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowableTest.java
Thu Mar 27 02:49:52 2014
@@ -16,63 +16,45 @@
  */
 package org.apache.logging.log4j.core.pattern;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.List;
-import java.util.Map;
 
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
 import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.*;
 
 /**
  *
  */
 public class ExtendedThrowableTest {
-    private static final String CONFIG = "log4j-throwablefilter.xml";
-    private static Configuration config;
-    private static ListAppender app;
-    private static LoggerContext ctx;
-
-    @BeforeClass
-    public static void setupClass() {
-        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
-        ctx = (LoggerContext) LogManager.getContext(false);
-        config = ctx.getConfiguration();
-        for (final Map.Entry<String, Appender> entry : config.getAppenders().entrySet())
{
-            if (entry.getKey().equals("List")) {
-                app = (ListAppender) entry.getValue();
-                break;
-            }
-        }
-    }
+    private ListAppender app;
+
+    @Rule
+    public InitialLoggerContext init = new InitialLoggerContext("log4j-throwablefilter.xml");
 
-    @AfterClass
-    public static void cleanupClass() {
-        System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
-        ctx.reconfigure();
-        StatusLogger.getLogger().reset();
+    @Before
+    public void setUp() throws Exception {
+        this.app = (ListAppender) this.init.getContext().getConfiguration().getAppenders().get("List");
     }
 
-    org.apache.logging.log4j.Logger logger = LogManager.getLogger("LoggerTest");
+    @After
+    public void tearDown() throws Exception {
+        this.app.clear();
+    }
 
     @Test
     public void testException() {
+        final Logger logger = this.init.getContext().getLogger("LoggerTest");
         final Throwable cause = new NullPointerException("null pointer");
         final Throwable parent = new IllegalArgumentException("IllegalArgument", cause);
         logger.error("Exception", parent);
         final List<String> msgs = app.getMessages();
         assertNotNull(msgs);
-        assertTrue("Incorrect number of messages. Should be 1 is " + msgs.size(), msgs.size()
== 1);
+        assertEquals("Incorrect number of messages. Should be 1 is " + msgs.size(), msgs.size(),
1);
         assertTrue("No suppressed lines", msgs.get(0).contains("suppressed"));
-        app.clear();
     }
 }



Mime
View raw message