diff --git a/integration/build.xml b/integration/build.xml index d60b1fa..bcb3db6 100644 --- a/integration/build.xml +++ b/integration/build.xml @@ -13,6 +13,10 @@ + + + + @@ -103,7 +107,8 @@ testMatch, testMultiBinding, testIncompatibleMultiBinding, - testFuture_16Series"> + testFuture_16Series, + testActiveSecurityManager"> @@ -197,4 +202,34 @@ + + + + + + + + setPathToPolicy_FromTop + + + + + setPathToPolicy_FromInegration + + + + + + + + + + + + + + + diff --git a/integration/pom.xml b/integration/pom.xml index 1970406..2998e50 100644 --- a/integration/pom.xml +++ b/integration/pom.xml @@ -1,16 +1,14 @@ - + + 4.0.0 org.slf4j slf4j-parent - 1.7.12 + 1.7.13 - integration jar @@ -37,7 +35,6 @@ ant-junit 1.6.5 - diff --git a/integration/src/main/resources/META-INF/MANIFEST.MF b/integration/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e69de29 diff --git a/integration/src/policy/java-eclipse.policy b/integration/src/policy/java-eclipse.policy new file mode 100644 index 0000000..f196c95 --- /dev/null +++ b/integration/src/policy/java-eclipse.policy @@ -0,0 +1,10 @@ + +grant { + + // note that java.lang.RuntimePermission createSecurityManager is NOT granted + + permission java.util.PropertyPermission "user.dir", "read"; + permission java.util.PropertyPermission "*", "read"; + + permission java.net.SocketPermission "*", "connect,resolve"; +}; \ No newline at end of file diff --git a/integration/src/policy/java-under-ant.policy b/integration/src/policy/java-under-ant.policy new file mode 100644 index 0000000..1077f96 --- /dev/null +++ b/integration/src/policy/java-under-ant.policy @@ -0,0 +1,13 @@ + +grant { + + // note that java.lang.RuntimePermission createSecurityManager is NOT granted + + permission java.util.PropertyPermission "user.dir", "read"; + + // permissions required for Ant's Junit runner + permission java.util.PropertyPermission "*", "read, write"; + permission java.io.FilePermission "./-", "read"; + permission java.io.FilePermission "./-", "write"; + permission java.lang.RuntimePermission "setIO"; +}; \ No newline at end of file diff --git a/integration/src/test/java/org/slf4j/issues/Issue324Test.java b/integration/src/test/java/org/slf4j/issues/Issue324Test.java new file mode 100644 index 0000000..3f3c319 --- /dev/null +++ b/integration/src/test/java/org/slf4j/issues/Issue324Test.java @@ -0,0 +1,17 @@ +package org.slf4j.issues; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import junit.framework.TestCase; + +public class Issue324Test extends TestCase { + + + public void testLoggerCreationInPresenseOfSecurityManager() { + String currentDir = System.getProperty("user.dir"); + System.out.println("currentDir:"+currentDir); + Logger logger = LoggerFactory.getLogger(Issue324Test.class); + logger.debug("hello"); + } +} diff --git a/jcl-over-slf4j/pom.xml b/jcl-over-slf4j/pom.xml index ea67fbd..e372332 100644 --- a/jcl-over-slf4j/pom.xml +++ b/jcl-over-slf4j/pom.xml @@ -1,10 +1,11 @@ + org.slf4j slf4j-parent - 1.7.12 + 1.7.13 4.0.0 @@ -15,51 +16,16 @@ JCL 1.1.1 implemented over SLF4J http://www.slf4j.org - - - org.slf4j slf4j-api - org.slf4j slf4j-jdk14 test - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - - - - diff --git a/jcl-over-slf4j/src/test/java/org/apache/commons/logging/InvokeJCLTest.java b/jcl-over-slf4j/src/test/java/org/apache/commons/logging/InvokeJCLTest.java index 2df5a6f..f75240a 100644 --- a/jcl-over-slf4j/src/test/java/org/apache/commons/logging/InvokeJCLTest.java +++ b/jcl-over-slf4j/src/test/java/org/apache/commons/logging/InvokeJCLTest.java @@ -25,10 +25,14 @@ package org.apache.commons.logging; -import junit.framework.TestCase; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -public class InvokeJCLTest extends TestCase { +import org.junit.Test; +public class InvokeJCLTest { + + @Test public void testIsEnabledAPI() { // assume that we are running over slf4j-jdk14 Log log = LogFactory.getLog(InvokeJCLTest.class); @@ -40,6 +44,7 @@ assertTrue(log.isFatalEnabled()); } + @Test public void testPrintAPI() { Log log = LogFactory.getLog(InvokeJCLTest.class); Exception e = new Exception("just testing"); diff --git a/jcl-over-slf4j/src/test/java/org/apache/commons/logging/impl/SerializationTest.java b/jcl-over-slf4j/src/test/java/org/apache/commons/logging/impl/SerializationTest.java index a0b8c67..d0e6a20 100644 --- a/jcl-over-slf4j/src/test/java/org/apache/commons/logging/impl/SerializationTest.java +++ b/jcl-over-slf4j/src/test/java/org/apache/commons/logging/impl/SerializationTest.java @@ -30,30 +30,27 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import junit.framework.TestCase; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.slf4j.impl.JDK14LoggerFactory; import org.slf4j.spi.LocationAwareLogger; -public class SerializationTest extends TestCase { +public class SerializationTest { ObjectInputStream ois; ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos; - public SerializationTest(String name) { - super(name); + @Before + public void setUp() throws Exception { + oos = new ObjectOutputStream(baos); } - protected void setUp() throws Exception { - oos = new ObjectOutputStream(baos); - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { oos.close(); } @@ -67,6 +64,7 @@ resuscitatedLog.isDebugEnabled(); } + @Test public void testSLF4JLog() throws Exception { JDK14LoggerFactory factory = new JDK14LoggerFactory(); SLF4JLog log = new SLF4JLog(factory.getLogger("x")); @@ -74,12 +72,14 @@ verify(); } + @Test public void testSmoke() throws Exception { Log log = LogFactory.getLog("testing"); oos.writeObject(log); verify(); } + @Test public void testLocationAware() throws Exception { JDK14LoggerFactory factory = new JDK14LoggerFactory(); SLF4JLocationAwareLog log = new SLF4JLocationAwareLog((LocationAwareLogger) factory.getLogger("x")); diff --git a/jul-to-slf4j/pom.xml b/jul-to-slf4j/pom.xml index 40e249f..dc4bfe2 100644 --- a/jul-to-slf4j/pom.xml +++ b/jul-to-slf4j/pom.xml @@ -1,14 +1,13 @@ - + + 4.0.0 org.slf4j slf4j-parent - 1.7.12 + 1.7.13 jul-to-slf4j @@ -32,33 +31,4 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${required.jdk.version} - ${required.jdk.version} - - - - org.apache.maven.plugins - maven-jar-plugin - - - - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - - diff --git a/jul-to-slf4j/src/main/java/org/slf4j/bridge/SLF4JBridgeHandler.java b/jul-to-slf4j/src/main/java/org/slf4j/bridge/SLF4JBridgeHandler.java index a21d635..fe62f19 100644 --- a/jul-to-slf4j/src/main/java/org/slf4j/bridge/SLF4JBridgeHandler.java +++ b/jul-to-slf4j/src/main/java/org/slf4j/bridge/SLF4JBridgeHandler.java @@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory; import org.slf4j.spi.LocationAwareLogger; -// Based on http://bugzilla.slf4j.org/show_bug.cgi?id=38 +// Based on http://jira.qos.ch/browse/SLF4J-30 /** *

Bridge/route all JUL log records to the SLF4J API.

@@ -259,9 +259,15 @@ } Object[] params = record.getParameters(); // avoid formatting when there are no or 0 parameters. see also - // http://bugzilla.slf4j.org/show_bug.cgi?id=212 + // http://jira.qos.ch/browse/SLF4J-203 if (params != null && params.length > 0) { - message = MessageFormat.format(message, params); + try { + message = MessageFormat.format(message, params); + } catch (IllegalArgumentException e) { + // default to the same behavior as in java.util.logging.Formatter.formatMessage(LogRecord) + // see also http://jira.qos.ch/browse/SLF4J-337 + return message; + } } return message; } @@ -289,7 +295,7 @@ // this is a check to avoid calling the underlying logging system // with a null message. While it is legitimate to invoke j.u.l. with // a null message, other logging frameworks do not support this. - // see also http://bugzilla.slf4j.org/show_bug.cgi?id=108 + // see also http://jira.qos.ch/browse/SLF4J-99 if (message == null) { message = ""; } diff --git a/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerPerfTest.java b/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerPerfTest.java index f647f0d..384d90e 100644 --- a/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerPerfTest.java +++ b/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerPerfTest.java @@ -27,13 +27,13 @@ import java.util.logging.Handler; import java.util.logging.LogManager; -import junit.framework.TestCase; - import org.apache.log4j.FileAppender; import org.apache.log4j.PatternLayout; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.slf4j.LoggerFactory; - -public class SLF4JBridgeHandlerPerfTest extends TestCase { +public class SLF4JBridgeHandlerPerfTest { static String LOGGER_NAME = "yay"; static int RUN_LENGTH = 100 * 1000; @@ -50,12 +50,9 @@ Handler[] existingHandlers; - public SLF4JBridgeHandlerPerfTest(String arg0) { - super(arg0); - } - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { fileAppender = new FileAppender(new PatternLayout("%r [%t] %p %c %x - %m%n"), "target/test-output/toto.log"); existingHandlers = julRootLogger.getHandlers(); @@ -66,8 +63,8 @@ log4jRoot.addAppender(fileAppender); } - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { SLF4JBridgeHandler.uninstall(); fileAppender.close(); log4jRoot.getLoggerRepository().resetConfiguration(); @@ -94,6 +91,7 @@ return (end - start) * 1.0 / RUN_LENGTH; } + @Test public void testPerf() { SLF4JBridgeHandler.install(); diff --git a/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerTest.java b/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerTest.java index 4e3b666..a30d685 100644 --- a/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerTest.java +++ b/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerTest.java @@ -24,16 +24,18 @@ */ package org.slf4j.bridge; +import static org.junit.Assert.assertEquals; + import java.text.MessageFormat; import java.util.ResourceBundle; import java.util.logging.Level; -import junit.framework.TestCase; - import org.apache.log4j.spi.LocationInfo; import org.apache.log4j.spi.LoggingEvent; - -public class SLF4JBridgeHandlerTest extends TestCase { +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +public class SLF4JBridgeHandlerTest { static String LOGGER_NAME = "yay"; @@ -41,24 +43,22 @@ org.apache.log4j.Logger log4jRoot; java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger("yay"); - public SLF4JBridgeHandlerTest(String arg0) { - super(arg0); - } - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { listAppender.extractLocationInfo = true; log4jRoot = org.apache.log4j.Logger.getRootLogger(); log4jRoot.addAppender(listAppender); log4jRoot.setLevel(org.apache.log4j.Level.TRACE); } - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { SLF4JBridgeHandler.uninstall(); log4jRoot.getLoggerRepository().resetConfiguration(); } + @Test public void testSmoke() { SLF4JBridgeHandler.install(); String msg = "msg"; @@ -78,6 +78,7 @@ assertEquals("testSmoke", li.getMethodName()); } + @Test public void testLevels() { SLF4JBridgeHandler.install(); String msg = "msg"; @@ -100,6 +101,7 @@ assertLevel(i++, org.apache.log4j.Level.ERROR); } + @Test public void testLogWithResourceBundle() { SLF4JBridgeHandler.install(); @@ -118,6 +120,7 @@ assertEquals(expectedMsg, le.getMessage()); } + @Test public void testLogWithResourceBundleWithParameters() { SLF4JBridgeHandler.install(); @@ -163,6 +166,7 @@ assertEquals(expectedMsg3, le.getMessage()); } + @Test public void testLogWithPlaceholderNoParameters() { SLF4JBridgeHandler.install(); String msg = "msg {non-number-string}"; @@ -174,6 +178,19 @@ assertEquals(msg, le.getMessage()); } + // See http://jira.qos.ch/browse/SLF4J-337 + + @Test + public void illFormattedInputShouldBeReturnedAsIs() { + SLF4JBridgeHandler.install(); + String msg = "foo {18=bad} {0}"; + + julLogger.log(Level.INFO, msg, "ignored parameter due to IllegalArgumentException"); + assertEquals(1, listAppender.list.size()); + LoggingEvent le = (LoggingEvent) listAppender.list.get(0); + assertEquals(msg, le.getMessage()); + } + void assertLevel(int index, org.apache.log4j.Level expectedLevel) { LoggingEvent le = (LoggingEvent) listAppender.list.get(index); assertEquals(expectedLevel, le.getLevel()); diff --git a/log4j-over-slf4j/pom.xml b/log4j-over-slf4j/pom.xml index c2edb77..a55e01b 100644 --- a/log4j-over-slf4j/pom.xml +++ b/log4j-over-slf4j/pom.xml @@ -1,5 +1,5 @@ - + 4.0.0 @@ -7,16 +7,16 @@ org.slf4j slf4j-parent - 1.7.12 + 1.7.13 - log4j-over-slf4j - jar - Log4j Implemented Over SLF4J + log4j-over-slf4j + jar + Log4j Implemented Over SLF4J Log4j implemented over SLF4J - http://www.slf4j.org + http://www.slf4j.org @@ -29,35 +29,12 @@ org.slf4j slf4j-api - - + org.slf4j slf4j-jdk14 test - + - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - - diff --git a/log4j-over-slf4j/src/main/java/org/apache/log4j/Appender.java b/log4j-over-slf4j/src/main/java/org/apache/log4j/Appender.java index cc6a164..d832a8f 100644 --- a/log4j-over-slf4j/src/main/java/org/apache/log4j/Appender.java +++ b/log4j-over-slf4j/src/main/java/org/apache/log4j/Appender.java @@ -18,7 +18,6 @@ import org.apache.log4j.spi.Filter; import org.apache.log4j.spi.ErrorHandler; -import org.apache.log4j.spi.Layout; import org.apache.log4j.spi.LoggingEvent; /** diff --git a/log4j-over-slf4j/src/main/java/org/apache/log4j/Category.java b/log4j-over-slf4j/src/main/java/org/apache/log4j/Category.java index b263d59..d785a83 100644 --- a/log4j-over-slf4j/src/main/java/org/apache/log4j/Category.java +++ b/log4j-over-slf4j/src/main/java/org/apache/log4j/Category.java @@ -291,7 +291,7 @@ log(FQCN, p, msg, t); } - // See also http://bugzilla.slf4j.org/show_bug.cgi?id=168 + // See also http://jira.qos.ch/browse/SLF4J-159 public void log(String FQCN, Priority p, Object msg, Throwable t) { int levelInt = priorityToLevelInt(p); differentiatedLog(null, FQCN, levelInt, msg, t); @@ -346,5 +346,14 @@ public void setLevel(Level level) { // nothing to do } + + public boolean getAdditivity() { + return false; + } + + public void assertLog(boolean assertion, String msg) { + if(!assertion) + error(msg); + } } diff --git a/log4j-over-slf4j/src/main/java/org/apache/log4j/LogManager.java b/log4j-over-slf4j/src/main/java/org/apache/log4j/LogManager.java index 2932ad8..9e8f41d 100644 --- a/log4j-over-slf4j/src/main/java/org/apache/log4j/LogManager.java +++ b/log4j-over-slf4j/src/main/java/org/apache/log4j/LogManager.java @@ -51,7 +51,7 @@ /** * Returns a logger instance created by loggerFactory. This method was requested in - * bug #234. Note that + * SLF4J-225. Note that * log4j-over-slf4j does not ship with a LoggerFactory implementation. If this * method is called, the caller must provide his/her own implementation. * diff --git a/log4j-over-slf4j/src/main/java/org/apache/log4j/spi/Layout.java b/log4j-over-slf4j/src/main/java/org/apache/log4j/spi/Layout.java deleted file mode 100644 index 5a87f47..0000000 --- a/log4j-over-slf4j/src/main/java/org/apache/log4j/spi/Layout.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.log4j.spi; - -public class Layout { -} diff --git a/log4j-over-slf4j/src/test/java/org/apache/log4j/NDCTest.java b/log4j-over-slf4j/src/test/java/org/apache/log4j/NDCTest.java index a9c1cc0..0df8847 100644 --- a/log4j-over-slf4j/src/test/java/org/apache/log4j/NDCTest.java +++ b/log4j-over-slf4j/src/test/java/org/apache/log4j/NDCTest.java @@ -24,33 +24,42 @@ */ package org.apache.log4j; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * @author Ceki Gücü */ -public class NDCTest extends TestCase { +public class NDCTest { + @Before public void setUp() { assertEquals(0, NDC.getDepth()); } + @After public void tearDown() { NDC.clear(); } + @Test public void testSmoke() { NDC.push("a"); String back = NDC.pop(); assertEquals("a", back); } + @Test public void testPop() { NDC.push("peek"); String back = NDC.peek(); assertEquals("peek", back); } + @Test public void testClear() { NDC.push("clear"); NDC.clear(); diff --git a/log4j-over-slf4j/src/test/java/org/dummy/Bug131.java b/log4j-over-slf4j/src/test/java/org/dummy/Bug131.java index 10b7a29..3479dbb 100644 --- a/log4j-over-slf4j/src/test/java/org/dummy/Bug131.java +++ b/log4j-over-slf4j/src/test/java/org/dummy/Bug131.java @@ -24,16 +24,17 @@ */ package org.dummy; +import static org.junit.Assert.assertEquals; + import java.util.logging.Level; import java.util.logging.LogRecord; -import junit.framework.TestCase; - import org.apache.log4j.Category; import org.apache.log4j.Logger; +import org.junit.Test; +public class Bug131 { -public class Bug131 extends TestCase { - + @Test public void testBug131() { ListHandler listHandler = new ListHandler(); diff --git a/log4j-over-slf4j/src/test/java/org/dummy/Bug139.java b/log4j-over-slf4j/src/test/java/org/dummy/Bug139.java index d642fea..62d0980 100644 --- a/log4j-over-slf4j/src/test/java/org/dummy/Bug139.java +++ b/log4j-over-slf4j/src/test/java/org/dummy/Bug139.java @@ -24,16 +24,18 @@ */ package org.dummy; +import static org.junit.Assert.assertEquals; + import java.util.logging.Level; import java.util.logging.LogRecord; -import junit.framework.TestCase; - import org.apache.log4j.Category; import org.apache.log4j.Logger; +import org.junit.Test; -public class Bug139 extends TestCase { +public class Bug139 { + @Test public void test() { ListHandler listHandler = new ListHandler(); java.util.logging.Logger root = java.util.logging.Logger.getLogger(""); diff --git a/osgi-over-slf4j/pom.xml b/osgi-over-slf4j/pom.xml index b79400e..ce5f9d4 100644 --- a/osgi-over-slf4j/pom.xml +++ b/osgi-over-slf4j/pom.xml @@ -1,3 +1,4 @@ + @@ -6,7 +7,7 @@ org.slf4j slf4j-parent - 1.7.12 + 1.7.13 osgi-over-slf4j diff --git a/pom.xml b/pom.xml index e920481..bb1dd26 100644 --- a/pom.xml +++ b/pom.xml @@ -1,13 +1,12 @@ - 4.0.0 org.slf4j slf4j-parent - 1.7.12 + 1.7.13 pom SLF4J @@ -31,11 +30,16 @@ https://github.com/ceki/slf4j git@github.com:qos-ch/slf4j.git - + + 1.5 + ${required.jdk.version} + ${required.jdk.version} UTF-8 - 1.5 + UTF-8 + UTF-8 + 1.6.0 0.8.1 1.2.17 @@ -81,7 +85,6 @@ - @@ -111,7 +114,6 @@ - @@ -124,19 +126,37 @@ - src/main/resources + ${project.basedir}/src/main/resources true + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + 1.14 + + + org.codehaus.mojo.signature + java15 + 1.0 + + + + + + + org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.3 - 1.5 - 1.5 + ${required.jdk.version} + ${required.jdk.version} @@ -144,6 +164,19 @@ org.apache.maven.plugins maven-jar-plugin 2.3.1 + + + + ${parsedVersion.osgiVersion} + ${project.description} + ${maven.compiler.source} + ${maven.compiler.target} + ${project.version} + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + true + @@ -189,7 +222,7 @@ - + org.codehaus.mojo build-helper-maven-plugin diff --git a/slf4j-android/pom.xml b/slf4j-android/pom.xml index fe39407..3696b41 100644 --- a/slf4j-android/pom.xml +++ b/slf4j-android/pom.xml @@ -1,14 +1,14 @@ - + + + + 4.0.0 org.slf4j slf4j-parent - 1.7.12 + 1.7.13 - - 4.0.0 slf4j-android jar @@ -31,33 +31,4 @@ - - - - org.apache.maven.plugins - maven-jar-plugin - - - - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${required.jdk.version} - ${required.jdk.version} - - - - - diff --git a/slf4j-android/src/main/java/org/slf4j/impl/AndroidLoggerAdapter.java b/slf4j-android/src/main/java/org/slf4j/impl/AndroidLoggerAdapter.java index 06d1daa..946e72f 100644 --- a/slf4j-android/src/main/java/org/slf4j/impl/AndroidLoggerAdapter.java +++ b/slf4j-android/src/main/java/org/slf4j/impl/AndroidLoggerAdapter.java @@ -530,13 +530,13 @@ private void formatAndLog(int priority, String format, Object... argArray) { if (isLoggable(priority)) { FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - _log(priority, ft.getMessage(), ft.getThrowable()); + logInternal(priority, ft.getMessage(), ft.getThrowable()); } } private void log(int priority, String message, Throwable throwable) { if (isLoggable(priority)) { - _log(priority, message, throwable); + logInternal(priority, message, throwable); } } @@ -544,7 +544,7 @@ return Log.isLoggable(name, priority); } - private void _log(int priority, String message, Throwable throwable) { + private void logInternal(int priority, String message, Throwable throwable) { if (throwable != null) { message += '\n' + Log.getStackTraceString(throwable); } diff --git a/slf4j-api/pom.xml b/slf4j-api/pom.xml index c7b0784..5b9c1b3 100644 --- a/slf4j-api/pom.xml +++ b/slf4j-api/pom.xml @@ -1,5 +1,5 @@ - + 4.0.0 @@ -7,7 +7,7 @@ org.slf4j slf4j-parent - 1.7.12 + 1.7.13 slf4j-api @@ -18,11 +18,21 @@ http://www.slf4j.org - - - + + org.codehaus.mojo + animal-sniffer-maven-plugin + + + + org.slf4j.impl.StaticMDCBinder + org.slf4j.impl.StaticLoggerBinder + org.slf4j.impl.StaticMarkerBinder + + + org.apache.maven.plugins maven-surefire-plugin @@ -40,16 +50,6 @@ org.apache.maven.plugins maven-jar-plugin - - - - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - bundle-test-jar @@ -80,7 +80,6 @@ - diff --git a/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java b/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java index c0228ec..3c8c482 100644 --- a/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java +++ b/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java @@ -28,7 +28,6 @@ import java.net.URL; import java.util.Arrays; import java.util.Enumeration; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -85,7 +84,7 @@ // Support for detecting mismatched logger names. static final String DETECT_LOGGER_NAME_MISMATCH_PROPERTY = "slf4j.detectLoggerNameMismatch"; - static boolean DETECT_LOGGER_NAME_MISMATCH = Boolean.getBoolean(DETECT_LOGGER_NAME_MISMATCH_PROPERTY); + static boolean DETECT_LOGGER_NAME_MISMATCH = Util.safeGetBooleanSystemProperty(DETECT_LOGGER_NAME_MISMATCH_PROPERTY); /** * It is LoggerFactory's responsibility to track version changes and manage @@ -126,9 +125,9 @@ private static boolean messageContainsOrgSlf4jImplStaticLoggerBinder(String msg) { if (msg == null) return false; - if (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1) + if (msg.contains("org/slf4j/impl/StaticLoggerBinder")) return true; - if (msg.indexOf("org.slf4j.impl.StaticLoggerBinder") != -1) + if (msg.contains("org.slf4j.impl.StaticLoggerBinder")) return true; return false; } @@ -155,7 +154,7 @@ } } catch (java.lang.NoSuchMethodError nsme) { String msg = nsme.getMessage(); - if (msg != null && msg.indexOf("org.slf4j.impl.StaticLoggerBinder.getSingleton()") != -1) { + if (msg != null && msg.contains("org.slf4j.impl.StaticLoggerBinder.getSingleton()")) { INITIALIZATION_STATE = FAILED_INITIALIZATION; Util.report("slf4j-api 1.6.x (or later) is incompatible with this binding."); Util.report("Your binding is version 1.5.5 or earlier."); @@ -198,8 +197,8 @@ String requested = StaticLoggerBinder.REQUESTED_API_VERSION; boolean match = false; - for (int i = 0; i < API_COMPATIBILITY_LIST.length; i++) { - if (requested.startsWith(API_COMPATIBILITY_LIST[i])) { + for (String aAPI_COMPATIBILITY_LIST : API_COMPATIBILITY_LIST) { + if (requested.startsWith(aAPI_COMPATIBILITY_LIST)) { match = true; } } @@ -236,7 +235,7 @@ paths = loggerFactoryClassLoader.getResources(STATIC_LOGGER_BINDER_PATH); } while (paths.hasMoreElements()) { - URL path = (URL) paths.nextElement(); + URL path = paths.nextElement(); staticLoggerBinderPathSet.add(path); } } catch (IOException ioe) { @@ -257,9 +256,7 @@ private static void reportMultipleBindingAmbiguity(Set staticLoggerBinderPathSet) { if (isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) { Util.report("Class path contains multiple SLF4J bindings."); - Iterator iterator = staticLoggerBinderPathSet.iterator(); - while (iterator.hasNext()) { - URL path = (URL) iterator.next(); + for (URL path : staticLoggerBinderPathSet) { Util.report("Found binding in [" + path + "]"); } Util.report("See " + MULTIPLE_BINDINGS_URL + " for an explanation."); @@ -304,7 +301,7 @@ Logger logger = getLogger(clazz.getName()); if (DETECT_LOGGER_NAME_MISMATCH) { Class autoComputedCallingClass = Util.getCallingClass(); - if (nonMatchingClasses(clazz, autoComputedCallingClass)) { + if (autoComputedCallingClass != null && nonMatchingClasses(clazz, autoComputedCallingClass)) { Util.report(String.format("Detected logger name mismatch. Given name: \"%s\"; computed name: \"%s\".", logger.getName(), autoComputedCallingClass.getName())); Util.report("See " + LOGGER_NAME_MISMATCH_URL + " for an explanation"); @@ -339,7 +336,7 @@ throw new IllegalStateException(UNSUCCESSFUL_INIT_MSG); case ONGOING_INITIALIZATION: // support re-entrant behavior. - // See also http://bugzilla.slf4j.org/show_bug.cgi?id=106 + // See also http://jira.qos.ch/browse/SLF4J-97 return TEMP_FACTORY; } throw new IllegalStateException("Unreachable code"); diff --git a/slf4j-api/src/main/java/org/slf4j/MDC.java b/slf4j-api/src/main/java/org/slf4j/MDC.java index 23fe971..7eadaee 100644 --- a/slf4j-api/src/main/java/org/slf4j/MDC.java +++ b/slf4j-api/src/main/java/org/slf4j/MDC.java @@ -91,7 +91,7 @@ } catch (NoClassDefFoundError ncde) { mdcAdapter = new NOPMDCAdapter(); String msg = ncde.getMessage(); - if (msg != null && msg.indexOf("StaticMDCBinder") != -1) { + if (msg != null && msg.contains("StaticMDCBinder")) { Util.report("Failed to load class \"org.slf4j.impl.StaticMDCBinder\"."); Util.report("Defaulting to no-operation MDCAdapter implementation."); Util.report("See " + NO_STATIC_MDC_BINDER_URL + " for further details."); diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/BasicMDCAdapter.java b/slf4j-api/src/main/java/org/slf4j/helpers/BasicMDCAdapter.java index 376017c..5f5e69f 100644 --- a/slf4j-api/src/main/java/org/slf4j/helpers/BasicMDCAdapter.java +++ b/slf4j-api/src/main/java/org/slf4j/helpers/BasicMDCAdapter.java @@ -32,40 +32,38 @@ /** * Basic MDC implementation, which can be used with logging systems that lack * out-of-the-box MDC support. - * + * * This code was initially inspired by logback's LogbackMDCAdapter. However, * LogbackMDCAdapter has evolved and is now considerably more sophisticated. * * @author Ceki Gulcu * @author Maarten Bosteels + * @author Lukasz Cwik * * @since 1.5.0 */ public class BasicMDCAdapter implements MDCAdapter { - private InheritableThreadLocal> inheritableThreadLocal = new InheritableThreadLocal>(); - - static boolean isJDK14() { - try { - String javaVersion = System.getProperty("java.version"); - return javaVersion.startsWith("1.4"); - } catch (SecurityException se) { - // punt and assume JDK 1.5 or later - return false; + private InheritableThreadLocal> inheritableThreadLocal = + new InheritableThreadLocal>() { + @Override + protected Map childValue(Map parentValue) { + if (parentValue == null) { + return null; + } + return new HashMap(parentValue); } - } - - static boolean IS_JDK14 = isJDK14(); + }; /** * Put a context value (the val parameter) as identified with * the key parameter into the current thread's context map. * Note that contrary to log4j, the val parameter can be null. - * + * *

