KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > javalogging > test > TestParenting


1 package net.sourceforge.javalogging.test;
2
3 import java.util.logging.*;
4 import junit.framework.*;
5
6 public class TestParenting extends TestCase {
7
8     public static void main( String JavaDoc[] args ) {
9         TestSuite suite = new TestSuite( TestParenting.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 TestParenting( String JavaDoc name ) {
22         super( name );
23     }
24
25     public void testDefaultParent() {
26         Logger a_b_c = Logger.getLogger( "a.b.c" );
27         Logger root = Logger.getLogger( "" );
28         assertTrue( "Default parent wasn't the root!", a_b_c.getParent() == root );
29     }
30
31     public void testAddChild() {
32         Logger a_b_c = Logger.getLogger( "a.b.c" );
33         Logger a_b = Logger.getLogger( "a.b" );
34         assertTrue ( "a.b.c didn't get reparented to a.b!", a_b_c.getParent() == a_b );
35     }
36
37     public void testDefaultLevel() {
38         Logger a_b_c = Logger.getLogger( "a.b.c" );
39         Logger root = Logger.getLogger( "" );
40         root.setLevel( Level.WARNING );
41         assertTrue ( "Default level wasn't null!", a_b_c.getLevel() == null );
42
43         Logger a_b = Logger.getLogger( "a.b" );
44         assertTrue ( "Default level wasn't null!", a_b.getLevel() == null );
45
46         a_b.setLevel( Level.FINE );
47         assertTrue ( "a.b.c didn't pick up level assigned to a.b!",
48             a_b_c.isLoggable( Level.FINE ) );
49         assertTrue ( "a.b.c didn't pick up level assigned to a.b!",
50             ! a_b_c.isLoggable( Level.FINER ) );
51
52         a_b.setLevel( null );
53         assertTrue ( "a.b.c didn't pick up root level when a.b's was null!",
54             a_b_c.isLoggable( Level.WARNING ) );
55         assertTrue ( "a.b.c didn't pick up root level when a.b's was null!",
56             ! a_b_c.isLoggable( Level.INFO ) );
57
58     }
59 }
Popular Tags