KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > autodoc > v1 > testserver > junit > JUnitTestListenerUTest


1 /*
2  * @(#)JUnitTestListenerUTest.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.autodoc.v1.testserver.junit;
28
29 import net.sourceforge.groboutils.autodoc.v1.*;
30 import net.sourceforge.groboutils.autodoc.v1.testserver.*;
31
32 import java.util.*;
33
34 import org.easymock.EasyMock;
35 import org.easymock.MockControl;
36 import net.sourceforge.groboutils.junit.v1.iftc.*;
37 import junit.framework.Test;
38 import junit.framework.TestCase;
39 import junit.framework.TestSuite;
40 import junit.framework.AssertionFailedError;
41
42
43 /**
44  * Tests the JUnitTestListener class.
45  *
46  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
47  * @since March 27, 2002
48  * @version $Date: 2003/05/29 13:05:52 $
49  */

50 public class JUnitTestListenerUTest extends TestCase
51 {
52     //-------------------------------------------------------------------------
53
// Standard JUnit Class-specific declarations
54

55     private static final Class JavaDoc THIS_CLASS = JUnitTestListenerUTest.class;
56     
57     public JUnitTestListenerUTest( String JavaDoc name )
58     {
59         super( name );
60     }
61
62     
63     //-------------------------------------------------------------------------
64
// setup
65

66     
67     
68     /**
69      *
70      * @exception Exception thrown under any exceptional condition.
71      */

72     protected void setUp() throws Exception JavaDoc
73     {
74         super.setUp();
75         
76         // set ourself up
77
}
78
79
80     //-------------------------------------------------------------------------
81
// Tests
82

83     
84     public void testNeedMoreTests()
85     {}
86     
87     
88     
89     //-------------------------------------------------------------------------
90
// Helpers
91

92     static class MyMonitor implements Monitor
93     {
94         public Vector addedInfo = new Vector();
95         public Vector sentInfo = new Vector();
96         public Vector testInfo = new Vector();
97         
98         public void addTestData( TestInfo info )
99         {
100             this.addedInfo.addElement( info );
101             this.testInfo.addElement( info );
102         }
103         
104         
105         public TestData getTestData( TestInfo info )
106         {
107             return new DefaultTestData( info );
108         }
109         
110         
111         public void sendTestData( TestInfo info )
112         {
113             if (this.addedInfo.contains( info ))
114             {
115                 this.addedInfo.removeElement( info );
116                 this.sentInfo.addElement( info );
117             }
118             else
119             {
120                 throw new IllegalStateException JavaDoc("");
121             }
122         }
123         
124         
125         public void clear()
126         {
127             this.addedInfo = new Vector();
128             this.sentInfo = new Vector();
129             this.testInfo = new Vector();
130         }
131     }
132     
133     
134     static class MyMonitorFinder implements MonitorFinder
135     {
136         public MyMonitor monitor = new MyMonitor();
137         public Monitor getMonitor()
138         {
139             return this.monitor;
140         }
141     }
142     
143     
144     static class MyJUnitTestListener extends JUnitTestListener
145     {
146         public static MyMonitorFinder finder = new MyMonitorFinder();
147         public Vector start = new Vector();
148         public Vector end = new Vector();
149         public Vector error = new Vector();
150         public Vector thr = new Vector();
151         public Vector failure = new Vector();
152         
153         public MyJUnitTestListener()
154         {
155             super( finder );
156         }
157         
158         protected void startTest( TestData data )
159         {
160             this.start.addElement( data );
161         }
162         
163         protected void endTest( TestData data )
164         {
165             this.end.addElement( data );
166         }
167         
168         protected void addError( TestData data, Throwable JavaDoc t )
169         {
170             this.error.addElement( data );
171             this.thr.addElement( t );
172         }
173         
174         protected void addFailure( TestData data, AssertionFailedError t )
175         {
176             this.failure.addElement( data );
177             this.thr.addElement( t );
178         }
179     }
180     
181     //-------------------------------------------------------------------------
182
// Standard JUnit declarations
183

184     
185     public static TestSuite suite()
186     {
187         InterfaceTestSuite suite = JUnitTestListenerUTestI.suite();
188         suite.addTestSuite( THIS_CLASS );
189         suite.addFactory( new CxFactory( "A" ) {
190             public Object JavaDoc createImplObject() {
191                 MyJUnitTestListener.finder.monitor.clear();
192                 return new MyJUnitTestListener();
193             }
194         } );
195         
196         return suite;
197     }
198     
199     public static void main( String JavaDoc[] args )
200     {
201         String JavaDoc[] name = { THIS_CLASS.getName() };
202         
203         // junit.textui.TestRunner.main( name );
204
// junit.swingui.TestRunner.main( name );
205

206         junit.textui.TestRunner.main( name );
207     }
208     
209     
210     /**
211      *
212      * @exception Exception thrown under any exceptional condition.
213      */

214     protected void tearDown() throws Exception JavaDoc
215     {
216         // tear ourself down
217

218         super.tearDown();
219     }
220 }
221
222
Popular Tags