KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > junit > v1 > parser > TestClassCreatorUTest


1 /*
2  * @(#)TestClassCreatorUTest.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.junit.v1.parser;
28
29 import junit.framework.Test;
30 import junit.framework.TestCase;
31 import junit.framework.TestSuite;
32 import junit.framework.AssertionFailedError;
33
34 import java.io.IOException JavaDoc;
35 import java.lang.reflect.Method JavaDoc;
36
37
38 /**
39  * Tests the TestClassCreator class.
40  *
41  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
42  * @since November 4, 2002
43  * @version $Date: 2003/02/10 22:52:24 $
44  */

45 public class TestClassCreatorUTest extends TestCase
46 {
47     //-------------------------------------------------------------------------
48
// Standard JUnit Class-specific declarations
49

50     private static final Class JavaDoc THIS_CLASS = TestClassCreatorUTest.class;
51     
52     public TestClassCreatorUTest( String JavaDoc name )
53     {
54         super( name );
55     }
56
57     
58
59
60     //-------------------------------------------------------------------------
61
// Tests
62

63     
64     public void testConstructor1()
65     {
66         try
67         {
68             new TestClassCreator( null );
69         }
70         catch (IllegalArgumentException JavaDoc e)
71         {
72             // test exception?
73
}
74     }
75     
76     
77     public void testConstructor2()
78     {
79         new TestClassCreator( new JUnitOrigCreator() );
80     }
81     
82     
83     public void testWarnings1()
84     {
85         TestClassCreator tcc = new TestClassCreator( new JUnitOrigCreator() );
86         
87         String JavaDoc s[] = tcc.getWarnings();
88         
89         assertNotNull( "Returned null warnings array.",
90             s );
91         assertEquals( "Returned warnings array with elements.",
92             0,
93             s.length );
94     }
95     
96     
97     public void testWarnings2()
98     {
99         TestClassCreator tcc = new TestClassCreator( new JUnitOrigCreator() );
100         
101         tcc.warning( "a" );
102         String JavaDoc s[] = tcc.getWarnings();
103         
104         assertNotNull( "Returned null warnings array.",
105             s );
106         assertEquals( "Returned warnings array with incorrect element count.",
107             1,
108             s.length );
109         assertEquals( "Did not return warnings array with correct entry.",
110             "a",
111             s[0] );
112     }
113     
114     
115     public void testWarnings3()
116     {
117         TestClassCreator tcc = new TestClassCreator( new JUnitOrigCreator() );
118         
119         tcc.warning( "a" );
120         tcc.warning( "b" );
121         String JavaDoc s[] = tcc.getWarnings();
122         
123         assertNotNull( "Returned null warnings array.",
124             s );
125         assertEquals( "Returned warnings array with incorrect element count.",
126             2,
127             s.length );
128         assertEquals( "Did not return warnings array with correct entry.",
129             "a",
130             s[0] );
131         assertEquals( "Did not return warnings array with correct entry.",
132             "b",
133             s[1] );
134     }
135     
136     
137     public void testClearWarnings1()
138     {
139         TestClassCreator tcc = new TestClassCreator( new JUnitOrigCreator() );
140         
141         tcc.clearWarnings();
142         String JavaDoc s[] = tcc.getWarnings();
143         
144         assertNotNull( "Returned null warnings array.",
145             s );
146         assertEquals( "Returned warnings array with elements.",
147             0,
148             s.length );
149     }
150     
151     
152     public void testClearWarnings2()
153     {
154         TestClassCreator tcc = new TestClassCreator( new JUnitOrigCreator() );
155         
156         tcc.warning( "a" );
157         tcc.clearWarnings();
158         String JavaDoc s[] = tcc.getWarnings();
159         
160         assertNotNull( "Returned null warnings array.",
161             s );
162         assertEquals( "Returned warnings array with elements.",
163             0,
164             s.length );
165     }
166     
167     
168     public void testClearWarnings3()
169     {
170         TestClassCreator tcc = new TestClassCreator( new JUnitOrigCreator() );
171         
172         tcc.warning( "a" );
173         tcc.warning( "b" );
174         tcc.clearWarnings();
175         String JavaDoc s[] = tcc.getWarnings();
176         
177         assertNotNull( "Returned null warnings array.",
178             s );
179         assertEquals( "Returned warnings array with elements.",
180             0,
181             s.length );
182     }
183     
184     
185     public void testCreateWarningTests1()
186     {
187         TestClassCreator tcc = new TestClassCreator( new JUnitOrigCreator() );
188         
189         tcc.warning( "a" );
190         tcc.warning( "b" );
191         Test t[] = tcc.createWarningTests( new TestClassParser( THIS_CLASS ) );
192         
193         assertNotNull( "Returned null warning test list.",
194             t );
195         assertEquals(
196             "Returned warnings test list with incorrect element count.",
197             2,
198             t.length );
199         // need to test failures!!!
200

201         
202         
203         // warnings should not have been cleared
204
String JavaDoc s[] = tcc.getWarnings();
205         
206         assertNotNull( "Returned null warnings array.",
207             s );
208         assertEquals( "Returned warnings array with incorrect element count.",
209             2,
210             s.length );
211         assertEquals( "Did not return warnings array with correct entry.",
212             "a",
213             s[0] );
214         assertEquals( "Did not return warnings array with correct entry.",
215             "b",
216             s[1] );
217     }
218     
219     
220     
221 /*
222     
223     
224     public static class TesterNoTestMethods implements Test
225     {
226         public int countTestCases() { return 0; }
227         public void run( junit.framework.TestResult tr ) {}
228     }
229     
230     
231     public static class TesterOneTestMethod implements Test
232     {
233         public int countTestCases() { return 0; }
234         public void run( junit.framework.TestResult tr ) {}
235         
236         public void testMyTest() {}
237     }
238     
239     
240     private class StaticClass {}
241     public class InnerClass {}
242     
243     public void testGetTestMethods1()
244     {
245         TestClassParser tcp = new TestClassParser( String.class );
246         Method m[] = tcp.getTestMethods();
247         assertNotNull(
248             "Must never return null.",
249             m );
250         assertEquals(
251             "String should have no test methods.",
252             0,
253             m.length );
254         assertTrue(
255             "Must never return the same array, but rather a copy.",
256             m != tcp.getTestMethods() );
257     }
258     
259     public void testGetTestMethods2()
260     {
261         TestClassParser tcp = new TestClassParser( Runnable.class );
262         Method m[] = tcp.getTestMethods();
263         assertNotNull(
264             "Must never return null.",
265             m );
266         assertEquals(
267             "Runnable should have no test methods.",
268             0,
269             m.length );
270         assertTrue(
271             "Must never return the same array, but rather a copy.",
272             m != tcp.getTestMethods() );
273     }
274     
275     public void testGetTestMethods3()
276     {
277         TestClassParser tcp = new TestClassParser( StaticClass.class );
278         Method m[] = tcp.getTestMethods();
279         assertNotNull(
280             "Must never return null.",
281             m );
282         assertEquals(
283             "Runnable should have no test methods.",
284             0,
285             m.length );
286         assertTrue(
287             "Must never return the same array, but rather a copy.",
288             m != tcp.getTestMethods() );
289     }
290     
291     public void testGetTestMethods4()
292     {
293         TestClassParser tcp = new TestClassParser( InnerClass.class );
294         Method m[] = tcp.getTestMethods();
295         assertNotNull(
296             "Must never return null.",
297             m );
298         assertEquals(
299             "Runnable should have no test methods.",
300             0,
301             m.length );
302         assertTrue(
303             "Must never return the same array, but rather a copy.",
304             m != tcp.getTestMethods() );
305     }
306     
307     public void testGetTestMethods5()
308     {
309         TestClassParser tcp = new TestClassParser( TesterNoTestMethods.class );
310         Method m[] = tcp.getTestMethods();
311         assertNotNull(
312             "Must never return null.",
313             m );
314         assertEquals(
315             "Runnable should have no test methods.",
316             0,
317             m.length );
318         assertTrue(
319             "Must never return the same array, but rather a copy.",
320             m != tcp.getTestMethods() );
321     }
322     
323     public void testGetTestMethods6()
324     {
325         TestClassParser tcp = new TestClassParser( TesterOneTestMethod.class );
326         Method m[] = tcp.getTestMethods();
327         assertNotNull(
328             "Must never return null.",
329             m );
330         assertEquals(
331             "Runnable should have one test method.",
332             1,
333             m.length );
334         assertTrue(
335             "Must never return the same array, but rather a copy.",
336             m != tcp.getTestMethods() );
337     }
338     
339     
340     */

341     
342     
343     
344     //-------------------------------------------------------------------------
345
// Standard JUnit declarations
346

347     
348     public static Test suite()
349     {
350         TestSuite suite = new TestSuite( THIS_CLASS );
351         
352         return suite;
353     }
354     
355     public static void main( String JavaDoc[] args )
356     {
357         String JavaDoc[] name = { THIS_CLASS.getName() };
358         
359         // junit.textui.TestRunner.main( name );
360
// junit.swingui.TestRunner.main( name );
361

362         junit.textui.TestRunner.main( name );
363     }
364     
365     
366     /**
367      *
368      * @exception Exception thrown under any exceptional condition.
369      */

370     protected void setUp() throws Exception JavaDoc
371     {
372         super.setUp();
373         
374         // set ourself up
375
}
376     
377     
378     /**
379      *
380      * @exception Exception thrown under any exceptional condition.
381      */

382     protected void tearDown() throws Exception JavaDoc
383     {
384         // tear ourself down
385

386         
387         super.tearDown();
388     }
389 }
390
391
Popular Tags