KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > grlea > log > test > TestOfInnerClassLogging


1 package org.grlea.log.test;
2
3 // $Id: TestOfInnerClassLogging.java,v 1.2 2006/07/13 12:44:56 grlea Exp $
4
// Copyright (c) 2004-2006 Graham Lea. All rights reserved.
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 org.grlea.log.SimpleLog;
20 import org.grlea.log.SimpleLogger;
21
22 import junit.framework.TestSuite;
23
24 /**
25  * <p>Tests that logging for inner classes works and is configurable.</p>
26  *
27  * @author Graham Lea
28  * @version $Revision: 1.2 $
29  */

30 public class
31 TestOfInnerClassLogging
32 extends AbstractLoggingTest
33 {
34
35    public
36    TestOfInnerClassLogging(String JavaDoc name)
37    {
38       // Standard TestCase constructor. You shouldn't edit this.
39
super(name);
40    }
41
42    public void
43    testNormalLogging()
44    throws Exception JavaDoc
45    {
46       new InnerClass(log).doSomeLogging();
47
48       String JavaDoc[] expectedOutputLineParts =
49       {
50          " |main|TestOfInnerClassLogging$InnerClass|Test of Fatal",
51          " |main|TestOfInnerClassLogging$InnerClass|Test of Error",
52          " |main|TestOfInnerClassLogging$InnerClass|Test of Warn",
53          " |main|TestOfInnerClassLogging$InnerClass|Test of Info",
54       };
55
56       checkOutput(expectedOutputLineParts);
57    }
58
59    public void
60    testLudicrousLogging()
61    throws Exception JavaDoc
62    {
63       properties.setProperty(InnerClass.class.getName(), "Ludicrous");
64       log.reloadProperties();
65       new InnerClass(log).doSomeLogging();
66
67       String JavaDoc[] expectedOutputLineParts =
68       {
69          " |main|TestOfInnerClassLogging$InnerClass|Test of Fatal",
70          " |main|TestOfInnerClassLogging$InnerClass|Test of Error",
71          " |main|TestOfInnerClassLogging$InnerClass|Test of Warn",
72          " |main|TestOfInnerClassLogging$InnerClass|Test of Info",
73          " |main|TestOfInnerClassLogging$InnerClass|Test of Debug",
74          " |main|TestOfInnerClassLogging$InnerClass|Test of Verbose",
75          " |main|TestOfInnerClassLogging$InnerClass|Test of Ludicrous",
76       };
77
78       checkOutput(expectedOutputLineParts);
79    }
80
81    public void
82    testTracing()
83    throws Exception JavaDoc
84    {
85       properties.setProperty(InnerClass.class.getName(), "Fatal");
86       properties.setProperty(InnerClass.class.getName() + "#trace", "true");
87       log.reloadProperties();
88       new InnerClass(log).doSomeLogging();
89
90       String JavaDoc[] expectedOutputLineParts =
91       {
92          " |main|TestOfInnerClassLogging$InnerClass|Test of Fatal",
93          ">>>|main|TestOfInnerClassLogging$InnerClass|doSomeLogging",
94          "<<<|main|TestOfInnerClassLogging$InnerClass|doSomeLogging",
95       };
96
97       checkOutput(expectedOutputLineParts);
98    }
99
100
101    /**
102     * Returns a test suite that will automatically run all test methods in this
103     * class beginning with "test".
104     */

105    public static TestSuite
106    suite()
107    {
108       return new TestSuite(TestOfInnerClassLogging.class);
109    }
110
111
112    private static final class
113    InnerClass
114    {
115       private final SimpleLogger log;
116
117       public
118       InnerClass(SimpleLog logTarget)
119       {
120          log = new SimpleLogger(logTarget, InnerClass.class);
121       }
122
123       private void
124       doSomeLogging()
125       {
126          log.fatal("Test of Fatal");
127          log.error("Test of Error");
128          log.warn("Test of Warn");
129          log.info("Test of Info");
130          log.debug("Test of Debug");
131          log.verbose("Test of Verbose");
132          log.ludicrous("Test of Ludicrous");
133
134          log.entry("doSomeLogging()");
135          log.exit("doSomeLogging()");
136       }
137    }
138 }
Popular Tags