001: /*
002: * @(#)LogTPUTest.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.tp.v1.log;
028:
029: import java.io.*;
030:
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034: import net.sourceforge.groboutils.autodoc.v1.*;
035: import net.sourceforge.groboutils.junit.v1.iftc.*;
036: import junit.framework.AssertionFailedError;
037:
038: /**
039: * Tests the LogTP class.
040: *
041: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
042: * @version $Date: 2003/05/29 13:05:55 $
043: * @since July 21, 2002
044: */
045: public class LogTPUTest extends TestCase {
046: //-------------------------------------------------------------------------
047: // Standard JUnit Class-specific declarations
048:
049: private static final Class THIS_CLASS = LogTPUTest.class;
050:
051: public LogTPUTest(String name) {
052: super (name);
053: }
054:
055: //-------------------------------------------------------------------------
056: // setup
057:
058: /**
059: *
060: * @exception Exception thrown under any exceptional condition.
061: */
062: protected void setUp() throws Exception {
063: super .setUp();
064:
065: }
066:
067: //-------------------------------------------------------------------------
068: // Tests
069:
070: public void testPrintStep1() {
071: LogTP tp = new LogTP(null, null);
072: StringWriter sw = new StringWriter();
073: tp.setOutput(new PrintWriter(sw));
074:
075: tp.printStep("a", "text", 0);
076:
077: String s = sw.toString();
078: assertTrue("Did not print right text (got " + s + ").", s
079: .indexOf("1. a: 0. text") >= 0);
080: }
081:
082: public void testPrintStep2() {
083: LogTP tp = new LogTP(null, null);
084: StringWriter sw = new StringWriter();
085: tp.setOutput(new PrintWriter(sw));
086: tp.printStep("a", "text", 0);
087: sw = new StringWriter();
088: tp.setOutput(new PrintWriter(sw));
089:
090: tp.printStep("b", "other", 18);
091:
092: String s = sw.toString();
093: assertTrue("Did not print right text (got " + s + ").", s
094: .indexOf("2. b: 18. other") >= 0);
095: }
096:
097: //-------------------------------------------------------------------------
098: // Helpers
099:
100: //-------------------------------------------------------------------------
101: // Standard JUnit declarations
102:
103: public static Test suite() {
104: InterfaceTestSuite suite = AutoDocTPUTestI.suite();
105: suite.addTestSuite(THIS_CLASS);
106: suite.addFactory(new CxFactory("A") {
107: public Object createImplObject() {
108: return new LogTP(".", THIS_CLASS);
109: }
110: });
111: suite.addFactory(new CxFactory("B") {
112: public Object createImplObject() {
113: return new LogTP(null, THIS_CLASS);
114: }
115: });
116: suite.addFactory(new CxFactory("C") {
117: public Object createImplObject() {
118: return new LogTP(".", THIS_CLASS);
119: }
120: });
121: suite.addFactory(new CxFactory("D") {
122: public Object createImplObject() {
123: return new LogTP(null, null);
124: }
125: });
126:
127: return suite;
128: }
129:
130: public static void main(String[] args) {
131: String[] name = { THIS_CLASS.getName() };
132:
133: // junit.textui.TestRunner.main( name );
134: // junit.swingui.TestRunner.main( name );
135:
136: junit.textui.TestRunner.main(name);
137: }
138:
139: /**
140: *
141: * @exception Exception thrown under any exceptional condition.
142: */
143: protected void tearDown() throws Exception {
144: // tear ourself down
145:
146: super.tearDown();
147: }
148: }
|