[logback-dev] svn commit: r1624 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic/spi test/java/ch/qos/logback/classic/spi

noreply.ceki at qos.ch noreply.ceki at qos.ch
Tue Mar 4 11:51:19 CET 2008


Author: ceki
Date: Tue Mar  4 11:51:19 2008
New Revision: 1624

Added:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggerComparatorTest.java
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerComparator.java

Log:
- fixing bug #127  See http://bugzilla.qos.ch/show_bug.cgi?id=127 for further details

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerComparator.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerComparator.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerComparator.java	Tue Mar  4 11:51:19 2008
@@ -8,9 +8,15 @@
 public class LoggerComparator implements Comparator<Logger> {
 
   public int compare(Logger l1, Logger l2) {
+    if (l1.getName().equals(l2.getName())) {
+      return 0;
+    }
     if (l1.getName().equals(LoggerContext.ROOT_NAME)) {
       return -1;
     }
+    if (l2.getName().equals(LoggerContext.ROOT_NAME)) {
+      return 1;
+    }
     return l1.getName().compareTo(l2.getName());
   }
 

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggerComparatorTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggerComparatorTest.java	Tue Mar  4 11:51:19 2008
@@ -0,0 +1,38 @@
+package ch.qos.logback.classic.spi;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+
+
+public class LoggerComparatorTest {
+
+  LoggerComparator comparator = new LoggerComparator();
+  LoggerContext lc = new LoggerContext();
+
+  Logger root = lc.getLogger("root");
+
+  Logger a = lc.getLogger("a");
+  Logger b = lc.getLogger("b");
+
+  @Before
+  public void setUp() throws Exception {
+  
+  }
+
+  
+  
+  @Test
+  public void testSmoke() {
+    assertEquals(0, comparator.compare(a, a));
+    assertEquals(-1, comparator.compare(a, b));
+    assertEquals(1, comparator.compare(b, a));
+    assertEquals(-1, comparator.compare(root, a));
+    // following two tests failed before bug #127 was fixed
+    assertEquals(1, comparator.compare(a, root));
+    assertEquals(0, comparator.compare(root, root));
+  }
+}



More information about the logback-dev mailing list