001: /* ========================================================================
002: * JCommon : a free general purpose class library for the Java(tm) platform
003: * ========================================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jcommon/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ------------
028: * LogTest.java
029: * ------------
030: * (C)opyright 2004, by Thomas Morgner and Contributors.
031: *
032: * Original Author: Thomas Morgner;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: LogTest.java,v 1.3 2005/10/18 13:25:14 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 21-Feb-2004 : Initial version
040: * 07-Jun-2004 : Added JCommon header (DG);
041: */
042:
043: package org.jfree.util.junit;
044:
045: import junit.framework.TestCase;
046:
047: import org.jfree.util.Log;
048: import org.jfree.util.LogContext;
049: import org.jfree.util.LogTarget;
050:
051: /**
052: * A test for...
053: */
054: public class LogTest extends TestCase {
055:
056: private class LogTargetImpl implements LogTarget {
057:
058: /**
059: * Default constructor.
060: */
061: public LogTargetImpl() {
062: super ();
063: }
064:
065: /**
066: * Logs a message at a specified log level.
067: *
068: * @param level the log level.
069: * @param message the log message.
070: */
071: public void log(final int level, final Object message) {
072: // nothing required.
073: }
074:
075: /**
076: * Logs a message at a specified log level.
077: *
078: * @param level the log level.
079: * @param message the log message.
080: * @param e the exception
081: */
082: public void log(final int level, final Object message,
083: final Exception e) {
084: // nothing required.
085: }
086: }
087:
088: /**
089: * Creates a new test.
090: *
091: * @param s the test name.
092: */
093: public LogTest(final String s) {
094: super (s);
095: }
096:
097: /**
098: * Tests the addTarget() and removeTarget() methods.
099: */
100: public void testAddRemove() {
101: final LogTarget a = new LogTargetImpl();
102: final LogTarget b = new LogTargetImpl();
103:
104: Log.getInstance().removeTarget(a);
105: Log.getInstance().removeTarget(b);
106:
107: Log.getInstance().addTarget(a);
108: Log.getInstance().addTarget(b);
109:
110: Log.getInstance().removeTarget(a);
111: Log.getInstance().removeTarget(b);
112:
113: Log.getInstance().addTarget(a);
114: Log.getInstance().addTarget(b);
115:
116: Log.getInstance().removeTarget(b);
117: Log.getInstance().removeTarget(a);
118:
119: Log.getInstance().getTargets();
120: }
121:
122: /**
123: * Tests the log message methods.
124: */
125: public void testLogMessage() {
126: Log.debug("Test");
127: Log.info("Test");
128: Log.warn("Test");
129: Log.error("Test");
130: }
131:
132: /**
133: * Tests the log context.
134: */
135: public void testLogContext() {
136: final LogContext ctx = Log.createContext((String) null);
137: assertEquals("Context = null", ctx, Log
138: .createContext((String) null));
139:
140: final LogContext ctx2 = Log.createContext("Test");
141: assertEquals("Context Test", ctx2, Log.createContext("Test"));
142:
143: }
144: }
|