KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > util > test > DeprecationTestCase


1 /*
2  * Copyright 1999-2004 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 package org.apache.cocoon.util.test;
17
18 import junit.framework.TestCase;
19
20 import org.apache.avalon.framework.logger.ConsoleLogger;
21 import org.apache.avalon.framework.logger.Logger;
22 import org.apache.cocoon.util.Deprecation;
23 import org.apache.cocoon.util.DeprecationException;
24
25 /**
26  * Test Cases for the Deprecation class.
27  * @see org.apache.cocoon.util.Deprecation
28  *
29  * @version $Id: DeprecationTestCase.java 157288 2005-03-12 22:42:07Z sylvain $
30  */

31 public class DeprecationTestCase extends TestCase {
32     public DeprecationTestCase(String JavaDoc name) {
33         super(name);
34     }
35     
36     private Logger originalLogger;
37     private Logger consoleLogger;
38     
39     public void setUp() throws Exception JavaDoc {
40         super.setUp();
41         originalLogger = Deprecation.logger;
42         // Setup a disabled logger: avoids polluting the test output, and also test
43
// that isXXXEnabled also matches the forbidden deprecation level
44
consoleLogger = new ConsoleLogger(ConsoleLogger.LEVEL_DISABLED);
45         Deprecation.setLogger(consoleLogger);
46         Deprecation.setForbiddenLevel(Deprecation.ERROR);
47     }
48     
49     public void tearDown() throws Exception JavaDoc {
50         Deprecation.setLogger(originalLogger);
51         super.tearDown();
52     }
53     
54     public void testPrecond() {
55         // Double check that our logger won't let anything go through, and that
56
// enabled levels are because of the allowed level we've set.
57
assertFalse(consoleLogger.isInfoEnabled());
58         assertFalse(consoleLogger.isWarnEnabled());
59         assertFalse(consoleLogger.isErrorEnabled());
60     }
61     
62     public void testInfoOk() {
63         try {
64             Deprecation.logger.info("testing deprecation logs");
65         } catch(DeprecationException de) {
66             fail("Should not throw an exception");
67         }
68     }
69
70     public void testWarnOk() {
71         try {
72             Deprecation.logger.warn("testing deprecation logs");
73         } catch(DeprecationException de) {
74             fail("Should not throw an exception");
75         }
76     }
77     
78     public void testErrorFails() {
79         try {
80             Deprecation.logger.error("testing deprecation logs");
81         } catch(DeprecationException de) {
82             return; // success
83
}
84         fail("Should throw an exception");
85     }
86     
87     public void testDebugFails() {
88         Deprecation.setForbiddenLevel(Deprecation.DEBUG);
89         try {
90             Deprecation.logger.debug("testing deprecation logs");
91         } catch(DeprecationException de) {
92             return; // success
93
}
94         fail("Should throw an exception");
95     }
96
97     public void testInfoDisabled() {
98         assertFalse(Deprecation.logger.isInfoEnabled());
99     }
100
101     public void testWarnDisabled() {
102         assertFalse(Deprecation.logger.isWarnEnabled());
103     }
104
105     public void testErrorEnabled() {
106         assertTrue(Deprecation.logger.isErrorEnabled());
107     }
108 }
109
Popular Tags