You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2014/11/18 01:49:13 UTC

logging-log4j2 git commit: Bullet-proof testing with TestLogEventFactory.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master de9836486 -> c91c57c81


Bullet-proof testing with TestLogEventFactory.


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

Branch: refs/heads/master
Commit: c91c57c81c8956d46259d29c9190a171048e4cca
Parents: de98364
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Nov 17 19:49:08 2014 -0500
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Nov 17 19:49:08 2014 -0500

----------------------------------------------------------------------
 .../logging/log4j/core/LogEventFactoryTest.java    | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c91c57c8/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventFactoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventFactoryTest.java
index 10f143b..e5a025c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventFactoryTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventFactoryTest.java
@@ -16,11 +16,18 @@
  */
 package org.apache.logging.log4j.core;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.lang.reflect.Field;
 import java.util.List;
 
+import org.apache.commons.lang3.reflect.FieldUtils;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.core.config.LoggerConfig;
 import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.impl.DefaultLogEventFactory;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.impl.LogEventFactory;
 import org.apache.logging.log4j.core.util.Constants;
@@ -35,8 +42,6 @@ import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
-import static org.junit.Assert.*;
-
 /**
  *
  */
@@ -56,12 +61,20 @@ public class LogEventFactoryTest {
                 @Override
                 public void evaluate() throws Throwable {
                     System.setProperty(Constants.LOG4J_LOG_EVENT_FACTORY, TestLogEventFactory.class.getName());
+                    resetLogEventFactory(new TestLogEventFactory());
                     try {
                         base.evaluate();
                     } finally {
                         System.clearProperty(Constants.LOG4J_LOG_EVENT_FACTORY);
+                        resetLogEventFactory(new DefaultLogEventFactory());
                     }
                 }
+
+                private void resetLogEventFactory(LogEventFactory logEventFactory) throws IllegalAccessException {
+                    Field field = FieldUtils.getField(LoggerConfig.class, "LOG_EVENT_FACTORY", true);
+                    FieldUtils.removeFinalModifier(field, true);
+                    FieldUtils.writeStaticField(field, logEventFactory, false);
+                }
             };
         }
     }).around(context);