Author: psmith Date: Wed Jun 20 14:26:06 2007 New Revision: 549242 URL: http://svn.apache.org/viewvc?view=rev&rev=549242 Log: Fix for test cases breaking under Maven AND Eclipse.
Turns out that a failing test works fine by itself but not in conjunction with the other tests running because an Filter is left configured in the JUL system, DESPITE it's LogManager.reset() being called. One has to manually remove all the registered filters even if calling reset(). That's not much of a reset() method if you ask me. The fix makes sure that each unit test tears down the JUL configuration correctly before the next test case runs. Modified: logging/sandbox/jul-to-log4j-bridge/pom.xml logging/sandbox/jul-to-log4j-bridge/src/main/java/org/apache/logging/julbridge/JULLog4jBridge.java logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULReceiverTest.java logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/logging/julbridge/TestLogPosting.java Modified: logging/sandbox/jul-to-log4j-bridge/pom.xml URL: http://svn.apache.org/viewvc/logging/sandbox/jul-to-log4j-bridge/pom.xml?view=diff&rev=549242&r1=549241&r2=549242 ============================================================================== --- logging/sandbox/jul-to-log4j-bridge/pom.xml (original) +++ logging/sandbox/jul-to-log4j-bridge/pom.xml Wed Jun 20 14:26:06 2007 @@ -146,11 +146,6 @@ <groupId>org.codehaus.mojo</groupId> <artifactId>jxr-maven-plugin</artifactId> </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>cobertura-maven-plugin</artifactId> - <version>2.0</version> - </plugin> <plugin> <artifactId>maven-changes-plugin</artifactId> <configuration> Modified: logging/sandbox/jul-to-log4j-bridge/src/main/java/org/apache/logging/julbridge/JULLog4jBridge.java URL: http://svn.apache.org/viewvc/logging/sandbox/jul-to-log4j-bridge/src/main/java/org/apache/logging/julbridge/JULLog4jBridge.java?view=diff&rev=549242&r1=549241&r2=549242 ============================================================================== --- logging/sandbox/jul-to-log4j-bridge/src/main/java/org/apache/logging/julbridge/JULLog4jBridge.java (original) +++ logging/sandbox/jul-to-log4j-bridge/src/main/java/org/apache/logging/julbridge/JULLog4jBridge.java Wed Jun 20 14:26:06 2007 @@ -10,6 +10,7 @@ */ package org.apache.logging.julbridge; +import java.util.Enumeration; import java.util.logging.Filter; import java.util.logging.Level; @@ -119,10 +120,16 @@ /** * Reverse of [EMAIL PROTECTED] #assimilate()}, disconnects the bridge * from the java.util.logging subsystem by resetting that framework - * back to it's default configuration. + * back to it's default configuration (removes all Handlers and Filters) */ public static void repatriate() { - java.util.logging.LogManager.getLogManager().reset(); + + java.util.logging.LogManager logManager = java.util.logging.LogManager.getLogManager(); + Enumeration loggerNames = logManager.getLoggerNames(); + while(loggerNames.hasMoreElements()) { + logManager.getLogger(loggerNames.nextElement().toString()).setFilter(null); + } + logManager.reset(); } Modified: logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULReceiverTest.java URL: http://svn.apache.org/viewvc/logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULReceiverTest.java?view=diff&rev=549242&r1=549241&r2=549242 ============================================================================== --- logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULReceiverTest.java (original) +++ logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULReceiverTest.java Wed Jun 20 14:26:06 2007 @@ -20,6 +20,8 @@ import java.util.Iterator; import java.util.List; +import junit.framework.TestCase; + import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.LoggerRepositoryExImpl; @@ -27,10 +29,9 @@ import org.apache.log4j.spi.LoggerRepository; import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.spi.RepositorySelector; +import org.apache.logging.julbridge.JULLog4jBridge; import org.apache.logging.julbridge.MockAppender; -import junit.framework.TestCase; - public class JULReceiverTest extends TestCase { private final Object repositorySelectorGuard = new Object(); @@ -40,6 +41,7 @@ protected void setUp() throws Exception { super.setUp(); + java.util.logging.LogManager.getLogManager().reset(); mockAppender = new MockAppender(); LogManager.resetConfiguration(); LogManager.setRepositorySelector(new RepositorySelector() { @@ -52,6 +54,7 @@ protected void tearDown() throws Exception { super.tearDown(); + JULLog4jBridge.repatriate(); } public void testJULReceiverPluginConfiguration() { Modified: logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/logging/julbridge/TestLogPosting.java URL: http://svn.apache.org/viewvc/logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/logging/julbridge/TestLogPosting.java?view=diff&rev=549242&r1=549241&r2=549242 ============================================================================== --- logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/logging/julbridge/TestLogPosting.java (original) +++ logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/logging/julbridge/TestLogPosting.java Wed Jun 20 14:26:06 2007 @@ -55,5 +55,9 @@ } + public void tearDown() { + JULLog4jBridge.repatriate(); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]