KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > util > junit > LogTest


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ------------
28  * LogTest.java
29  * ------------
30  * (C)opyright 2004, by Thomas Morgner and Contributors.
31  *
32  * Original Author: Thomas Morgner;
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * $Id: LogTest.java,v 1.3 2005/10/18 13:25:14 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 21-Feb-2004 : Initial version
40  * 07-Jun-2004 : Added JCommon header (DG);
41  */

42
43 package org.jfree.util.junit;
44
45 import junit.framework.TestCase;
46
47 import org.jfree.util.Log;
48 import org.jfree.util.LogContext;
49 import org.jfree.util.LogTarget;
50
51 /**
52  * A test for...
53  */

54 public class LogTest extends TestCase {
55
56     private class LogTargetImpl implements LogTarget {
57
58         /**
59          * Default constructor.
60          */

61         public LogTargetImpl() {
62             super();
63         }
64
65         /**
66          * Logs a message at a specified log level.
67          *
68          * @param level the log level.
69          * @param message the log message.
70          */

71         public void log(final int level, final Object JavaDoc message) {
72             // nothing required.
73
}
74
75         /**
76          * Logs a message at a specified log level.
77          *
78          * @param level the log level.
79          * @param message the log message.
80          * @param e the exception
81          */

82         public void log(final int level, final Object JavaDoc message, final Exception JavaDoc e) {
83             // nothing required.
84
}
85     }
86
87     /**
88      * Creates a new test.
89      *
90      * @param s the test name.
91      */

92     public LogTest(final String JavaDoc s) {
93         super(s);
94     }
95
96     /**
97      * Tests the addTarget() and removeTarget() methods.
98      */

99     public void testAddRemove() {
100         final LogTarget a = new LogTargetImpl();
101         final LogTarget b = new LogTargetImpl();
102
103         Log.getInstance().removeTarget(a);
104         Log.getInstance().removeTarget(b);
105
106         Log.getInstance().addTarget(a);
107         Log.getInstance().addTarget(b);
108
109         Log.getInstance().removeTarget(a);
110         Log.getInstance().removeTarget(b);
111
112         Log.getInstance().addTarget(a);
113         Log.getInstance().addTarget(b);
114
115         Log.getInstance().removeTarget(b);
116         Log.getInstance().removeTarget(a);
117
118         Log.getInstance().getTargets();
119     }
120
121     /**
122      * Tests the log message methods.
123      */

124     public void testLogMessage () {
125         Log.debug("Test");
126         Log.info("Test");
127         Log.warn("Test");
128         Log.error("Test");
129     }
130
131     /**
132      * Tests the log context.
133      */

134     public void testLogContext() {
135         final LogContext ctx = Log.createContext((String JavaDoc) null);
136         assertEquals("Context = null", ctx, Log.createContext((String JavaDoc) null));
137
138         final LogContext ctx2 = Log.createContext("Test");
139         assertEquals("Context Test", ctx2, Log.createContext("Test"));
140
141     }
142 }
143
Popular Tags