migrate test to Junit 4 conventions

This commit is contained in:
Ceki Gulcu 2015-11-06 14:38:39 +01:00
parent 18e6156c09
commit acfc07008b
40 changed files with 426 additions and 391 deletions

View File

@ -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 @@ public class InvokeJCLTest extends TestCase {
assertTrue(log.isFatalEnabled());
}
@Test
public void testPrintAPI() {
Log log = LogFactory.getLog(InvokeJCLTest.class);
Exception e = new Exception("just testing");

View File

@ -30,30 +30,27 @@ import java.io.IOException;
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);
}
protected void setUp() throws Exception {
@Before
public 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 @@ public class SerializationTest extends TestCase {
resuscitatedLog.isDebugEnabled();
}
@Test
public void testSLF4JLog() throws Exception {
JDK14LoggerFactory factory = new JDK14LoggerFactory();
SLF4JLog log = new SLF4JLog(factory.getLogger("x"));
@ -74,12 +72,14 @@ public class SerializationTest extends TestCase {
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"));

View File

@ -27,13 +27,13 @@ package org.slf4j.bridge;
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 @@ public class SLF4JBridgeHandlerPerfTest extends TestCase {
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 @@ public class SLF4JBridgeHandlerPerfTest extends TestCase {
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 @@ public class SLF4JBridgeHandlerPerfTest extends TestCase {
return (end - start) * 1.0 / RUN_LENGTH;
}
@Test
public void testPerf() {
SLF4JBridgeHandler.install();

View File

@ -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 @@ public class SLF4JBridgeHandlerTest extends TestCase {
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 @@ public class SLF4JBridgeHandlerTest extends TestCase {
assertEquals("testSmoke", li.getMethodName());
}
@Test
public void testLevels() {
SLF4JBridgeHandler.install();
String msg = "msg";
@ -100,6 +101,7 @@ public class SLF4JBridgeHandlerTest extends TestCase {
assertLevel(i++, org.apache.log4j.Level.ERROR);
}
@Test
public void testLogWithResourceBundle() {
SLF4JBridgeHandler.install();
@ -118,6 +120,7 @@ public class SLF4JBridgeHandlerTest extends TestCase {
assertEquals(expectedMsg, le.getMessage());
}
@Test
public void testLogWithResourceBundleWithParameters() {
SLF4JBridgeHandler.install();
@ -163,6 +166,7 @@ public class SLF4JBridgeHandlerTest extends TestCase {
assertEquals(expectedMsg3, le.getMessage());
}
@Test
public void testLogWithPlaceholderNoParameters() {
SLF4JBridgeHandler.install();
String msg = "msg {non-number-string}";

View File

@ -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();

View File

@ -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();

View File

@ -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("");

View File

@ -28,7 +28,6 @@ import java.io.IOException;
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;

View File

@ -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 @@ import org.slf4j.helpers.BasicMarkerFactory;
* @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 @@ public class BasicMarkerTest extends TestCase {
multiComp.add(comp);
}
@Test
public void testPrimitive() {
assertEquals(BLUE_STR, blue.getName());
assertTrue(blue.contains(blue));
@ -80,20 +82,24 @@ public class BasicMarkerTest extends TestCase {
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 @@ public class BasicMarkerTest extends TestCase {
assertFalse(multiComp.contains(red));
}
@Test
public void testMultiCompositeByName() {
assertTrue(multiComp.contains(COMP_STR));
assertTrue(multiComp.contains(BLUE_STR));
@ -108,6 +115,7 @@ public class BasicMarkerTest extends TestCase {
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 @@ public class BasicMarkerTest extends TestCase {
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 @@ public class BasicMarkerTest extends TestCase {
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 @@ public class BasicMarkerTest extends TestCase {
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 @@ public class BasicMarkerTest extends TestCase {
assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR));
}
@Test
public void testHomonyms() {
final String diffPrefix = "homonym" + diff;
final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;

View File

@ -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);

View File

@ -24,112 +24,125 @@
package org.slf4j.helpers;
import junit.framework.TestCase;
import org.slf4j.spi.MDCAdapter;
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 extends TestCase {
MDCAdapter mdc = new BasicMDCAdapter();
public class BasicMDCAdapterTest {
MDCAdapter mdc = new BasicMDCAdapter();
@Override
protected void tearDown() throws Exception {
mdc.clear();
}
@After
public void tearDown() throws Exception {
mdc.clear();
}
public void testSettingAndGettingWithMDC() {
assertNull(mdc.get("testKey"));
mdc.put("testKey", "testValue");
assertEquals(mdc.get("testKey"), "testValue");
}
@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");
}
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());
}
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<String, String> copy = mdc.getCopyOfContextMap();
mdc.put("anotherTestKey", "anotherTestValue");
assertFalse(copy.size() == mdc.getCopyOfContextMap().size());
}
public void testGetCopyOfContextMapFromMDC() {
mdc.put("testKey", "testValue");
Map<String, String> 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"));
}
});
}
public void testMDCInheritsValuesFromParentThread() throws Exception {
mdc.put("parentKey", "parentValue");
runAndWait(new Runnable() {
public void run() {
mdc.put("childKey", "childValue");
@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"));
}
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"));
}
public void testMDCChildThreadCanOverwriteParentThread() throws Exception {
mdc.put("sharedKey", "parentValue");
runAndWait(new Runnable() {
public void run() {
@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"));
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;
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());
}
String getMessage() {
return exception != null ? exception.getMessage() : "";
/** 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() : "";
}
}
}
}

View File

@ -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 @@ import junit.framework.TestCase;
* @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 @@ public class BubbleSortTest extends TestCase {
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 @@ public class BubbleSortTest extends TestCase {
assertEquals(3000, a[i++]);
}
@Test
public void testInverted() {
int[] a = new int[] { 3000, 300, 30, 3 };
BubbleSort.sort(a);
@ -72,6 +79,7 @@ public class BubbleSortTest extends TestCase {
assertEquals(3000, a[i++]);
}
@Test
public void testWithSameEntry() {
int[] a = new int[] { 10, 20, 10, 20 };
BubbleSort.sort(a);
@ -82,6 +90,7 @@ public class BubbleSortTest extends TestCase {
assertEquals(20, a[i++]);
}
@Test
public void testRandom() {
int len = 100;
Random random = new Random(156);

View File

@ -26,11 +26,11 @@ package org.slf4j.helpers;
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 @@ public class MessageFormatterPerfTest extends TestCase {
//
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 @@ public class MessageFormatterPerfTest extends TestCase {
BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
}
@Test
public void testSLF4JPerf_TwoArg() {
slf4jMessageFormatter_TwoArg(RUN_LENGTH);
double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH);

View File

@ -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.HashSet;
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<String> EXCLUDED_METHODS = new HashSet<String>(Arrays.asList("getName"));
@Test
public void testDelegate() throws Exception {
SubstituteLogger log = new SubstituteLogger("foo");
assertTrue(log.delegate() instanceof NOPLogger);

View File

@ -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 @@ public class SubstituteLoggerFactoryTest extends TestCase {
assertTrue("Loggers with same name must be same", log == log2);
}
@Test
public void testLoggerNameList() {
factory.getLogger("foo1");
factory.getLogger("foo2");
@ -52,6 +58,7 @@ public class SubstituteLoggerFactoryTest extends TestCase {
assertEquals(expectedNames, actualNames);
}
@Test
public void testLoggers() {
factory.getLogger("foo1");
factory.getLogger("foo2");

View File

@ -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");

View File

@ -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 @@ public class LocLoggerTest extends TestCase {
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 @@ public class LocLoggerTest extends TestCase {
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);

View File

@ -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 {
}

View File

@ -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 @@ public class EventLoggerTest extends TestCase {
}
@After
public void tearDown() throws Exception {
super.tearDown();
MDC.clear();
}
@ -77,7 +76,8 @@ public class EventLoggerTest extends TestCase {
assertEquals(expectedMsg, le.getMessage());
assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName());
}
@Test
public void testEventLogger() {
EventData data[] = new EventData[2];
data[0] = new EventData();

View File

@ -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");

View File

@ -26,13 +26,11 @@ package org.slf4j.dummyExt;
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 {
}

View File

@ -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
@ -54,10 +52,6 @@ public class XLoggerTest extends TestCase {
log4jRoot.setLevel(org.apache.log4j.Level.TRACE);
}
public void tearDown() throws Exception {
super.tearDown();
}
void verify(LoggingEvent le, String expectedMsg) {
assertEquals(expectedMsg, le.getMessage());
assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName());
@ -74,6 +68,7 @@ public class XLoggerTest extends TestCase {
assertEquals(le.getLevel().toString(), level.toString());
}
@Test
public void testEntering() {
XLogger logger = XLoggerFactory.getXLogger("UnitTest");
logger.entry();
@ -89,6 +84,7 @@ public class XLoggerTest extends TestCase {
verify((LoggingEvent) listAppender.list.get(2), "entry with (test)");
}
@Test
public void testExiting() {
XLogger logger = XLoggerFactory.getXLogger("UnitTest");
logger.exit();
@ -101,6 +97,7 @@ public class XLoggerTest extends TestCase {
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 @@ public class XLoggerTest extends TestCase {
verifyWithLevelAndException(event, XLogger.Level.DEBUG, "throwing", t);
}
@Test
public void testCaught() {
XLogger logger = XLoggerFactory.getXLogger("UnitTest");
long x = 5;
@ -130,6 +128,7 @@ public class XLoggerTest extends TestCase {
// 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 = 136; // requires update if line numbers change

View File

@ -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"));

View File

@ -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;
@RunWith(Suite.class)
@SuiteClasses({UtilTest.class,
ProfilerTest.class})
public class PackageTest {
public class PackageTest extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(UtilTest.class);
suite.addTestSuite(ProfilerTest.class);
return suite;
}
}

View File

@ -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 @@ public class ProfilerTest extends TestCase {
assertNull(profiler.getLastTimeInstrument());
}
@Test
public void testBasicProfiling() {
Profiler profiler = new Profiler("BAS");
@ -80,6 +80,7 @@ public class ProfilerTest extends TestCase {
// |-- 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");

View File

@ -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);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public class UtilTest {
@Test
public void testSelectDurationUnitForDisplay() throws InterruptedException {
assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(10));
assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(9 * Util.NANOS_IN_ONE_MICROSECOND));

View File

@ -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 @@ import junit.framework.TestCase;
* @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 @@ public class InvocationTest extends TestCase {
logger.error("Hello world 4.", e);
}
@Test
public void testNull() {
Logger logger = LoggerFactory.getLogger("testNull");
logger.debug(null);
@ -96,6 +100,7 @@ public class InvocationTest extends TestCase {
logger.error(null, e);
}
@Test
public void testMarker() {
Logger logger = LoggerFactory.getLogger("testMarker");
Marker blue = MarkerFactory.getMarker("BLUE");
@ -115,6 +120,7 @@ public class InvocationTest extends TestCase {
logger.error(blue, "hello {} and {} ", "world", "universe");
}
@Test
public void testMDC() {
MDC.put("k", "v");
assertNull(MDC.get("k"));

View File

@ -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");

View File

@ -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;

View File

@ -34,7 +34,7 @@ import java.io.Serializable;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory;
* 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 @@ public class LoggerSerializationTest extends TestCase {
}
}
@Test
public void testCanLoggerBeSerialized() throws IOException, ClassNotFoundException {
LoggerHolder lh1 = new LoggerHolder();

View File

@ -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 @@ import junit.framework.TestCase;
* @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);
}
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
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 @@ public class InvocationTest extends TestCase {
assertEquals(11, listAppender.list.size());
}
@Test
public void testNull() {
Logger logger = LoggerFactory.getLogger("testNull");
logger.trace(null);
@ -108,17 +113,20 @@ public class InvocationTest extends TestCase {
// 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");
@ -140,6 +148,7 @@ public class InvocationTest extends TestCase {
assertEquals(12, listAppender.list.size());
}
@Test
public void testMDC() {
MDC.put("k", "v");
assertNotNull(MDC.get("k"));
@ -160,6 +169,7 @@ public class InvocationTest extends TestCase {
}
}
@Test
public void testMDCContextMapValues() {
Map<String, String> map = new HashMap<String, String>();
map.put("ka", "va");

View File

@ -26,28 +26,29 @@ package org.slf4j.impl;
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());

View File

@ -27,29 +27,15 @@ package org.slf4j.migrator;
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"));

View File

@ -26,17 +26,17 @@ package org.slf4j.migrator;
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");

View File

@ -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 @@ public class AbbreviatorTest extends TestCase {
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 @@ public class AbbreviatorTest extends TestCase {
}
}
@Test
public void testImpossibleToAbbreviate() {
Abbreviator abb = new Abbreviator(2, 20, FS);
String in = "iczldqwivpgm/mgrmvbjdxrwmqgprdjusth";
@ -74,6 +64,7 @@ public class AbbreviatorTest extends TestCase {
assertEquals(in, r);
}
@Test
public void testNoFS() {
Abbreviator abb = new Abbreviator(2, 100, FS);
String r = abb.abbreviate("hello");
@ -81,6 +72,7 @@ public class AbbreviatorTest extends TestCase {
}
@Test
public void testZeroPrefix() {
{
Abbreviator abb = new Abbreviator(0, 100, FS);
@ -89,6 +81,7 @@ public class AbbreviatorTest extends TestCase {
}
}
@Test
public void testTheories() {
int MAX_RANDOM_FIXED_LEN = 20;
int MAX_RANDOM_AVG_LEN = 20;

View File

@ -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 @@ public class JCLRuleSetTest extends TestCase {
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 @@ public class JCLRuleSetTest extends TestCase {
jclConverter.getOneLineReplacement("// myLog = LogFactory.getLog(MyClass.class);//logger instanciation"));
}
@Test
public void testLogFactoryGetFactoryReplacement() {
// Logger declaration and instanciation without modifier
@ -91,6 +93,8 @@ public class JCLRuleSetTest extends TestCase {
jclConverter.getOneLineReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
}
@Test
public void testLogDeclarationReplacement() {
// simple Logger declaration
@ -106,6 +110,7 @@ public class JCLRuleSetTest extends TestCase {
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 ="));

View File

@ -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 @@ public class NoConversionTest extends TestCase {
* 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());

View File

@ -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());

View File

@ -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 @@ import junit.framework.TestCase;
* @author Ceki Gulcu
*
*/
public class InvocationTest extends TestCase {
public InvocationTest(String arg0) {
super(arg0);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public class InvocationTest {
@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 @@ public class InvocationTest extends TestCase {
logger.error("Hello world 4.", e);
}
@Test
public void testNull() {
Logger logger = LoggerFactory.getLogger("testNull");
logger.debug(null);
@ -90,6 +81,7 @@ public class InvocationTest extends TestCase {
logger.error(null, e);
}
@Test
public void testMarker() {
Logger logger = LoggerFactory.getLogger("testMarker");
Marker blue = MarkerFactory.getMarker("BLUE");
@ -109,6 +101,7 @@ public class InvocationTest extends TestCase {
logger.error(blue, "hello {} and {} ", "world", "universe");
}
@Test
public void testMDC() {
MDC.put("k", "v");
assertNull(MDC.get("k"));
@ -117,6 +110,7 @@ public class InvocationTest extends TestCase {
MDC.clear();
}
@Test
public void testMDCCloseable() {
MDC.MDCCloseable closeable = MDC.putCloseable("k", "v");
assertNull(MDC.get("k"));

View File

@ -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 @@ import junit.framework.TestCase;
* @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);
@ -82,13 +85,15 @@ public class InvocationTest extends TestCase {
// 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);
@ -103,6 +108,7 @@ public class InvocationTest extends TestCase {
logger.error(null, e);
}
@Test
public void testMarker() {
Logger logger = LoggerFactory.getLogger("testMarker");
Marker blue = MarkerFactory.getMarker("BLUE");
@ -122,6 +128,7 @@ public class InvocationTest extends TestCase {
logger.error(blue, "hello {} and {} ", "world", "universe");
}
@Test
public void testMDC() {
MDC.put("k", "v");
assertNull(MDC.get("k"));