Repository: logging-log4j2
Updated Branches:
  refs/heads/master 38cc8121b -> 924bcafab


Add test to verify logging an exception with parameters works


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

Branch: refs/heads/master
Commit: 924bcafabe4a4385e00a0ae0f8e25024b1841729
Parents: 38cc812
Author: Ralph Goers <[email protected]>
Authored: Sun Feb 7 15:32:43 2016 -0700
Committer: Ralph Goers <[email protected]>
Committed: Sun Feb 7 15:32:43 2016 -0700

----------------------------------------------------------------------
 .../apache/logging/log4j/core/LoggerTest.java   | 23 +++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/924bcafa/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
----------------------------------------------------------------------
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 8e48ea2..0574099 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
@@ -37,7 +37,9 @@ import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.Configurator;
 import org.apache.logging.log4j.core.config.LoggerConfig;
 import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.MessageFactory;
+import org.apache.logging.log4j.message.ParameterizedMessage;
 import org.apache.logging.log4j.message.ParameterizedMessageFactory;
 import org.apache.logging.log4j.message.StringFormatterMessageFactory;
 import org.apache.logging.log4j.message.StructuredDataMessage;
@@ -54,9 +56,9 @@ import org.junit.rules.TestName;
 public class LoggerTest {
 
     private static final String CONFIG = "log4j-test2.xml";
-    
+
     @Rule
-    public final TestName testName = new TestName(); 
+    public final TestName testName = new TestName();
     private ListAppender app;
     private ListAppender host;
     private ListAppender noThrown;
@@ -67,7 +69,7 @@ public class LoggerTest {
     private void assertEventCount(final List<LogEvent> events, final int 
expected) {
         assertEquals("Incorrect number of events.", expected, events.size());
     }
-    
+
     @Before
     public void before() {
         logger = context.getLogger("LoggerTest");
@@ -393,5 +395,20 @@ public class LoggerTest {
         final Logger localLogger = 
context.getLogger("org.apache.logging.log4j.core.LoggerTest");
         assertTrue("Incorrect level - expected DEBUG, actual " + 
localLogger.getLevel(), localLogger.getLevel() == Level.DEBUG);
     }
+
+    @Test
+    public void paramWithExceptionTest() throws Exception {
+        logger.error("Throwing with parameters {}", "TestParam", new 
NullPointerException("Test Exception"));
+        List<LogEvent> events = app.getEvents();
+        assertNotNull("Log event list not returned", events);
+        assertTrue("Incorrect number of log events: expected 1, actual " + 
events.size(), events.size() == 1);
+        LogEvent event = events.get(0);
+        Throwable thrown = event.getThrown();
+        assertNotNull("No throwable present in log event", thrown);
+        Message msg = event.getMessage();
+        assertTrue("Incorrect message type. Expected ParameterizedMessage, 
actual " + msg.getClass().getSimpleName(),
+                msg instanceof ParameterizedMessage);
+
+    }
 }
 

Reply via email to