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 2014/10/04 20:27:52 UTC

[2/3] git commit: Use ILC in test.

Use ILC in test.


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

Branch: refs/heads/master
Commit: b7206d0521b6076d07646932f426435e104319b2
Parents: b171c5d
Author: Matt Sicker <ma...@apache.org>
Authored: Sat Oct 4 13:27:30 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sat Oct 4 13:27:30 2014 -0500

----------------------------------------------------------------------
 log4j-to-slf4j/pom.xml                          |  5 ++
 .../org/apache/logging/slf4j/LoggerTest.java    | 55 +++++++-------------
 2 files changed, 25 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b7206d05/log4j-to-slf4j/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-to-slf4j/pom.xml b/log4j-to-slf4j/pom.xml
index 369c7b6..ed63f40 100644
--- a/log4j-to-slf4j/pom.xml
+++ b/log4j-to-slf4j/pom.xml
@@ -62,6 +62,11 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>hamcrest-all</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b7206d05/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java b/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
index d6f39da..8cb77df 100644
--- a/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
+++ b/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
@@ -20,6 +20,8 @@ package org.apache.logging.slf4j;
 import java.util.Date;
 import java.util.List;
 
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.testUtil.StringListAppender;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.ThreadContext;
@@ -27,16 +29,12 @@ import org.apache.logging.log4j.message.MessageFactory;
 import org.apache.logging.log4j.message.ParameterizedMessageFactory;
 import org.apache.logging.log4j.message.StringFormatterMessageFactory;
 import org.junit.Before;
-import org.junit.BeforeClass;
+import org.junit.ClassRule;
 import org.junit.Test;
-import org.slf4j.LoggerFactory;
-
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.joran.JoranConfigurator;
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.joran.spi.JoranException;
-import ch.qos.logback.core.testUtil.StringListAppender;
 
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.theInstance;
 import static org.junit.Assert.*;
 
 /**
@@ -45,36 +43,23 @@ import static org.junit.Assert.*;
 public class LoggerTest {
 
     private static final String CONFIG = "target/test-classes/logback-slf4j.xml";
-    private static Logger logger;
-    private static org.slf4j.Logger slf4jLogger;
-    private static LoggerContext context;
-    private static Logger root;
-    private static ch.qos.logback.classic.Logger rootLogger;
-    private static StringListAppender<ILoggingEvent> list;
-
-    @BeforeClass
-    public static void setupClass() throws Exception {
-        slf4jLogger = LoggerFactory.getLogger(LoggerTest.class);
-        context = ((ch.qos.logback.classic.Logger) slf4jLogger).getLoggerContext();
-        configure(CONFIG);
-        logger = LogManager.getLogger(LoggerTest.class);
-        assertTrue("Incorrect SLF4J Logger", ((SLF4JLogger) logger).getLogger() == slf4jLogger);
-        root = LogManager.getRootLogger();
-        rootLogger = context.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
-        list = (StringListAppender<ILoggingEvent>) rootLogger.getAppender("LIST");
-        rootLogger.detachAppender("console");
-    }
 
-    private static void configure(final String file) throws JoranException {
-        final JoranConfigurator jc = new JoranConfigurator();
-        jc.setContext(context);
-        jc.doConfigure(file);
-    }
+    @ClassRule
+    public static final InitialLoggerContext CTX = new InitialLoggerContext(CONFIG);
+
+    private Logger logger;
+    private StringListAppender<ILoggingEvent> list;
 
     @Before
-    public void before() {
-    	assertNotNull(list);
-    	assertNotNull(list.strList);
+    public void setUp() throws Exception {
+        final org.slf4j.Logger slf4jLogger = CTX.getLogger();
+        logger = LogManager.getLogger();
+        assertThat(slf4jLogger, is(theInstance(((SLF4JLogger) logger).getLogger())));
+        final ch.qos.logback.classic.Logger rootLogger = CTX.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
+        rootLogger.detachAppender("console");
+        list = TestUtil.getListAppender(rootLogger, "LIST");
+        assertThat(list, is(notNullValue()));
+        assertThat(list.strList, is(notNullValue()));
         list.strList.clear();
     }