001: /*
002: * @(#)Log4jLogUTest.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.autodoc.v1.log4j;
028:
029: import net.sourceforge.groboutils.autodoc.v1.*;
030:
031: import net.sourceforge.groboutils.junit.v1.iftc.*;
032: import junit.framework.Test;
033: import junit.framework.TestCase;
034: import junit.framework.TestSuite;
035:
036: /**
037: * Tests the Log4jLog class.
038: *
039: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
040: * @version $Date: 2003/05/27 13:32:51 $
041: * @since March 28, 2002
042: */
043: public class Log4jLogUTest extends TestCase {
044: //-------------------------------------------------------------------------
045: // Standard JUnit Class-specific declarations
046:
047: private static final Class THIS_CLASS = Log4jLogUTest.class;
048:
049: public Log4jLogUTest(String name) {
050: super (name);
051: }
052:
053: //-------------------------------------------------------------------------
054: // setup
055:
056: /**
057: *
058: * @exception Exception thrown under any exceptional condition.
059: */
060: protected void setUp() throws Exception {
061: super .setUp();
062:
063: // set ourself up
064: }
065:
066: //-------------------------------------------------------------------------
067: // Tests
068:
069: public void testConstructor1() {
070: try {
071: new Log4jLog((Class) null);
072: fail("did not throw IllegalArgumentException.");
073: } catch (IllegalArgumentException e) {
074: // test exception?
075: }
076: }
077:
078: public void testConstructor2() {
079: new Log4jLog(this .getClass());
080: }
081:
082: public void testConstructor3() {
083: try {
084: new Log4jLog((org.apache.log4j.Logger) null);
085: fail("did not throw IllegalArgumentException.");
086: } catch (IllegalArgumentException e) {
087: // test exception?
088: }
089: }
090:
091: public void testConstructor4() {
092: new Log4jLog(org.apache.log4j.Logger.getLogger(this .getClass()));
093: }
094:
095: public void testConcatMessage1() {
096: Log4jLog log = new Log4jLog(this .getClass());
097: Object sb = log.concatMessage(null);
098: assertNotNull("concatMessage must not return null.", sb);
099: assertEquals("did not concat objects correctly.", "null", sb
100: .toString());
101: }
102:
103: public void testConcatMessage2() {
104: Log4jLog log = new Log4jLog(this .getClass());
105: Object sb = log.concatMessage(new Object[0]);
106: assertNotNull("concatMessage must not return null.", sb);
107: assertEquals("did not concat objects correctly.", "", sb
108: .toString());
109: }
110:
111: public void testConcatMessage3() {
112: Log4jLog log = new Log4jLog(this .getClass());
113: Object sb = log.concatMessage(new Object[1]);
114: assertNotNull("concatMessage must not return null.", sb);
115: assertEquals("did not concat objects correctly.", "null", sb
116: .toString());
117: }
118:
119: public void testConcatMessage4() {
120: Log4jLog log = new Log4jLog(this .getClass());
121: Object sb = log.concatMessage(new Object[] { "a", "b" });
122: assertNotNull("concatMessage must not return null.", sb);
123: assertEquals("did not concat objects correctly.", "ab", sb
124: .toString());
125: }
126:
127: public void testConcatMessage5() {
128: Log4jLog log = new Log4jLog(this .getClass());
129: StringBuffer sb = (StringBuffer) log
130: .concatMessage(new Object[] { "a", null, "b" });
131: assertNotNull("concatMessage must not return null.", sb);
132: assertEquals("did not concat objects correctly.", "anullb", sb
133: .toString());
134: }
135:
136: //-------------------------------------------------------------------------
137: // Helpers
138:
139: //-------------------------------------------------------------------------
140: // Standard JUnit declarations
141:
142: public static Test suite() {
143: InterfaceTestSuite suite = AutoDocLogUTestI.suite();
144: suite.addTestSuite(THIS_CLASS);
145: suite.addFactory(new CxFactory("A") {
146: public Object createImplObject() {
147: return new Log4jLog(Test.class);
148: }
149: });
150:
151: return suite;
152: }
153:
154: public static void main(String[] args) {
155: String[] name = { THIS_CLASS.getName() };
156:
157: // junit.textui.TestRunner.main( name );
158: // junit.swingui.TestRunner.main( name );
159:
160: junit.textui.TestRunner.main(name);
161: }
162:
163: /**
164: *
165: * @exception Exception thrown under any exceptional condition.
166: */
167: protected void tearDown() throws Exception {
168: // tear ourself down
169:
170: super.tearDown();
171: }
172: }
|