KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > logging > BasicOperationsTestCase


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
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  
17 package org.apache.commons.logging;
18
19 import junit.framework.TestCase;
20
21 /**
22  * Tests the basic logging operations to ensure that they all function
23  * without exception failure. In other words, that they do no fail by
24  * throwing exceptions.
25  * This is the minimum requirement for any well behaved logger
26  * and so this test should be run for each kind.
27  */

28 public class BasicOperationsTestCase extends TestCase
29 {
30     public void testIsEnabledClassLog()
31     {
32         Log log = LogFactory.getLog(BasicOperationsTestCase.class);
33         executeIsEnabledTest(log);
34     }
35     
36     public void testIsEnabledNamedLog()
37     {
38         Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
39         executeIsEnabledTest(log);
40     }
41     
42     public void executeIsEnabledTest(Log log)
43     {
44         try
45         {
46             log.isTraceEnabled();
47             log.isDebugEnabled();
48             log.isInfoEnabled();
49             log.isWarnEnabled();
50             log.isErrorEnabled();
51             log.isFatalEnabled();
52         }
53         catch (Throwable JavaDoc t)
54         {
55             t.printStackTrace();
56             fail("Exception thrown: " + t);
57         }
58     }
59     
60     
61     public void testMessageWithoutExceptionClassLog()
62     {
63         Log log = LogFactory.getLog(BasicOperationsTestCase.class);
64         executeMessageWithoutExceptionTest(log);
65     }
66     
67     public void testMessageWithoutExceptionNamedLog()
68     {
69         Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
70         executeMessageWithoutExceptionTest(log);
71     }
72     
73     public void executeMessageWithoutExceptionTest(Log log)
74     {
75         try
76         {
77             log.trace("Hello, Mum");
78             log.debug("Hello, Mum");
79             log.info("Hello, Mum");
80             log.warn("Hello, Mum");
81             log.error("Hello, Mum");
82             log.fatal("Hello, Mum");
83         }
84         catch (Throwable JavaDoc t)
85         {
86             t.printStackTrace();
87             fail("Exception thrown: " + t);
88         }
89     }
90     
91     public void testMessageWithExceptionClassLog()
92     {
93         Log log = LogFactory.getLog(BasicOperationsTestCase.class);
94         executeMessageWithExceptionTest(log);
95     }
96     
97     public void testMessageWithExceptionNamedLog()
98     {
99         Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
100         executeMessageWithExceptionTest(log);
101     }
102     
103     public void executeMessageWithExceptionTest(Log log)
104     {
105         try
106         {
107             log.trace("Hello, Mum", new ArithmeticException JavaDoc());
108             log.debug("Hello, Mum", new ArithmeticException JavaDoc());
109             log.info("Hello, Mum", new ArithmeticException JavaDoc());
110             log.warn("Hello, Mum", new ArithmeticException JavaDoc());
111             log.error("Hello, Mum", new ArithmeticException JavaDoc());
112             log.fatal("Hello, Mum", new ArithmeticException JavaDoc());
113         }
114         catch (Throwable JavaDoc t)
115         {
116             t.printStackTrace();
117             fail("Exception thrown: " + t);
118         }
119     }
120 }
121
Popular Tags