[slf4j-dev] svn commit: r1163 - slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext

ceki at slf4j.org ceki at slf4j.org
Thu Oct 2 17:38:39 CEST 2008


Author: ceki
Date: Thu Oct  2 17:38:39 2008
New Revision: 1163

Added:
   slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/ListAppender.java
Modified:
   slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/XLoggerTest.java

Log:
- adding test cases as requested by Raph Goers in bug 104
  This is an intermediary commit (the test case does not pass). Complete fix
  to follow.

Added: slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/ListAppender.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/ListAppender.java	Thu Oct  2 17:38:39 2008
@@ -0,0 +1,30 @@
+package org.slf4j.ext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.spi.LoggingEvent;
+
+public class ListAppender extends AppenderSkeleton {
+
+  public List<LoggingEvent> list = new ArrayList<LoggingEvent>();
+  
+  public boolean extractLocationInfo = false;
+  
+  protected void append(LoggingEvent event) {
+    list.add(event);
+    if(extractLocationInfo) {
+      event.getLocationInformation();
+    }
+  }
+
+  public void close() {
+  }
+
+  public boolean requiresLayout() {
+    return false;
+  }
+
+}
+

Modified: slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/XLoggerTest.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/XLoggerTest.java	(original)
+++ slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/XLoggerTest.java	Thu Oct  2 17:38:39 2008
@@ -2,15 +2,107 @@
 
 import junit.framework.TestCase;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.spi.LoggingEvent;
 
 public class XLoggerTest extends TestCase {
 
-  Logger logger = LoggerFactory.getLogger(this.getClass());
-  
-  public void testSmoke() {
-    XLogger xLogger = new XLogger(logger);
-    xLogger.entry(logger);
+  ListAppender listAppender;
+  org.apache.log4j.Logger log4jRoot;
+
+  public XLoggerTest(String name) {
+    super(name);
+  }
+
+  public void setUp() throws Exception {
+    super.setUp();
+
+    // start from a clean slate for each test
+
+    listAppender = new ListAppender();
+    listAppender.extractLocationInfo = true;
+    log4jRoot = org.apache.log4j.Logger.getRootLogger();
+    log4jRoot.addAppender(listAppender);
+    log4jRoot.setLevel(org.apache.log4j.Level.TRACE);
+  }
+
+  public void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  public void testEntering() {
+    XLogger logger = XLoggerFactory.getXLogger("UnitTest");
+    logger.entry();
+    logger.entry(1);
+    logger.entry("test");
+
+    assertEquals(3, listAppender.list.size());
+
+    LoggingEvent le0 = (LoggingEvent) listAppender.list.get(0);
+    assertEquals("entry", le0.getMessage());
+    System.out.println("*********"+le0.getLocationInformation().fullInfo);
+
+    assertEquals("XLoggerTest.java", le0.getLocationInformation().getFileName());
+    LoggingEvent le1 = (LoggingEvent) listAppender.list.get(1);
+    assertEquals("entry with (1)", le1.getMessage());
+
+    LoggingEvent le2 = (LoggingEvent) listAppender.list.get(2);
+    assertEquals("entry with (test)", le2.getMessage());
+  }
+
+  public void testExiting() {
+    XLogger logger = XLoggerFactory.getXLogger("UnitTest");
+    logger.exit();
+    // assertEquals("exit", logMessage);
+    // logger.exit(0);
+    // assertEquals("exit 0", logMessage);
+    // logger.exit(false);
+    // assertEquals("exit false", logMessage);
+  }
+
+  public void testThrowing() {
+    XLogger logger = XLoggerFactory.getXLogger("UnitTest");
+    logger.throwing(new UnsupportedOperationException("Test"));
+    // assertTrue(logMessage.startsWith("throwing
+    // java.lang.UnsupportedOperationException:"));
   }
+
+  public void testCaught() {
+    XLogger logger = XLoggerFactory.getXLogger("UnitTest");
+    long x = 5;
+    try {
+      @SuppressWarnings("unused")
+      long y = x / 0;
+    } catch (Exception ex) {
+      logger.catching(ex);
+    }
+    // assertTrue(logMessage.startsWith("caught
+    // java.lang.ArithmeticException:"));
+  }
+
+  // public void testDump() {
+  // XLogger logger = XLoggerFactory.getXLogger("UnitTest");
+  // String dumpData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Document>\n
+  // <Data>Test</Data>\n</Document>";
+  // logger.
+  //    
+  // dump(logger, dumpData.getBytes());
+  // String expected = "3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31";
+  // assertTrue(logMessage.trim().startsWith(expected));
+  // }
+
+  // public void testTimer() {
+  // Timer timer = new Timer("TestTimer");
+  // LoggerUtil.startTimer(timer);
+  // assertEquals("Timer TestTimer started", logMessage);
+  // LoggerUtil.pauseTimer(timer);
+  // assertEquals("Timer TestTimer paused", logMessage);
+  // LoggerUtil.resumeTimer(timer);
+  // assertEquals("Timer TestTimer resumed", logMessage);
+  // LoggerUtil.stopTimer(timer);
+  // String expected = "Timer TestTimer stopped. Elapsed time:";
+  // assertTrue("Expected \"" + expected + "\" Result \"" + logMessage + "\"",
+  // logMessage.startsWith(expected));
+  // }
+
 }



More information about the slf4j-dev mailing list