1 17 package org.apache.log.test; 18 19 import junit.framework.TestCase; 20 import org.apache.log.Hierarchy; 21 import org.apache.log.Logger; 22 23 28 public final class LoggerListenerTestCase 29 extends TestCase 30 { 31 public LoggerListenerTestCase( final String name ) 32 { 33 super( name ); 34 } 35 36 public void testUnicastLoggerListener() 37 { 38 final Hierarchy hierarchy = new Hierarchy(); 39 final RecordingLoggerListener listener = new RecordingLoggerListener(); 40 41 try 42 { 43 hierarchy.addLoggerListener( listener ); 44 hierarchy.addLoggerListener( listener ); 45 46 fail( "You should only be able to add one listener." ); 47 } 48 catch (UnsupportedOperationException uoe) 49 { 50 } 52 } 53 54 public void testRemoveLoggerListener() 55 { 56 final Hierarchy hierarchy = new Hierarchy(); 57 final RecordingLoggerListener listener = new RecordingLoggerListener(); 58 59 hierarchy.addLoggerListener( listener ); 60 hierarchy.removeLoggerListener( listener ); 61 hierarchy.addLoggerListener( listener ); 62 63 } 65 66 public void testPriorityInheritance() 67 throws Exception 68 { 69 final RecordingLoggerListener listener = new RecordingLoggerListener(); 70 final Hierarchy hierarchy = new Hierarchy(); 71 hierarchy.addLoggerListener( listener ); 72 73 final Logger root = hierarchy.getRootLogger(); 74 final Logger l1 = root.getChildLogger( "logger1" ); 75 final Logger l2 = root.getChildLogger( "logger2" ); 76 final Logger l3 = root.getChildLogger( "logger1.logger3" ); 77 final Logger l4 = root.getChildLogger( "logger5.logger4" ); 78 final Logger l5 = root.getChildLogger( "logger5" ); 79 80 final Logger[] loggers = listener.getLoggers(); 81 assertEquals( "Logger Count", 5, loggers.length ); 82 assertEquals( "Logger[0]", l1, loggers[ 0 ] ); 83 assertEquals( "Logger[1]", l2, loggers[ 1 ] ); 84 assertEquals( "Logger[2]", l3, loggers[ 2 ] ); 85 assertEquals( "Logger[3]", l5, loggers[ 3 ] ); 86 assertEquals( "Logger[4]", l4, loggers[ 4 ] ); 87 } 88 } 89 | Popular Tags |