* If the current thread does not have a context map it is created as a side * effect of this call. - * + * * @throws IllegalArgumentException * in case the "key" parameter is null */ @@ -73,9 +71,9 @@ if (key == null) { throw new IllegalArgumentException("key cannot be null"); } - Map map = (Map) inheritableThreadLocal.get(); + Map map = inheritableThreadLocal.get(); if (map == null) { - map = Collections. synchronizedMap(new HashMap()); + map = new HashMap(); inheritableThreadLocal.set(map); } map.put(key, val); @@ -85,9 +83,9 @@ * Get the context identified by the key parameter. */ public String get(String key) { - Map Map = (Map) inheritableThreadLocal.get(); - if ((Map != null) && (key != null)) { - return (String) Map.get(key); + Map map = inheritableThreadLocal.get(); + if ((map != null) && (key != null)) { + return map.get(key); } else { return null; } @@ -97,7 +95,7 @@ * Remove the the context identified by the key parameter. */ public void remove(String key) { - Map map = (Map) inheritableThreadLocal.get(); + Map map = inheritableThreadLocal.get(); if (map != null) { map.remove(key); } @@ -107,27 +105,21 @@ * Clear all entries in the MDC. */ public void clear() { - Map map = (Map) inheritableThreadLocal.get(); + Map map = inheritableThreadLocal.get(); if (map != null) { map.clear(); - // the InheritableThreadLocal.remove method was introduced in JDK 1.5 - // Thus, invoking clear() on previous JDK 1.4 will fail - if (isJDK14()) { - inheritableThreadLocal.set(null); - } else { - inheritableThreadLocal.remove(); - } + inheritableThreadLocal.remove(); } } /** * Returns the keys in the MDC as a {@link Set} of {@link String}s The * returned value can be null. - * + * * @return the keys in the MDC */ public Set getKeys() { - Map map = (Map) inheritableThreadLocal.get(); + Map map = inheritableThreadLocal.get(); if (map != null) { return map.keySet(); } else { @@ -136,26 +128,20 @@ } /** - * Return a copy of the current thread's context map. + * Return a copy of the current thread's context map. * Returned value may be null. - * + * */ public Map getCopyOfContextMap() { - Map oldMap = (Map) inheritableThreadLocal.get(); + Map oldMap = inheritableThreadLocal.get(); if (oldMap != null) { - Map newMap = Collections. synchronizedMap(new HashMap()); - synchronized (oldMap) { - newMap.putAll(oldMap); - } - return newMap; + return new HashMap(oldMap); } else { return null; } } public void setContextMap(Map contextMap) { - Map map = Collections. synchronizedMap(new HashMap(contextMap)); - inheritableThreadLocal.set(map); + inheritableThreadLocal.set(new HashMap(contextMap)); } - } diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java b/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java index 14b5308..7ed253d 100644 --- a/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java +++ b/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java @@ -101,7 +101,7 @@ int size = referenceList.size(); for (int i = 0; i < size; i++) { - Marker m = (Marker) referenceList.get(i); + Marker m = referenceList.get(i); if (referenceToRemove.equals(m)) { referenceList.remove(i); return true; @@ -120,8 +120,7 @@ } if (hasReferences()) { - for (int i = 0; i < referenceList.size(); i++) { - Marker ref = (Marker) referenceList.get(i); + for (Marker ref : referenceList) { if (ref.contains(other)) { return true; } @@ -143,8 +142,7 @@ } if (hasReferences()) { - for (int i = 0; i < referenceList.size(); i++) { - Marker ref = (Marker) referenceList.get(i); + for (Marker ref : referenceList) { if (ref.contains(name)) { return true; } @@ -182,7 +180,7 @@ StringBuilder sb = new StringBuilder(this.getName()); sb.append(' ').append(OPEN); while (it.hasNext()) { - reference = (Marker) it.next(); + reference = it.next(); sb.append(reference.getName()); if (it.hasNext()) { sb.append(SEP); diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java b/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java index 2fa5435..d5a5051 100644 --- a/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java +++ b/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java @@ -203,34 +203,34 @@ return new FormattingTuple(messagePattern, argArray, throwableCandidate); } else { // add the tail string which contains no variables and return // the result. - sbuf.append(messagePattern.substring(i, messagePattern.length())); + sbuf.append(messagePattern, i, messagePattern.length()); return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate); } } else { if (isEscapedDelimeter(messagePattern, j)) { if (!isDoubleEscaped(messagePattern, j)) { L--; // DELIM_START was escaped, thus should not be incremented - sbuf.append(messagePattern.substring(i, j - 1)); + sbuf.append(messagePattern, i, j - 1); sbuf.append(DELIM_START); i = j + 1; } else { // The escape character preceding the delimiter start is // itself escaped: "abc x:\\{}" // we have to consume one backward slash - sbuf.append(messagePattern.substring(i, j - 1)); + sbuf.append(messagePattern, i, j - 1); deeplyAppendParameter(sbuf, argArray[L], new HashMap()); i = j + 2; } } else { // normal case - sbuf.append(messagePattern.substring(i, j)); + sbuf.append(messagePattern, i, j); deeplyAppendParameter(sbuf, argArray[L], new HashMap()); i = j + 2; } } } // append the characters following the last {} pair. - sbuf.append(messagePattern.substring(i, messagePattern.length())); + sbuf.append(messagePattern, i, messagePattern.length()); if (L < argArray.length - 1) { return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate); } else { diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/Util.java b/slf4j-api/src/main/java/org/slf4j/helpers/Util.java index 0a033a4..7cdf076 100644 --- a/slf4j-api/src/main/java/org/slf4j/helpers/Util.java +++ b/slf4j-api/src/main/java/org/slf4j/helpers/Util.java @@ -35,6 +35,27 @@ private Util() { } + public static String safeGetSystemProperty(String key) { + if (key == null) + throw new IllegalArgumentException("null input"); + + String result = null; + try { + result = System.getProperty(key); + } catch (java.lang.SecurityException sm) { + ; // ignore + } + return result; + } + + public static boolean safeGetBooleanSystemProperty(String key) { + String value = safeGetSystemProperty(key); + if (value == null) + return false; + else + return value.equalsIgnoreCase("true"); + } + /** * In order to call {@link SecurityManager#getClassContext()}, which is a * protected method, we add this wrapper which allows the method to be visible @@ -46,7 +67,28 @@ } } - private static final ClassContextSecurityManager SECURITY_MANAGER = new ClassContextSecurityManager(); + private static ClassContextSecurityManager SECURITY_MANAGER; + private static boolean SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED = false; + + private static ClassContextSecurityManager getSecurityManager() { + if(SECURITY_MANAGER != null) + return SECURITY_MANAGER; + else if(SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED) + return null; + else { + SECURITY_MANAGER = safeCreateSecurityManager(); + SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED = true; + return SECURITY_MANAGER; + } + } + + private static ClassContextSecurityManager safeCreateSecurityManager() { + try { + return new ClassContextSecurityManager(); + } catch (java.lang.SecurityException sm) { + return null; + } + } /** * Returns the name of the class which called the invoking method. @@ -54,7 +96,10 @@ * @return the name of the class which called the invoking method. */ public static Class getCallingClass() { - Class[] trace = SECURITY_MANAGER.getClassContext(); + ClassContextSecurityManager securityManager = getSecurityManager(); + if(securityManager == null) + return null; + Class[] trace = securityManager.getClassContext(); String thisClassName = Util.class.getName(); // Advance until Util is found diff --git a/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java b/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java index 74666d0..7e855bb 100644 --- a/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java +++ b/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java @@ -24,10 +24,11 @@ */ package org.slf4j; +import static org.junit.Assert.*; + import java.util.Iterator; -import junit.framework.TestCase; - +import org.junit.Test; import org.slf4j.helpers.BasicMarkerFactory; /** @@ -36,7 +37,7 @@ * @author Ceki Gülcü * @author Joern Huxhorn */ -public class BasicMarkerTest extends TestCase { +public class BasicMarkerTest { static final String BLUE_STR = "BLUE"; static final String RED_STR = "RED"; static final String GREEN_STR = "GREEN"; @@ -69,6 +70,7 @@ multiComp.add(comp); } + @Test public void testPrimitive() { assertEquals(BLUE_STR, blue.getName()); assertTrue(blue.contains(blue)); @@ -80,20 +82,24 @@ assertTrue(blue2.contains(blue)); } + @Test public void testPrimitiveByName() { assertTrue(blue.contains(BLUE_STR)); } + @Test public void testComposite() { assertTrue(comp.contains(comp)); assertTrue(comp.contains(blue)); } + @Test public void testCompositeByName() { assertTrue(comp.contains(COMP_STR)); assertTrue(comp.contains(BLUE_STR)); } + @Test public void testMultiComposite() { assertTrue(multiComp.contains(comp)); assertTrue(multiComp.contains(blue)); @@ -101,6 +107,7 @@ assertFalse(multiComp.contains(red)); } + @Test public void testMultiCompositeByName() { assertTrue(multiComp.contains(COMP_STR)); assertTrue(multiComp.contains(BLUE_STR)); @@ -108,6 +115,7 @@ assertFalse(multiComp.contains(RED_STR)); } + @Test public void testMultiAdd() { Marker parent = factory.getMarker(PARENT_MARKER_STR); Marker child = factory.getMarker(CHILD_MARKER_STR); @@ -122,6 +130,7 @@ assertFalse(iterator.hasNext()); } + @Test public void testAddRemove() { final String NEW_PREFIX = "NEW_"; Marker parent = factory.getMarker(NEW_PREFIX + PARENT_MARKER_STR); @@ -142,6 +151,7 @@ assertFalse(parent.remove(child)); } + @Test public void testSelfRecursion() { final String diffPrefix = "NEW_" + diff; final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR; @@ -155,6 +165,7 @@ assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR)); } + @Test public void testIndirectRecursion() { final String diffPrefix = "NEW_" + diff; final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR; @@ -175,6 +186,7 @@ assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR)); } + @Test public void testHomonyms() { final String diffPrefix = "homonym" + diff; final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR; diff --git a/slf4j-api/src/test/java/org/slf4j/NoBindingTest.java b/slf4j-api/src/test/java/org/slf4j/NoBindingTest.java index 3191275..c9f85e6 100644 --- a/slf4j-api/src/test/java/org/slf4j/NoBindingTest.java +++ b/slf4j-api/src/test/java/org/slf4j/NoBindingTest.java @@ -24,28 +24,33 @@ */ package org.slf4j; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.Random; +import org.junit.Test; import org.slf4j.helpers.BasicMarker; import org.slf4j.helpers.NOPLogger; -import junit.framework.TestCase; - -public class NoBindingTest extends TestCase { +public class NoBindingTest { int diff = new Random().nextInt(10000); + @Test public void testLogger() { Logger logger = LoggerFactory.getLogger(NoBindingTest.class); logger.debug("hello" + diff); assertTrue(logger instanceof NOPLogger); } - public void testMDC() { + @Test + public void testMDC() { MDC.put("k" + diff, "v"); assertNull(MDC.get("k")); } + @Test public void testMarker() { Marker m = MarkerFactory.getMarker("a" + diff); assertTrue(m instanceof BasicMarker); diff --git a/slf4j-api/src/test/java/org/slf4j/helpers/BasicMDCAdapterTest.java b/slf4j-api/src/test/java/org/slf4j/helpers/BasicMDCAdapterTest.java new file mode 100644 index 0000000..d0df4c0 --- /dev/null +++ b/slf4j-api/src/test/java/org/slf4j/helpers/BasicMDCAdapterTest.java @@ -0,0 +1,148 @@ +/** + * Copyright (c) 2004-2013 QOS.ch, Copyright (C) 2015 Google Inc. + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.slf4j.helpers; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.lang.Thread.UncaughtExceptionHandler; +import java.util.Map; + +import org.junit.After; +import org.junit.Test; +import org.slf4j.spi.MDCAdapter; + +/** + * Tests for {@link BasicMDCAdapter} + * + * @author Lukasz Cwik + */ +public class BasicMDCAdapterTest { + MDCAdapter mdc = new BasicMDCAdapter(); + + @After + public void tearDown() throws Exception { + mdc.clear(); + } + + @Test + public void testSettingAndGettingWithMDC() { + assertNull(mdc.get("testKey")); + mdc.put("testKey", "testValue"); + assertEquals(mdc.get("testKey"), "testValue"); + } + + @Test + public void testOverwritingAKeyInMDC() { + assertNull(mdc.get("testKey")); + mdc.put("testKey", "testValue"); + mdc.put("testKey", "differentTestValue"); + assertEquals(mdc.get("testKey"), "differentTestValue"); + } + + @Test + public void testClearingMDC() { + mdc.put("testKey", "testValue"); + assertFalse(mdc.getCopyOfContextMap().isEmpty()); + mdc.clear(); + assertNull(mdc.getCopyOfContextMap()); + } + + @Test + public void testGetCopyOfContextMapFromMDC() { + mdc.put("testKey", "testValue"); + Map copy = mdc.getCopyOfContextMap(); + mdc.put("anotherTestKey", "anotherTestValue"); + assertFalse(copy.size() == mdc.getCopyOfContextMap().size()); + } + + @Test + public void testMDCInheritsValuesFromParentThread() throws Exception { + mdc.put("parentKey", "parentValue"); + runAndWait(new Runnable() { + public void run() { + mdc.put("childKey", "childValue"); + assertEquals("parentValue", mdc.get("parentKey")); + } + }); + } + + @Test + public void testMDCDoesntGetValuesFromChildThread() throws Exception { + mdc.put("parentKey", "parentValue"); + runAndWait(new Runnable() { + public void run() { + mdc.put("childKey", "childValue"); + } + }); + assertEquals("parentValue", mdc.get("parentKey")); + assertNull(mdc.get("childKey")); + } + + @Test + public void testMDCChildThreadCanOverwriteParentThread() throws Exception { + mdc.put("sharedKey", "parentValue"); + runAndWait(new Runnable() { + public void run() { + assertEquals("parentValue", mdc.get("sharedKey")); + mdc.put("sharedKey", "childValue"); + assertEquals("childValue", mdc.get("sharedKey")); + } + }); + assertEquals("parentValue", mdc.get("sharedKey")); + } + + private void runAndWait(Runnable runnable) throws Exception { + RecordingExceptionHandler handler = new RecordingExceptionHandler(); + Thread thread = new Thread(runnable); + thread.setUncaughtExceptionHandler(handler); + thread.start(); + try { + thread.join(); + } catch (Throwable t) { + fail("Unexpected failure in child thread:" + t.getMessage()); + } + assertFalse(handler.getMessage(), handler.hadException()); + } + + /** A {@link UncaughtExceptionHandler} that records whether the thread threw an exception. */ + private static class RecordingExceptionHandler implements UncaughtExceptionHandler { + private Throwable exception; + + public void uncaughtException(Thread t, Throwable e) { + exception = e; + } + + boolean hadException() { + return exception != null; + } + + String getMessage() { + return exception != null ? exception.getMessage() : ""; + } + } +} diff --git a/slf4j-api/src/test/java/org/slf4j/helpers/BubbleSortTest.java b/slf4j-api/src/test/java/org/slf4j/helpers/BubbleSortTest.java index 95e1937..403ecd6 100644 --- a/slf4j-api/src/test/java/org/slf4j/helpers/BubbleSortTest.java +++ b/slf4j-api/src/test/java/org/slf4j/helpers/BubbleSortTest.java @@ -24,10 +24,13 @@ */ package org.slf4j.helpers; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.util.Arrays; import java.util.Random; -import junit.framework.TestCase; +import org.junit.Test; /** * Test that our BubbleSort algorithm is correctly implemented. @@ -35,8 +38,9 @@ * @author Ceki * */ -public class BubbleSortTest extends TestCase { +public class BubbleSortTest { + @Test public void testSmoke() { int[] a = new int[] { 5, 3, 2, 7 }; BubbleSort.sort(a); @@ -47,11 +51,13 @@ assertEquals(7, a[i++]); } + @Test public void testEmpty() { int[] a = new int[] {}; BubbleSort.sort(a); } + @Test public void testSorted() { int[] a = new int[] { 3, 30, 300, 3000 }; BubbleSort.sort(a); @@ -62,6 +68,7 @@ assertEquals(3000, a[i++]); } + @Test public void testInverted() { int[] a = new int[] { 3000, 300, 30, 3 }; BubbleSort.sort(a); @@ -72,6 +79,7 @@ assertEquals(3000, a[i++]); } + @Test public void testWithSameEntry() { int[] a = new int[] { 10, 20, 10, 20 }; BubbleSort.sort(a); @@ -82,6 +90,7 @@ assertEquals(20, a[i++]); } + @Test public void testRandom() { int len = 100; Random random = new Random(156); diff --git a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java index a9a7d2d..21b6a24 100644 --- a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java +++ b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java @@ -26,11 +26,11 @@ import java.text.MessageFormat; -import junit.framework.TestCase; import org.junit.Ignore; +import org.junit.Test; @Ignore -public class MessageFormatterPerfTest extends TestCase { +public class MessageFormatterPerfTest{ //extends TestCase { Integer i1 = new Integer(1); Integer i2 = new Integer(2); @@ -38,22 +38,13 @@ // static long REFERENCE_BIPS = 48416; - public MessageFormatterPerfTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - } - - protected void tearDown() throws Exception { - } - public void XtestJDKFormatterPerf() { jdkMessageFormatter(RUN_LENGTH); double duration = jdkMessageFormatter(RUN_LENGTH); System.out.println("jdk duration = " + duration + " nanos"); } + @Test public void testSLF4JPerf_OneArg() { slf4jMessageFormatter_OneArg(RUN_LENGTH); double duration = slf4jMessageFormatter_OneArg(RUN_LENGTH); @@ -62,6 +53,7 @@ BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS); } + @Test public void testSLF4JPerf_TwoArg() { slf4jMessageFormatter_TwoArg(RUN_LENGTH); double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH); diff --git a/slf4j-api/src/test/java/org/slf4j/helpers/SubstitutableLoggerTest.java b/slf4j-api/src/test/java/org/slf4j/helpers/SubstitutableLoggerTest.java index 9484445..ab076fc 100644 --- a/slf4j-api/src/test/java/org/slf4j/helpers/SubstitutableLoggerTest.java +++ b/slf4j-api/src/test/java/org/slf4j/helpers/SubstitutableLoggerTest.java @@ -24,6 +24,9 @@ */ package org.slf4j.helpers; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -34,15 +37,16 @@ import java.util.List; import java.util.Set; -import junit.framework.TestCase; +import org.junit.Test; import org.slf4j.Logger; /** * @author Chetan Mehrotra */ -public class SubstitutableLoggerTest extends TestCase { +public class SubstitutableLoggerTest { private static final Set EXCLUDED_METHODS = new HashSet(Arrays.asList("getName")); + @Test public void testDelegate() throws Exception { SubstituteLogger log = new SubstituteLogger("foo"); assertTrue(log.delegate() instanceof NOPLogger); diff --git a/slf4j-api/src/test/java/org/slf4j/helpers/SubstituteLoggerFactoryTest.java b/slf4j-api/src/test/java/org/slf4j/helpers/SubstituteLoggerFactoryTest.java index 2771205..246f9c4 100644 --- a/slf4j-api/src/test/java/org/slf4j/helpers/SubstituteLoggerFactoryTest.java +++ b/slf4j-api/src/test/java/org/slf4j/helpers/SubstituteLoggerFactoryTest.java @@ -24,16 +24,21 @@ */ package org.slf4j.helpers; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; import org.slf4j.Logger; import java.util.Arrays; import java.util.HashSet; import java.util.Set; -public class SubstituteLoggerFactoryTest extends TestCase { +public class SubstituteLoggerFactoryTest { private SubstituteLoggerFactory factory = new SubstituteLoggerFactory(); + @Test public void testFactory() { Logger log = factory.getLogger("foo"); assertNotNull(log); @@ -42,6 +47,7 @@ assertTrue("Loggers with same name must be same", log == log2); } + @Test public void testLoggerNameList() { factory.getLogger("foo1"); factory.getLogger("foo2"); @@ -52,6 +58,7 @@ assertEquals(expectedNames, actualNames); } + @Test public void testLoggers() { factory.getLogger("foo1"); factory.getLogger("foo2"); diff --git a/slf4j-ext/pom.xml b/slf4j-ext/pom.xml index af8dbe9..38fb357 100644 --- a/slf4j-ext/pom.xml +++ b/slf4j-ext/pom.xml @@ -1,5 +1,5 @@ - + 4.0.0 @@ -7,7 +7,7 @@ org.slf4j slf4j-parent - 1.7.12 + 1.7.13 slf4j-ext @@ -48,21 +48,12 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - - ${required.jdk.version} - ${required.jdk.version} - - - + org.apache.maven.plugins maven-surefire-plugin - + false once plain @@ -74,32 +65,21 @@ - org.apache.maven.plugins maven-jar-plugin - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} org.slf4j.agent.AgentPremain ../../../../javassist/javassist/3.4.GA/javassist-3.4.GA.jar javassist-3.4.GA.jar javassist.jar - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - + + - - - - - - diff --git a/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java b/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java index aa9dc01..897f38f 100644 --- a/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java +++ b/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java @@ -102,7 +102,7 @@ public XLogger(Logger logger) { // If class B extends A, assuming B does not override method x(), the caller // of new B().x() is A and not B, see also - // http://bugzilla.slf4j.org/show_bug.cgi?id=114 + // http://jira.qos.ch/browse/SLF4J-105 super(logger, LoggerWrapper.class.getName()); } diff --git a/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java b/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java index 575a05b..8096f36 100644 --- a/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java +++ b/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java @@ -92,7 +92,7 @@ */ public static String getSignature(CtBehavior method) throws NotFoundException { - CtClass parameterTypes[] = method.getParameterTypes(); + CtClass[] parameterTypes = method.getParameterTypes(); CodeAttribute codeAttribute = method.getMethodInfo().getCodeAttribute(); diff --git a/slf4j-ext/src/test/java/org/slf4j/NDCTest.java b/slf4j-ext/src/test/java/org/slf4j/NDCTest.java index 0ae9e19..f919a4b 100644 --- a/slf4j-ext/src/test/java/org/slf4j/NDCTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/NDCTest.java @@ -24,29 +24,33 @@ */ package org.slf4j; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; -public class NDCTest extends TestCase { +import org.junit.Before; +import org.junit.Test; - protected void setUp() throws Exception { - super.setUp(); +public class NDCTest { + + @Before + public void setUp() throws Exception { MDC.clear(); } - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testEmpty() { assertEquals("", NDC.pop()); } + + @Test public void testSmoke() { NDC.push("a"); String result = NDC.pop(); assertEquals("a", result); } + + @Test public void testSmoke2() { NDC.push("a"); NDC.push("b"); diff --git a/slf4j-ext/src/test/java/org/slf4j/cal10n_dummy/LocLoggerTest.java b/slf4j-ext/src/test/java/org/slf4j/cal10n_dummy/LocLoggerTest.java index 6409609..c6c6e00 100644 --- a/slf4j-ext/src/test/java/org/slf4j/cal10n_dummy/LocLoggerTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/cal10n_dummy/LocLoggerTest.java @@ -24,19 +24,20 @@ */ package org.slf4j.cal10n_dummy; +import static org.junit.Assert.assertEquals; + import java.util.Locale; -import junit.framework.TestCase; - import org.apache.log4j.spi.LoggingEvent; +import org.junit.Before; +import org.junit.Test; import org.slf4j.cal10n.LocLogger; import org.slf4j.cal10n.LocLoggerFactory; import org.slf4j.dummyExt.ListAppender; import ch.qos.cal10n.IMessageConveyor; import ch.qos.cal10n.MessageConveyor; - -public class LocLoggerTest extends TestCase { +public class LocLoggerTest { ListAppender listAppender; org.apache.log4j.Logger log4jRoot; @@ -46,13 +47,9 @@ final static String EXPECTED_FILE_NAME = "LocLoggerTest.java"; - public LocLoggerTest(String name) { - super(name); - } + @Before public void setUp() throws Exception { - super.setUp(); - // start from a clean slate for each test listAppender = new ListAppender(); @@ -67,10 +64,8 @@ assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName()); } - public void tearDown() throws Exception { - super.tearDown(); - } + @Test public void testSmoke() { LocLogger locLogger = llFactory_uk.getLocLogger(this.getClass()); locLogger.info(Months.JAN); diff --git a/slf4j-ext/src/test/java/org/slf4j/cal10n_dummy/PackageTest.java b/slf4j-ext/src/test/java/org/slf4j/cal10n_dummy/PackageTest.java index bf1ea17..b56dd4a 100644 --- a/slf4j-ext/src/test/java/org/slf4j/cal10n_dummy/PackageTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/cal10n_dummy/PackageTest.java @@ -24,13 +24,11 @@ */ package org.slf4j.cal10n_dummy; -import junit.framework.*; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; -public class PackageTest extends TestCase { - - public static Test suite() { - TestSuite suite = new TestSuite(); - suite.addTestSuite(LocLoggerTest.class); - return suite; - } +@RunWith(Suite.class) +@SuiteClasses({ LocLoggerTest.class }) +public class PackageTest { } diff --git a/slf4j-ext/src/test/java/org/slf4j/dummyExt/EventLoggerTest.java b/slf4j-ext/src/test/java/org/slf4j/dummyExt/EventLoggerTest.java index 705ea47..40d5976 100644 --- a/slf4j-ext/src/test/java/org/slf4j/dummyExt/EventLoggerTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/dummyExt/EventLoggerTest.java @@ -24,31 +24,30 @@ */ package org.slf4j.dummyExt; +import static org.junit.Assert.assertEquals; + import java.util.Date; import java.util.Locale; import java.util.TimeZone; -import junit.framework.TestCase; - import org.apache.log4j.spi.LocationInfo; import org.apache.log4j.spi.LoggingEvent; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.slf4j.MDC; import org.slf4j.ext.EventData; import org.slf4j.ext.EventLogger; - -public class EventLoggerTest extends TestCase { +public class EventLoggerTest { ListAppender listAppender; org.apache.log4j.Logger log4; final static String EXPECTED_FILE_NAME = "EventLoggerTest.java"; - public EventLoggerTest(String name) { - super(name); - } + @Before public void setUp() throws Exception { - super.setUp(); // start from a clean slate for each test @@ -68,8 +67,8 @@ } + @After public void tearDown() throws Exception { - super.tearDown(); MDC.clear(); } @@ -77,7 +76,8 @@ assertEquals(expectedMsg, le.getMessage()); assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName()); } - + + @Test public void testEventLogger() { EventData data[] = new EventData[2]; data[0] = new EventData(); diff --git a/slf4j-ext/src/test/java/org/slf4j/dummyExt/MDCStrLookupTest.java b/slf4j-ext/src/test/java/org/slf4j/dummyExt/MDCStrLookupTest.java index 22b2063..db77298 100644 --- a/slf4j-ext/src/test/java/org/slf4j/dummyExt/MDCStrLookupTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/dummyExt/MDCStrLookupTest.java @@ -24,25 +24,14 @@ */ package org.slf4j.dummyExt; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import org.junit.Test; import org.slf4j.MDC; import org.slf4j.ext.MDCStrLookup; +public class MDCStrLookupTest { -public class MDCStrLookupTest extends TestCase { - - public MDCStrLookupTest(String name) { - super(name); - } - - public void setUp() throws Exception { - super.setUp(); - } - - public void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testLookup() throws Exception { MDC.put("key", "value"); MDC.put("number", "2"); diff --git a/slf4j-ext/src/test/java/org/slf4j/dummyExt/PackageTest.java b/slf4j-ext/src/test/java/org/slf4j/dummyExt/PackageTest.java index 38c2052..56fb103 100644 --- a/slf4j-ext/src/test/java/org/slf4j/dummyExt/PackageTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/dummyExt/PackageTest.java @@ -26,13 +26,11 @@ import junit.framework.*; -public class PackageTest extends TestCase { +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; - public static Test suite() { - TestSuite suite = new TestSuite(); - suite.addTestSuite(MDCStrLookupTest.class); - suite.addTestSuite(XLoggerTest.class); - suite.addTestSuite(EventLoggerTest.class); - return suite; - } +@RunWith(Suite.class) +@SuiteClasses({ MDCStrLookupTest.class, XLoggerTest.class, EventLoggerTest.class }) +public class PackageTest { } diff --git a/slf4j-ext/src/test/java/org/slf4j/dummyExt/XLoggerTest.java b/slf4j-ext/src/test/java/org/slf4j/dummyExt/XLoggerTest.java index e09e463..a88fcca 100644 --- a/slf4j-ext/src/test/java/org/slf4j/dummyExt/XLoggerTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/dummyExt/XLoggerTest.java @@ -24,26 +24,24 @@ */ package org.slf4j.dummyExt; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.apache.log4j.spi.LocationInfo; import org.apache.log4j.spi.LoggingEvent; +import org.junit.Before; +import org.junit.Test; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; -public class XLoggerTest extends TestCase { +public class XLoggerTest { ListAppender listAppender; org.apache.log4j.Logger log4jRoot; final static String EXPECTED_FILE_NAME = "XLoggerTest.java"; - public XLoggerTest(String name) { - super(name); - } - + @Before public void setUp() throws Exception { - super.setUp(); // start from a clean slate for each test @@ -52,10 +50,6 @@ log4jRoot = org.apache.log4j.Logger.getRootLogger(); log4jRoot.addAppender(listAppender); log4jRoot.setLevel(org.apache.log4j.Level.TRACE); - } - - public void tearDown() throws Exception { - super.tearDown(); } void verify(LoggingEvent le, String expectedMsg) { @@ -74,6 +68,7 @@ assertEquals(le.getLevel().toString(), level.toString()); } + @Test public void testEntering() { XLogger logger = XLoggerFactory.getXLogger("UnitTest"); logger.entry(); @@ -89,6 +84,7 @@ verify((LoggingEvent) listAppender.list.get(2), "entry with (test)"); } + @Test public void testExiting() { XLogger logger = XLoggerFactory.getXLogger("UnitTest"); logger.exit(); @@ -101,6 +97,7 @@ verify((LoggingEvent) listAppender.list.get(2), "exit with (false)"); } + @Test public void testThrowing() { XLogger logger = XLoggerFactory.getXLogger("UnitTest"); Throwable t = new UnsupportedOperationException("Test"); @@ -112,6 +109,7 @@ verifyWithLevelAndException(event, XLogger.Level.DEBUG, "throwing", t); } + @Test public void testCaught() { XLogger logger = XLoggerFactory.getXLogger("UnitTest"); long x = 5; @@ -128,7 +126,9 @@ verifyWithLevelAndException((LoggingEvent) listAppender.list.get(1), XLogger.Level.DEBUG, "catching", t); } - // See http://bugzilla.slf4j.org/show_bug.cgi?id=114 + // See http://jira.qos.ch/browse/SLF4J-105 + // formerly http://bugzilla.slf4j.org/show_bug.cgi?id=114 + @Test public void testLocationExtraction_Bug114() { XLogger logger = XLoggerFactory.getXLogger("UnitTest"); int line = 135; // requires update if line numbers change diff --git a/slf4j-ext/src/test/java/org/slf4j/instrumentation/ToStringHelperTest.java b/slf4j-ext/src/test/java/org/slf4j/instrumentation/ToStringHelperTest.java index 2fa793f..7c41a74 100644 --- a/slf4j-ext/src/test/java/org/slf4j/instrumentation/ToStringHelperTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/instrumentation/ToStringHelperTest.java @@ -24,10 +24,13 @@ */ package org.slf4j.instrumentation; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; -public class ToStringHelperTest extends TestCase { +import org.junit.Test; +public class ToStringHelperTest { + + @Test public void testRenderer() { assertEquals("", "null", ToStringHelper.render(null)); assertEquals("", "a", ToStringHelper.render("a")); diff --git a/slf4j-ext/src/test/java/org/slf4j/profiler/PackageTest.java b/slf4j-ext/src/test/java/org/slf4j/profiler/PackageTest.java index 7ee52d2..1c2b09c 100644 --- a/slf4j-ext/src/test/java/org/slf4j/profiler/PackageTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/profiler/PackageTest.java @@ -24,14 +24,14 @@ */ package org.slf4j.profiler; -import junit.framework.*; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; -public class PackageTest extends TestCase { +@RunWith(Suite.class) +@SuiteClasses({UtilTest.class, + ProfilerTest.class}) +public class PackageTest { - public static Test suite() { - TestSuite suite = new TestSuite(); - suite.addTestSuite(UtilTest.class); - suite.addTestSuite(ProfilerTest.class); - return suite; - } + }diff --git a/slf4j-ext/src/test/java/org/slf4j/profiler/ProfilerTest.java b/slf4j-ext/src/test/java/org/slf4j/profiler/ProfilerTest.java index 57368b9..cd1ec3c 100644 --- a/slf4j-ext/src/test/java/org/slf4j/profiler/ProfilerTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/profiler/ProfilerTest.java @@ -24,19 +24,18 @@ */ package org.slf4j.profiler; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -public class ProfilerTest extends TestCase { +public class ProfilerTest { Logger logger = LoggerFactory.getLogger(ProfilerTest.class); - public void setUp() throws Exception { - super.setUp(); - } - + @Test public void testSmoke() { Profiler profiler = new Profiler("SMOKE"); profiler.stop(); @@ -49,6 +48,7 @@ assertNull(profiler.getLastTimeInstrument()); } + @Test public void testBasicProfiling() { Profiler profiler = new Profiler("BAS"); @@ -80,6 +80,7 @@ // |-- Total elapsed time [subtask] 7.321 milliseconds. // |-- elapsed time [doZ] 3.211 milliseconds. // |-- Total elapsed time [BAS] 30.317 milliseconds. + @Test public void testNestedProfiling() { Profiler profiler = new Profiler("BAS"); diff --git a/slf4j-ext/src/test/java/org/slf4j/profiler/UtilTest.java b/slf4j-ext/src/test/java/org/slf4j/profiler/UtilTest.java index 39f1b6c..5af271e 100644 --- a/slf4j-ext/src/test/java/org/slf4j/profiler/UtilTest.java +++ b/slf4j-ext/src/test/java/org/slf4j/profiler/UtilTest.java @@ -24,22 +24,13 @@ */ package org.slf4j.profiler; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; -public class UtilTest extends TestCase { +import org.junit.Test; - public UtilTest(String name) { - super(name); - } +public class UtilTest { - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testSelectDurationUnitForDisplay() throws InterruptedException { assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(10)); assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(9 * Util.NANOS_IN_ONE_MICROSECOND)); diff --git a/slf4j-jcl/pom.xml b/slf4j-jcl/pom.xml index 6cf95b6..1d17a62 100644 --- a/slf4j-jcl/pom.xml +++ b/slf4j-jcl/pom.xml @@ -1,3 +1,4 @@ + @@ -6,7 +7,7 @@ org.slf4j slf4j-parent - 1.7.12 + 1.7.13 slf4j-jcl @@ -21,33 +22,11 @@ org.slf4j slf4j-api - commons-logging commons-logging 1.1.1 - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - - diff --git a/slf4j-jcl/src/test/java/org/slf4j/InvocationTest.java b/slf4j-jcl/src/test/java/org/slf4j/InvocationTest.java index 599eaca..dcc294f 100644 --- a/slf4j-jcl/src/test/java/org/slf4j/InvocationTest.java +++ b/slf4j-jcl/src/test/java/org/slf4j/InvocationTest.java @@ -24,9 +24,13 @@ */ package org.slf4j; +import static org.junit.Assert.assertNull; + import java.util.logging.Level; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Test whether invoking the SLF4J API causes problems or not. @@ -34,31 +38,30 @@ * @author Ceki Gulcu * */ -public class InvocationTest extends TestCase { +public class InvocationTest { Level oldLevel; java.util.logging.Logger root = java.util.logging.Logger.getLogger(""); - public InvocationTest(String arg0) { - super(arg0); - } - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { oldLevel = root.getLevel(); root.setLevel(Level.OFF); } - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { root.setLevel(oldLevel); } + @Test public void test1() { Logger logger = LoggerFactory.getLogger("test1"); logger.debug("Hello world."); } + @Test public void test2() { Integer i1 = new Integer(1); Integer i2 = new Integer(2); @@ -82,6 +85,7 @@ logger.error("Hello world 4.", e); } + @Test public void testNull() { Logger logger = LoggerFactory.getLogger("testNull"); logger.debug(null); @@ -96,6 +100,7 @@ logger.error(null, e); } + @Test public void testMarker() { Logger logger = LoggerFactory.getLogger("testMarker"); Marker blue = MarkerFactory.getMarker("BLUE"); @@ -115,6 +120,7 @@ logger.error(blue, "hello {} and {} ", "world", "universe"); } + @Test public void testMDC() { MDC.put("k", "v"); assertNull(MDC.get("k")); diff --git a/slf4j-jdk14/pom.xml b/slf4j-jdk14/pom.xml index c1845ea..f22250e 100644 --- a/slf4j-jdk14/pom.xml +++ b/slf4j-jdk14/pom.xml @@ -1,23 +1,20 @@ - + + 4.0.0 org.slf4j slf4j-parent - 1.7.12 + 1.7.13 slf4j-jdk14 - jar SLF4J JDK14 Binding SLF4J JDK14 Binding http://www.slf4j.org - @@ -34,23 +31,4 @@ - - - - org.apache.maven.plugins - maven-jar-plugin - - - - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - diff --git a/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerAdapter.java b/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerAdapter.java index 446557e..6122284 100644 --- a/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerAdapter.java +++ b/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerAdapter.java @@ -574,6 +574,8 @@ LogRecord record = new LogRecord(level, msg); record.setLoggerName(getName()); record.setThrown(t); + // Note: parameters in record are not set because SLF4J only + // supports a single formatting style fillCallerData(callerFQCN, record); logger.log(record); @@ -643,7 +645,7 @@ // construction of location data for disabled log // statements. As of 2008-07-31, callers of this method // do not perform this check. See also - // http://bugzilla.slf4j.org/show_bug.cgi?id=90 + // http://jira.qos.ch/browse/SLF4J-81 if (logger.isLoggable(julLevel)) { log(callerFQCN, julLevel, message, t); } diff --git a/slf4j-jdk14/src/test/java/org/slf4j/impl/JDK14AdapterLoggerNameTest.java b/slf4j-jdk14/src/test/java/org/slf4j/impl/JDK14AdapterLoggerNameTest.java index 16c0d61..17651d5 100644 --- a/slf4j-jdk14/src/test/java/org/slf4j/impl/JDK14AdapterLoggerNameTest.java +++ b/slf4j-jdk14/src/test/java/org/slf4j/impl/JDK14AdapterLoggerNameTest.java @@ -24,34 +24,40 @@ */ package org.slf4j.impl; +import static org.junit.Assert.assertNotNull; + import java.util.logging.Handler; import java.util.logging.LogRecord; import java.util.logging.Logger; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -public class JDK14AdapterLoggerNameTest extends TestCase { +public class JDK14AdapterLoggerNameTest { private MockHandler mockHandler; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { Logger logger = Logger.getLogger("TEST"); mockHandler = new MockHandler(); removeHandlers(logger); logger.addHandler(mockHandler); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { removeHandlers(Logger.getLogger("TEST")); - super.tearDown(); } + @Test public void testLoggerNameusingJdkLogging() throws Exception { Logger.getLogger("TEST").info("test message"); assertCorrectLoggerName(); } + @Test public void testLoggerNameUsingSlf4j() throws Exception { JDK14LoggerFactory factory = new JDK14LoggerFactory(); org.slf4j.Logger logger = factory.getLogger("TEST"); diff --git a/slf4j-jdk14/src/test/java/org/slf4j/impl/PerfTest.java b/slf4j-jdk14/src/test/java/org/slf4j/impl/PerfTest.java index bec9067..269ffaf 100644 --- a/slf4j-jdk14/src/test/java/org/slf4j/impl/PerfTest.java +++ b/slf4j-jdk14/src/test/java/org/slf4j/impl/PerfTest.java @@ -24,28 +24,16 @@ */ package org.slf4j.impl; -import junit.framework.TestCase; - +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.helpers.BogoPerf; -public class PerfTest extends TestCase { +public class PerfTest { static long REFERENCE_BIPS = 9000; - public PerfTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testBug72() { int LEN = 1000 * 1000 * 10; diff --git a/slf4j-jdk14/src/test/java/org/slf4j/issue/LoggerSerializationTest.java b/slf4j-jdk14/src/test/java/org/slf4j/issue/LoggerSerializationTest.java index b12e6b4..73314fe 100644 --- a/slf4j-jdk14/src/test/java/org/slf4j/issue/LoggerSerializationTest.java +++ b/slf4j-jdk14/src/test/java/org/slf4j/issue/LoggerSerializationTest.java @@ -34,15 +34,15 @@ import junit.framework.Assert; -import junit.framework.TestCase; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * See http://bugzilla.slf4j.org/show_bug.cgi?id=261 + * See http://jira.qos.ch/browse/SLF4J-252 * @author Thorbjorn Ravn Andersen */ -public class LoggerSerializationTest extends TestCase { +public class LoggerSerializationTest { static class LoggerHolder implements Serializable { private static final long serialVersionUID = 1L; @@ -58,6 +58,7 @@ } } + @Test public void testCanLoggerBeSerialized() throws IOException, ClassNotFoundException { LoggerHolder lh1 = new LoggerHolder(); diff --git a/slf4j-log4j12/pom.xml b/slf4j-log4j12/pom.xml index 596515e..b1930b6 100644 --- a/slf4j-log4j12/pom.xml +++ b/slf4j-log4j12/pom.xml @@ -1,14 +1,13 @@ - + + 4.0.0 org.slf4j slf4j-parent - 1.7.12 + 1.7.13 slf4j-log4j12 @@ -17,7 +16,6 @@ SLF4J LOG4J-12 Binding SLF4J LOG4J-12 Binding http://www.slf4j.org - @@ -31,23 +29,4 @@ - - - - org.apache.maven.plugins - maven-jar-plugin - - - - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - diff --git a/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerAdapter.java b/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerAdapter.java index 1cd25d6..0685a4e 100644 --- a/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerAdapter.java +++ b/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerAdapter.java @@ -48,7 +48,7 @@ * The TRACE level was introduced in log4j version 1.2.12. In order to avoid * crashing the host application, in the case the log4j version in use predates * 1.2.12, the TRACE level will be mapped as DEBUG. See also bug 68. + * href="http://jira.qos.ch/browse/SLF4J-59">SLF4J-59. * * @author Ceki Gülcü */ diff --git a/slf4j-log4j12/src/test/java/org/slf4j/InvocationTest.java b/slf4j-log4j12/src/test/java/org/slf4j/InvocationTest.java index 0b6c3ec..8bf3453 100644 --- a/slf4j-log4j12/src/test/java/org/slf4j/InvocationTest.java +++ b/slf4j-log4j12/src/test/java/org/slf4j/InvocationTest.java @@ -24,12 +24,18 @@ */ package org.slf4j; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import java.util.HashMap; import java.util.Map; import org.apache.log4j.spi.LoggingEvent; - -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Test whether invoking the SLF4J API causes problems or not. @@ -37,33 +43,31 @@ * @author Ceki Gulcu * */ -public class InvocationTest extends TestCase { +public class InvocationTest { ListAppender listAppender = new ListAppender(); org.apache.log4j.Logger root; - public InvocationTest(String arg0) { - super(arg0); + + @Before + public void setUp() throws Exception { + root = org.apache.log4j.Logger.getRootLogger(); + root.addAppender(listAppender); } - protected void setUp() throws Exception { - super.setUp(); - root = org.apache.log4j.Logger.getRootLogger(); - root.addAppender(listAppender); - - } - - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { root.getLoggerRepository().resetConfiguration(); } - + + @Test public void test1() { Logger logger = LoggerFactory.getLogger("test1"); logger.debug("Hello world."); assertEquals(1, listAppender.list.size()); } + @Test public void test2() { Integer i1 = new Integer(1); Integer i2 = new Integer(2); @@ -90,6 +94,7 @@ assertEquals(11, listAppender.list.size()); } + @Test public void testNull() { Logger logger = LoggerFactory.getLogger("testNull"); logger.trace(null); @@ -106,18 +111,22 @@ assertEquals(8, listAppender.list.size()); } - // http://bugzilla.slf4j.org/show_bug.cgi?id=78 + // http://jira.qos.ch/browse/SLF4J-69 + // formerly http://bugzilla.slf4j.org/show_bug.cgi?id=78 + @Test public void testNullParameter_BUG78() { Logger logger = LoggerFactory.getLogger("testNullParameter_BUG78"); String[] parameters = null; String msg = "hello {}"; - logger.debug(msg, parameters); + logger.debug(msg, (Object[]) parameters); + assertEquals(1, listAppender.list.size()); LoggingEvent e = (LoggingEvent) listAppender.list.get(0); assertEquals(msg, e.getMessage()); } + @Test public void testMarker() { Logger logger = LoggerFactory.getLogger("testMarker"); Marker blue = MarkerFactory.getMarker("BLUE"); @@ -139,6 +148,7 @@ assertEquals(12, listAppender.list.size()); } + @Test public void testMDC() { MDC.put("k", "v"); assertNotNull(MDC.get("k")); @@ -159,6 +169,7 @@ } } + @Test public void testMDCContextMapValues() { Map map = new HashMap(); map.put("ka", "va"); diff --git a/slf4j-log4j12/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java b/slf4j-log4j12/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java index 7dbad78..9a3fa5d 100644 --- a/slf4j-log4j12/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java +++ b/slf4j-log4j12/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java @@ -26,28 +26,29 @@ import java.util.Random; -import junit.framework.TestCase; - +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -public class RecursiveInitializationTest extends TestCase { +public class RecursiveInitializationTest { // value of LogManager.DEFAULT_CONFIGURATION_KEY; static String CONFIG_FILE_KEY = "log4j.configuration"; int diff = new Random().nextInt(10000); - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { System.setProperty(CONFIG_FILE_KEY, "recursiveInit.properties"); - super.setUp(); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { System.clearProperty(CONFIG_FILE_KEY); - super.tearDown(); } + @Test public void testLog4j() { Logger logger = LoggerFactory.getLogger("x" + diff); System.out.println("logger class=" + logger.getClass().getName()); diff --git a/slf4j-migrator/pom.xml b/slf4j-migrator/pom.xml index 886c88a..3ae6c11 100644 --- a/slf4j-migrator/pom.xml +++ b/slf4j-migrator/pom.xml @@ -1,14 +1,13 @@ - + + 4.0.0 org.slf4j slf4j-parent - 1.7.12 + 1.7.13 slf4j-migrator @@ -17,30 +16,4 @@ SLF4J Migrator SLF4J Migrator - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${required.jdk.version} - ${required.jdk.version} - - - - - org.apache.maven.plugins - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - - - diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/helper/Abbreviator.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/helper/Abbreviator.java index ada9d26..3322642 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/helper/Abbreviator.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/helper/Abbreviator.java @@ -48,7 +48,7 @@ return filename; } StringBuilder buf = new StringBuilder(desiredLength); - buf.append(filename.substring(0, firstIndex + 1)); + buf.append(filename, 0, firstIndex + 1); buf.append(FILLER); int nextIndex = computeNextIndex(filename, firstIndex); if (nextIndex != -1) { diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/FileConverterTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/FileConverterTest.java index 2b9c98f..a2b5bc4 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/FileConverterTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/FileConverterTest.java @@ -27,29 +27,15 @@ import java.io.File; import java.io.IOException; -import junit.framework.TestCase; - -import org.slf4j.migrator.InplaceFileConverter; +import org.junit.Ignore; +import org.junit.Test; import org.slf4j.migrator.internal.NopProgressListener; import org.slf4j.migrator.line.EmptyRuleSet; +public class FileConverterTest { -public class FileConverterTest extends TestCase { - public FileConverterTest(String arg0) { - super(arg0); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void test() { - } - + @Test + @Ignore public void XtestNOP() throws IOException { InplaceFileConverter fc = new InplaceFileConverter(new EmptyRuleSet(), new NopProgressListener()); fc.convert(new File("c:/varargs.txt")); diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/ProjectConverterTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/ProjectConverterTest.java index 68e999d..975355d 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/ProjectConverterTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/ProjectConverterTest.java @@ -26,17 +26,17 @@ import java.io.File; -import org.slf4j.migrator.Constant; -import org.slf4j.migrator.ProjectConverter; +import org.junit.Ignore; +import org.junit.Test; import org.slf4j.migrator.internal.NopProgressListener; -import junit.framework.TestCase; - -public class ProjectConverterTest extends TestCase { +public class ProjectConverterTest { public void test() { } + @Test + @Ignore public void XtestBarracuda() { ProjectConverter pc = new ProjectConverter(Constant.LOG4J_TO_SLF4J, new NopProgressListener()); File projectFolder = new File("c:/home/ceki//Varia/Barracuda"); diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/AbbreviatorTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/AbbreviatorTest.java index a4a461b..106aaf9 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/AbbreviatorTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/AbbreviatorTest.java @@ -24,11 +24,11 @@ */ package org.slf4j.migrator.helper; -import org.slf4j.migrator.helper.Abbreviator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; - -public class AbbreviatorTest extends TestCase { +import org.junit.Test; +public class AbbreviatorTest { static final char FS = '/'; static final String INPUT_0 = "/abc/123456/ABC"; @@ -36,18 +36,7 @@ RandomHelper rh = new RandomHelper(FS); - public AbbreviatorTest(String arg0) { - super(arg0); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testSmoke() { { Abbreviator abb = new Abbreviator(2, 100, FS); @@ -67,6 +56,7 @@ } } + @Test public void testImpossibleToAbbreviate() { Abbreviator abb = new Abbreviator(2, 20, FS); String in = "iczldqwivpgm/mgrmvbjdxrwmqgprdjusth"; @@ -74,6 +64,7 @@ assertEquals(in, r); } + @Test public void testNoFS() { Abbreviator abb = new Abbreviator(2, 100, FS); String r = abb.abbreviate("hello"); @@ -81,6 +72,7 @@ } + @Test public void testZeroPrefix() { { Abbreviator abb = new Abbreviator(0, 100, FS); @@ -89,6 +81,7 @@ } } + @Test public void testTheories() { int MAX_RANDOM_FIXED_LEN = 20; int MAX_RANDOM_AVG_LEN = 20; diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/JCLRuleSetTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/JCLRuleSetTest.java index 351a13c..a1f28e9 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/JCLRuleSetTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/JCLRuleSetTest.java @@ -24,15 +24,14 @@ */ package org.slf4j.migrator.line; -import org.slf4j.migrator.line.JCLRuleSet; -import org.slf4j.migrator.line.LineConverter; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; - -public class JCLRuleSetTest extends TestCase { +import org.junit.Test; +public class JCLRuleSetTest { LineConverter jclConverter = new LineConverter(new JCLRuleSet()); + @Test public void testImportReplacement() { // LogFactory import replacement assertEquals("import org.slf4j.LoggerFactory;", jclConverter.getOneLineReplacement("import org.apache.commons.logging.LogFactory;")); @@ -40,6 +39,8 @@ assertEquals("import org.slf4j.Logger;", jclConverter.getOneLineReplacement("import org.apache.commons.logging.Log;")); } + + @Test public void testLogFactoryGetLogReplacement() { // Logger declaration and instanciation without modifier assertEquals(" Logger l = LoggerFactory.getLogger(MyClass.class);", @@ -65,6 +66,7 @@ jclConverter.getOneLineReplacement("// myLog = LogFactory.getLog(MyClass.class);//logger instanciation")); } + @Test public void testLogFactoryGetFactoryReplacement() { // Logger declaration and instanciation without modifier @@ -91,6 +93,8 @@ jclConverter.getOneLineReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation")); } + + @Test public void testLogDeclarationReplacement() { // simple Logger declaration @@ -106,6 +110,7 @@ assertEquals("//private Logger myLog;", jclConverter.getOneLineReplacement("//private Log myLog;")); } + @Test public void testMultiLineReplacement() { // Logger declaration on a line assertEquals("protected Logger log =", jclConverter.getOneLineReplacement("protected Log log =")); diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/NoConversionTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/NoConversionTest.java index e8f1f98..616f5df 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/NoConversionTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/NoConversionTest.java @@ -24,18 +24,16 @@ */ package org.slf4j.migrator.line; -import org.slf4j.migrator.line.JCLRuleSet; -import org.slf4j.migrator.line.LineConverter; -import org.slf4j.migrator.line.Log4jRuleSet; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; - -public class NoConversionTest extends TestCase { +import org.junit.Test; +public class NoConversionTest { /** * This test shows that performing JCL to SLF4J conversion has no impact on * Log4j implementation */ + @Test public void testJclOverLog4jConversion() { // running jcl to slf4j conversion // JCLMatcher jclMatcher = @@ -56,6 +54,7 @@ * This test shows that performing Log4j to SLF4J conversion has no impact on * JCL implementation */ + @Test public void testLog4jOverJclConversion() { // running log4j to slf4j conversion LineConverter log4jConverter = new LineConverter(new Log4jRuleSet()); diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcherTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcherTest.java index 36c42b5..bdb0ded 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcherTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcherTest.java @@ -24,12 +24,13 @@ */ package org.slf4j.migrator.line; -import org.slf4j.migrator.line.LineConverter; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.junit.Test; -public class TrivialMatcherTest extends TestCase { +public class TrivialMatcherTest { + @Test public void testSimpleReplacement() { LineConverter trivialLC = new LineConverter(new TrivialMatcher()); diff --git a/slf4j-nop/pom.xml b/slf4j-nop/pom.xml index 160dceb..1602c26 100644 --- a/slf4j-nop/pom.xml +++ b/slf4j-nop/pom.xml @@ -1,14 +1,13 @@ - + + 4.0.0 org.slf4j slf4j-parent - 1.7.12 + 1.7.13 slf4j-nop @@ -18,7 +17,6 @@ SLF4J NOP Binding http://www.slf4j.org - org.slf4j @@ -26,25 +24,4 @@ - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - - diff --git a/slf4j-nop/src/test/java/org/slf4j/InvocationTest.java b/slf4j-nop/src/test/java/org/slf4j/InvocationTest.java index adca421..037bde1 100644 --- a/slf4j-nop/src/test/java/org/slf4j/InvocationTest.java +++ b/slf4j-nop/src/test/java/org/slf4j/InvocationTest.java @@ -24,9 +24,9 @@ */ package org.slf4j; -import java.io.Closeable; -import java.io.IOException; -import junit.framework.TestCase; +import static org.junit.Assert.assertNull; + +import org.junit.Test; /** * Test whether invoking the SLF4J API causes problems or not. @@ -34,25 +34,15 @@ * @author Ceki Gulcu * */ -public class InvocationTest extends TestCase { +public class InvocationTest { - public InvocationTest(String arg0) { - super(arg0); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void test1() { Logger logger = LoggerFactory.getLogger("test1"); logger.debug("Hello world."); } + @Test public void test2() { Integer i1 = new Integer(1); Integer i2 = new Integer(2); @@ -76,6 +66,7 @@ logger.error("Hello world 4.", e); } + @Test public void testNull() { Logger logger = LoggerFactory.getLogger("testNull"); logger.debug(null); @@ -90,6 +81,7 @@ logger.error(null, e); } + @Test public void testMarker() { Logger logger = LoggerFactory.getLogger("testMarker"); Marker blue = MarkerFactory.getMarker("BLUE"); @@ -109,6 +101,7 @@ logger.error(blue, "hello {} and {} ", "world", "universe"); } + @Test public void testMDC() { MDC.put("k", "v"); assertNull(MDC.get("k")); @@ -117,6 +110,7 @@ MDC.clear(); } + @Test public void testMDCCloseable() { MDC.MDCCloseable closeable = MDC.putCloseable("k", "v"); assertNull(MDC.get("k")); diff --git a/slf4j-simple/pom.xml b/slf4j-simple/pom.xml index f8ce3cd..544a3fa 100644 --- a/slf4j-simple/pom.xml +++ b/slf4j-simple/pom.xml @@ -1,3 +1,4 @@ + @@ -6,7 +7,7 @@ org.slf4j slf4j-parent - 1.7.12 + 1.7.13 slf4j-simple @@ -22,26 +23,4 @@ - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - ${parsedVersion.osgiVersion} - ${project.description} - ${project.version} - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - - - diff --git a/slf4j-simple/src/test/java/org/slf4j/DetectLoggerNameMismatchTest.java b/slf4j-simple/src/test/java/org/slf4j/DetectLoggerNameMismatchTest.java index 545918c..10939e1 100644 --- a/slf4j-simple/src/test/java/org/slf4j/DetectLoggerNameMismatchTest.java +++ b/slf4j-simple/src/test/java/org/slf4j/DetectLoggerNameMismatchTest.java @@ -80,6 +80,7 @@ public void testTriggerWithProperty() { setTrialEnabled(true); LoggerFactory.getLogger(String.class); + String s = String.valueOf(byteArrayOutputStream); assertMismatchDetected(true); } @@ -90,8 +91,9 @@ public void testTriggerWholeMessage() { setTrialEnabled(true); LoggerFactory.getLogger(String.class); - assertTrue("Actual value of byteArrayOutputStream: " + String.valueOf(byteArrayOutputStream), String.valueOf(byteArrayOutputStream).contains( - "Detected logger name mismatch. Given name: \"java.lang.String\"; " + "computed name: \"org.slf4j.DetectLoggerNameMismatchTest\".")); + boolean success = String.valueOf(byteArrayOutputStream).contains( + "Detected logger name mismatch. Given name: \"java.lang.String\"; " + "computed name: \"org.slf4j.DetectLoggerNameMismatchTest\"."); + assertTrue("Actual value of byteArrayOutputStream: " + String.valueOf(byteArrayOutputStream), success); } /* diff --git a/slf4j-simple/src/test/java/org/slf4j/InvocationTest.java b/slf4j-simple/src/test/java/org/slf4j/InvocationTest.java index e25051f..d21dfe2 100644 --- a/slf4j-simple/src/test/java/org/slf4j/InvocationTest.java +++ b/slf4j-simple/src/test/java/org/slf4j/InvocationTest.java @@ -24,9 +24,13 @@ */ package org.slf4j; +import static org.junit.Assert.assertNull; + import java.io.PrintStream; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Test whether invoking the SLF4J API causes problems or not. @@ -34,29 +38,28 @@ * @author Ceki Gulcu * */ -public class InvocationTest extends TestCase { +public class InvocationTest { PrintStream old = System.err; - public InvocationTest(String arg0) { - super(arg0); - } - - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { System.setErr(new SilentPrintStream(old)); } - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { + System.setErr(old); } + @Test public void test1() { Logger logger = LoggerFactory.getLogger("test1"); logger.debug("Hello world."); } + @Test public void test2() { Integer i1 = new Integer(1); Integer i2 = new Integer(2); @@ -80,14 +83,17 @@ logger.error("Hello world 4.", e); } - // http://bugzilla.slf4j.org/show_bug.cgi?id=78 + // http://jira.qos.ch/browse/SLF4J-69 + // formerly http://bugzilla.slf4j.org/show_bug.cgi?id=78 + @Test public void testNullParameter_BUG78() { Logger logger = LoggerFactory.getLogger("testNullParameter_BUG78"); String[] parameters = null; String msg = "hello {}"; - logger.info(msg, parameters); + logger.info(msg, (Object[]) parameters); } + @Test public void testNull() { Logger logger = LoggerFactory.getLogger("testNull"); logger.debug(null); @@ -102,6 +108,7 @@ logger.error(null, e); } + @Test public void testMarker() { Logger logger = LoggerFactory.getLogger("testMarker"); Marker blue = MarkerFactory.getMarker("BLUE"); @@ -121,6 +128,7 @@ logger.error(blue, "hello {} and {} ", "world", "universe"); } + @Test public void testMDC() { MDC.put("k", "v"); assertNull(MDC.get("k"));