[slf4j-dev] svn commit: r1164 - in slf4j/trunk/slf4j-ext/src: main/java/org/slf4j/ext test/java/org/slf4j/dummyExt test/java/org/slf4j/ext

ceki at slf4j.org ceki at slf4j.org
Thu Oct 2 18:09:45 CEST 2008


Author: ceki
Date: Thu Oct  2 18:09:45 2008
New Revision: 1164

Added:
   slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/
      - copied from r1157, /slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/
   slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/ListAppender.java
      - copied, changed from r1163, /slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/ListAppender.java
   slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/XLoggerTest.java
      - copied, changed from r1163, /slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/XLoggerTest.java
   slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/package.html
Removed:
   slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/
Modified:
   slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java

Log:
- test cases pass. The tests are in a different package because
  log4j location information extraction code requires this.

Explanation:
  
Tests related to the org.slfj.ext package. However, location information code
required the caller class (XLogger) to have a different prefix than
the test class XLoggerTest. This is ensured by having the test class
placed in a different package.

Modified: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java	(original)
+++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java	Thu Oct  2 18:09:45 2008
@@ -25,7 +25,7 @@
   static Marker CATCHING_MARKER = MarkerFactory.getMarker("EXCEPTION");
 
   static String EXIT_MESSAGE_0 = "exit";
-  static String EXIT_MESSAGE_1 = "exit with {}";
+  static String EXIT_MESSAGE_1 = "exit with ({})";
 
   static String ENTRY_MESSAGE_0 = "entry";
   static String ENTRY_MESSAGE_1 = "entry with ({})";
@@ -96,7 +96,7 @@
    */
   public void exit(Object result) {
     if (instanceofLAL && logger.isTraceEnabled(ENTRY_MARKER)) {
-      String formattedMessage = MessageFormatter.format(EXIT_MESSAGE_0, result);
+      String formattedMessage = MessageFormatter.format(EXIT_MESSAGE_1, result);
       ((LocationAwareLogger) logger).log(EXIT_MARKER, FQCN,
           LocationAwareLogger.TRACE_INT, formattedMessage, null);
     }

Copied: slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/ListAppender.java (from r1163, /slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/ListAppender.java)
==============================================================================
--- /slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/ext/ListAppender.java	(original)
+++ slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/ListAppender.java	Thu Oct  2 18:09:45 2008
@@ -1,4 +1,4 @@
-package org.slf4j.ext;
+package org.slf4j.dummyExt;
 
 import java.util.ArrayList;
 import java.util.List;

Copied: slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/XLoggerTest.java (from r1163, /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/dummyExt/XLoggerTest.java	Thu Oct  2 18:09:45 2008
@@ -1,15 +1,18 @@
-package org.slf4j.ext;
+package org.slf4j.dummyExt;
 
 import junit.framework.TestCase;
 
-import org.apache.log4j.LogManager;
 import org.apache.log4j.spi.LoggingEvent;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
 
 public class XLoggerTest extends TestCase {
 
   ListAppender listAppender;
   org.apache.log4j.Logger log4jRoot;
-
+  
+  final static String EXPECTED_FILE_NAME = "XLoggerTest.java";
+  
   public XLoggerTest(String name) {
     super(name);
   }
@@ -30,6 +33,17 @@
     super.tearDown();
   }
 
+  
+  void verify(LoggingEvent le, String expectedMsg) {
+    assertEquals(expectedMsg, le.getMessage());
+    assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName());
+  }
+
+  void verifyWithException(LoggingEvent le, String expectedMsg, Throwable t) {
+    verify(le, expectedMsg);
+    assertEquals(t.toString(), le.getThrowableStrRep()[0]);
+  }
+  
   public void testEntering() {
     XLogger logger = XLoggerFactory.getXLogger("UnitTest");
     logger.entry();
@@ -37,47 +51,43 @@
     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());
-  }
+    verify((LoggingEvent) listAppender.list.get(0), "entry");
+    verify((LoggingEvent) listAppender.list.get(1), "entry with (1)");
+    verify((LoggingEvent) listAppender.list.get(2), "entry with (test)");
+   }
 
   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);
+    logger.exit(0);
+    logger.exit(false);
+    
+    assertEquals(3, listAppender.list.size());
+    verify((LoggingEvent) listAppender.list.get(0), "exit");
+    verify((LoggingEvent) listAppender.list.get(1), "exit with (0)");
+    verify((LoggingEvent) listAppender.list.get(2), "exit with (false)");
   }
 
   public void testThrowing() {
     XLogger logger = XLoggerFactory.getXLogger("UnitTest");
-    logger.throwing(new UnsupportedOperationException("Test"));
-    // assertTrue(logMessage.startsWith("throwing
-    // java.lang.UnsupportedOperationException:"));
+    Throwable t = new UnsupportedOperationException("Test");
+    logger.throwing(t);
+    assertEquals(1, listAppender.list.size());
+    verifyWithException((LoggingEvent) listAppender.list.get(0), "throwing", t);
   }
 
   public void testCaught() {
     XLogger logger = XLoggerFactory.getXLogger("UnitTest");
     long x = 5;
+    Throwable t = null;
     try {
       @SuppressWarnings("unused")
       long y = x / 0;
     } catch (Exception ex) {
+      t = ex;
       logger.catching(ex);
     }
-    // assertTrue(logMessage.startsWith("caught
-    // java.lang.ArithmeticException:"));
+    verifyWithException((LoggingEvent) listAppender.list.get(0), "catching", t);
   }
 
   // public void testDump() {
@@ -91,18 +101,5 @@
   // 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));
-  // }
 
 }

Added: slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/package.html
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/package.html	Thu Oct  2 18:09:45 2008
@@ -0,0 +1,4 @@
+Tests related to the org.slfj.ext package. However, location information code
+required the caller class (XLogger) to have a different prefix than
+the test class XLoggerTest. This is ensured by having the test class
+placed in a different package.
\ No newline at end of file



More information about the slf4j-dev mailing list