001: /*
002: * @(#)AutoDocITImplUTest.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.pmti.v1.autodoc.v1;
028:
029: import java.util.Vector;
030: import java.util.Hashtable;
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034: import net.sourceforge.groboutils.autodoc.v1.AutoDocITUTestI;
035: import net.sourceforge.groboutils.autodoc.v1.testserver.*;
036: import net.sourceforge.groboutils.junit.v1.iftc.*;
037: import junit.framework.AssertionFailedError;
038:
039: /**
040: * Tests the AutoDocITImpl class.
041: *
042: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
043: * @version $Date: 2003/05/29 13:04:45 $
044: * @since March 5, 2002
045: */
046: public class AutoDocITImplUTest extends TestCase {
047: //-------------------------------------------------------------------------
048: // Standard JUnit Class-specific declarations
049:
050: private static final Class THIS_CLASS = AutoDocITImplUTest.class;
051:
052: //private static final IJUnitDocumentor LOG = (new JUnitLog(THIS_CLASS)).getDocumentor();
053:
054: public AutoDocITImplUTest(String name) {
055: super (name);
056: }
057:
058: //-------------------------------------------------------------------------
059: // setup
060:
061: /**
062: *
063: * @exception Exception thrown under any exceptional condition.
064: */
065: protected void setUp() throws Exception {
066: super .setUp();
067:
068: // set ourself up
069: }
070:
071: //-------------------------------------------------------------------------
072: // Tests
073:
074: public class MyMonitor implements Monitor {
075: public Vector addedTests = new Vector();
076: public Hashtable testData = new Hashtable();
077: public Vector sentTests = new Vector();
078:
079: public void addTestData(TestInfo info) {
080: addedTests.addElement(info);
081: }
082:
083: public TestData getTestData(TestInfo info) {
084: return (TestData) testData.get(info);
085: }
086:
087: public void sendTestData(TestInfo info) {
088: sentTests.addElement(info);
089: }
090: }
091:
092: public class MyMonitorFinder implements MonitorFinder {
093: private Monitor m;
094:
095: public MyMonitorFinder(Monitor m) {
096: this .m = m;
097: }
098:
099: public Monitor getMonitor() {
100: return m;
101: }
102: }
103:
104: public void testSendTestIssue1() {
105: MyMonitor mon = new MyMonitor();
106: MyMonitorFinder mf = new MyMonitorFinder(mon);
107: DefaultTestInfo ti = new DefaultTestInfo("a", "b");
108: DefaultTestData td = new DefaultTestData(ti);
109: mon.testData.put(ti, td);
110:
111: AutoDocITImpl it = new AutoDocITImpl(THIS_CLASS, mf);
112: try {
113: it.sendTestIssue(ti, "");
114: fail("did not throw IllegalStateException");
115: } catch (IllegalStateException iae) {
116: // test exception?
117: }
118: }
119:
120: public void testSendTestIssue2() {
121: MyMonitor mon = new MyMonitor();
122: MyMonitorFinder mf = new MyMonitorFinder(mon);
123: DefaultTestInfo ti = new DefaultTestInfo("a", "b");
124: ITFTestData td = new ITFTestData(ti);
125: mon.testData.put(ti, td);
126:
127: AutoDocITImpl it = new AutoDocITImpl(THIS_CLASS, mf);
128: it.sendTestIssue(ti, "a");
129:
130: String[] issues = td.getIssues();
131: assertNotNull("null issue set", issues);
132: assertEquals("incorrect number of issues registered.",
133: issues.length, 1);
134: assertEquals("incorrect registration of issue.", issues[0], "a");
135: }
136:
137: //-------------------------------------------------------------------------
138: // Helpers
139:
140: //-------------------------------------------------------------------------
141: // Standard JUnit declarations
142:
143: public static Test suite() {
144: InterfaceTestSuite suite = AutoDocITUTestI.suite();
145: suite.addTestSuite(THIS_CLASS);
146: suite.addFactory(new CxFactory("A") {
147: public Object createImplObject() {
148: return new AutoDocITImpl(THIS_CLASS);
149: }
150: });
151:
152: return suite;
153: }
154:
155: public static void main(String[] args) {
156: String[] name = { THIS_CLASS.getName() };
157:
158: // junit.textui.TestRunner.main( name );
159: // junit.swingui.TestRunner.main( name );
160:
161: junit.textui.TestRunner.main(name);
162: }
163:
164: /**
165: *
166: * @exception Exception thrown under any exceptional condition.
167: */
168: protected void tearDown() throws Exception {
169: // tear ourself down
170:
171: super.tearDown();
172: }
173: }
|