1 package net.sourceforge.javalogging.test; 2 3 import java.util.logging.*; 4 import junit.framework.*; 5 6 public class TestLogRecordLoggerName extends TestCase { 7 8 public static void main( String [] args ) { 9 TestSuite suite = new TestSuite( TestLogRecordLoggerName.class ); 10 TestResult results = new TestResult(); 11 suite.run( results ); 12 if ( results.errorCount() > 0 || results.failureCount() > 0 ) { 13 System.err.println( "FAIL" ); 14 System.err.println( results ); 15 } 16 else { 17 System.err.println( "PASS" ); 18 } 19 } 20 21 public TestLogRecordLoggerName( String name ) { 22 super( name ); 23 } 24 25 public void testGetLoggerName() { 26 LogRecord record = new LogRecord( Level.INFO, "The message." ); 27 assertTrue( "Logger name didn't start out null!", record.getLoggerName() == null ); 28 Logger l = Logger.getLogger( this.getClass().getName() ); 29 final String name = l.getName(); 30 assertEquals( "Logger's name isn't right!", name, this.getClass().getName() ); 31 l.setUseParentHandlers( false ); 32 Handler checkingHandler = new Handler() { 33 public void publish( LogRecord record ) { 34 String loggerName = record.getLoggerName(); 35 assertEquals( "Record's logger name wasn't right!", name, loggerName ); 36 } 37 38 public void flush() { 39 } 40 41 public void close() { 42 } 43 44 }; 45 l.addHandler( checkingHandler ); 46 l.log( record ); 47 } 48 49 } | Popular Tags |