View Javadoc
1   package org.codehaus.plexus.logging;
2   
3   /*
4    * Copyright 2001-2006 Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import junit.framework.TestCase;
20  
21  /**
22   *
23   * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
24   * @version $Revision$ $Date$
25   */
26  public class LogEnabledTest
27      extends TestCase
28  {
29      public void testGetLogger()
30          throws Exception
31      {
32          MockLogEnabled logEnabled = new MockLogEnabled();
33          MockLogger logger = new MockLogger( "base" );
34          logEnabled.enableLogging( logger );
35          assertEquals( "logger", logger, logEnabled.getLogger() );
36      }
37  
38      public void testSetupLoggerOnLogEnabled()
39          throws Exception
40      {
41          MockLogEnabled logEnabled = new MockLogEnabled();
42          MockLogEnabled childLogEnabled = new MockLogEnabled();
43          MockLogger logger = new MockLogger( "base" );
44          logEnabled.enableLogging( logger );
45          logEnabled.setupLogger( childLogEnabled );
46          assertEquals( "logEnabled.logger", logger, logEnabled.getLogger() );
47          assertEquals( "childLogEnabled.logger", logger, childLogEnabled.getLogger() );
48      }
49  
50      public void testSetupLoggerOnNonLogEnabled()
51          throws Exception
52      {
53          MockLogEnabled logEnabled = new MockLogEnabled();
54          MockLogger logger = new MockLogger( "base" );
55          logEnabled.enableLogging( logger );
56          logEnabled.setupLogger( new Object() );
57      }
58  
59      public void testSetupLoggerWithNameOnLogEnabled()
60          throws Exception
61      {
62          MockLogEnabled logEnabled = new MockLogEnabled();
63          MockLogEnabled childLogEnabled = new MockLogEnabled();
64          MockLogger logger = new MockLogger( "base" );
65          logEnabled.enableLogging( logger );
66          logEnabled.setupLogger( childLogEnabled, "child" );
67          assertEquals( "logEnabled.logger", logger, logEnabled.getLogger() );
68          assertEquals( "childLogEnabled.logger.name",
69                        "base.child",
70                        ( (MockLogger) childLogEnabled.getLogger() ).getName() );
71      }
72  
73      public void testSetupLoggerWithNullName()
74          throws Exception
75      {
76          MockLogEnabled logEnabled = new MockLogEnabled();
77          MockLogEnabled childLogEnabled = new MockLogEnabled();
78          MockLogger logger = new MockLogger( "base" );
79          logEnabled.enableLogging( logger );
80          try
81          {
82              logEnabled.setupLogger( childLogEnabled, (String) null );
83          }
84          catch ( IllegalStateException npe )
85          {
86              return;
87          }
88          fail( "Expected to fail setting up child logger with null name" );
89      }
90  }