1   /*
2      Copyright 2002-2006 Martin van den Bemt
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15  */
16  package org.xulux.logging;
17  
18  import junit.framework.TestCase;
19  
20  import org.apache.log4j.Logger;
21  
22  /**
23   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
24   * @version $Id: Log4jLoggerTest.java,v 1.1 2005/12/18 12:58:20 mvdb Exp $
25   */
26  
27  public class Log4jLoggerTest extends TestCase {
28  
29      static Log4jAppender appender = new Log4jAppender();
30      
31      static {
32          Logger logger = Logger.getRootLogger();
33          logger.addAppender(appender);
34      }
35      
36      /**
37       * Constructor for Log4jLoggerTest.
38       * @param name the name of the test
39       */
40      public Log4jLoggerTest(String name) {
41          super(name);
42      }
43      
44      public void testInitDestroy() {
45          System.out.println("testInitDestroy");
46          Log4jLogger ll = new Log4jLogger();
47          ll.init();
48          ll.destroy();
49      }
50  
51      public void testLog() {
52          System.out.println("testLog");
53          Log4jLogger log = new Log4jLogger();
54          log.log(0, null, null);
55          log.log(0, "test", null);
56          assertEquals(1,appender.getLogList().size());
57      }
58      
59      public void testLogException() {
60          System.out.println("testLogException");
61          Log4jLogger log = new Log4jLogger();
62          log.log(0, null, null, null);
63          log.log(0, "test", null, null);
64          assertEquals(1, appender.getLogList().size());
65      }
66  
67      protected void tearDown() throws Exception {
68          // reset the logging data..
69          appender.close();
70      }
71  }