KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > pmti > v1 > autodoc > v1 > ITFTestDataUTest


1 /*
2  * @(#)ITFTestDataUTest.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.pmti.v1.autodoc.v1;
28
29 import org.easymock.EasyMock;
30 import org.easymock.MockControl;
31 import junit.framework.Test;
32 import junit.framework.TestCase;
33 import junit.framework.TestSuite;
34 import net.sourceforge.groboutils.autodoc.v1.testserver.TestInfo;
35 import net.sourceforge.groboutils.autodoc.v1.testserver.TestData;
36 import net.sourceforge.groboutils.autodoc.v1.testserver.DefaultTestInfo;
37 import net.sourceforge.groboutils.autodoc.v1.testserver.TestDataUTestI;
38 import net.sourceforge.groboutils.junit.v1.iftc.*;
39 import junit.framework.AssertionFailedError;
40
41
42 /**
43  * Tests the ITFTestData class.
44  *
45  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
46  * @version $Date: 2003/05/29 13:04:45 $
47  * @since March 5, 2002
48  */

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

54     private static final Class JavaDoc THIS_CLASS = ITFTestDataUTest.class;
55     //private static final IJUnitDocumentor LOG = (new JUnitLog(THIS_CLASS)).getDocumentor();
56

57     public ITFTestDataUTest( String JavaDoc name )
58     {
59         super( name );
60     }
61
62     
63     //-------------------------------------------------------------------------
64
// setup
65

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

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

81
82     public void testConstructor1()
83     {
84         try
85         {
86             new ITFTestData( null );
87             fail("Did not throw IllegalArgumentException.");
88         }
89         catch (IllegalArgumentException JavaDoc e)
90         {
91             // test exception?
92
}
93     }
94     
95     
96     public void testSetGetIssues1()
97     {
98         ITFTestData td = createTestData();
99         
100         td.addIssueID( "a" );
101         String JavaDoc s[] = td.getIssues();
102         
103         assertNotNull(
104             "returned null string array",
105             s );
106         assertEquals(
107             "not right number of issues",
108             s.length,
109             1 );
110         assertEquals(
111             "not correct issue ID.",
112             s[0],
113             "a" );
114         
115         td.addIssueID( "a" );
116         s = td.getIssues();
117         
118         assertNotNull(
119             "returned null string array",
120             s );
121         assertEquals(
122             "not right number of issues",
123             s.length,
124             1 );
125         assertEquals(
126             "not correct issue ID.",
127             s[0],
128             "a" );
129         
130         td.addIssueID( "b" );
131         s = td.getIssues();
132         
133         assertNotNull(
134             "returned null string array",
135             s );
136         assertEquals(
137             "not right number of issues",
138             s.length,
139             2 );
140         assertEquals(
141             "not correct issue ID.",
142             s[0],
143             "a" );
144         assertEquals(
145             "not correct issue ID.",
146             s[1],
147             "b" );
148     }
149     
150     
151     public void testAddGetErrors1()
152     {
153         ITFTestData td = createTestData();
154         Throwable JavaDoc t1 = new Throwable JavaDoc("ignore");
155         td.addError( t1 );
156         
157         Throwable JavaDoc t[] = td.getErrors();
158         
159         assertNotNull(
160             "returned null errors.",
161             t );
162         assertEquals(
163             "not right amount of errors.",
164             t.length,
165             1 );
166         assertEquals(
167             "not right error.",
168             t[0],
169             t1 );
170         
171         td.addError( t1 );
172         t = td.getErrors();
173         assertNotNull(
174             "returned null errors.",
175             t );
176         assertEquals(
177             "not right amount of errors.",
178             t.length,
179             2 );
180         assertEquals(
181             "not right error.",
182             t[0],
183             t1 );
184         assertEquals(
185             "not right error.",
186             t[1],
187             t1 );
188         
189         Throwable JavaDoc t2 = new Throwable JavaDoc("ignore again");
190         td.addError( t2 );
191         t = td.getErrors();
192         assertNotNull(
193             "returned null errors.",
194             t );
195         assertEquals(
196             "not right amount of errors.",
197             t.length,
198             3 );
199         assertEquals(
200             "not right error.",
201             t[0],
202             t1 );
203         assertEquals(
204             "not right error.",
205             t[1],
206             t1 );
207         assertEquals(
208             "not right error.",
209             t[2],
210             t2 );
211     }
212     
213     
214     public void testAddGetFailures1()
215     {
216         ITFTestData td = createTestData();
217         AssertionFailedError t1 = new AssertionFailedError("ignore");
218         td.addFailure( t1 );
219         
220         AssertionFailedError t[] = td.getFailures();
221         
222         assertNotNull(
223             "returned null failure.",
224             t );
225         assertEquals(
226             "not right amount of failure.",
227             t.length,
228             1 );
229         assertEquals(
230             "not right failure.",
231             t[0],
232             t1 );
233         
234         td.addFailure( t1 );
235         t = td.getFailures();
236         assertNotNull(
237             "returned null failure.",
238             t );
239         assertEquals(
240             "not right amount of failure.",
241             t.length,
242             2 );
243         assertEquals(
244             "not right failure.",
245             t[0],
246             t1 );
247         assertEquals(
248             "not right failure.",
249             t[1],
250             t1 );
251         
252         AssertionFailedError t2 = new AssertionFailedError("ignore again");
253         td.addFailure( t2 );
254         t = td.getFailures();
255         assertNotNull(
256             "returned null failure.",
257             t );
258         assertEquals(
259             "not right amount of failure.",
260             t.length,
261             3 );
262         assertEquals(
263             "not right failure.",
264             t[0],
265             t1 );
266         assertEquals(
267             "not right failure.",
268             t[1],
269             t1 );
270         assertEquals(
271             "not right failure.",
272             t[2],
273             t2 );
274     }
275     
276     
277     public void testAddGetTests1()
278     {
279         ITFTestData td = createTestData();
280         
281         assertEquals(
282             "Not right number of initial TCs found.",
283             td.getTestCount(),
284             0 );
285         
286         td.addTest();
287         assertEquals(
288             "Not right number of TCs found.",
289             td.getTestCount(),
290             1 );
291         
292         td.addTest();
293         td.addTest();
294         td.addTest();
295         assertEquals(
296             "Not right number of TCs found.",
297             td.getTestCount(),
298             4 );
299     }
300     
301     
302     public void testTimes1()
303     {
304         ITFTestData td = createTestData();
305         
306         assertEquals(
307             "Initial runtime is incorrect.",
308             td.getRunTime(),
309             -1 );
310     }
311     
312     
313     public void testTimes2()
314     {
315         ITFTestData td = createTestData();
316         
317         td.setStartTime( 0L );
318
319         assertEquals(
320             "Initial runtime is incorrect.",
321             td.getRunTime(),
322             -1 );
323     }
324     
325     
326     public void testTimes3()
327     {
328         ITFTestData td = createTestData();
329         
330         td.setEndTime( 0L );
331         
332         assertEquals(
333             "Initial runtime is incorrect.",
334             td.getRunTime(),
335             -1 );
336     }
337     
338     
339     public void testTimes4()
340     {
341         ITFTestData td = createTestData();
342         
343         td.setStartTime( 0L );
344         td.setEndTime( 0L );
345         assertEquals(
346             "0 runtime is incorrect.",
347             td.getRunTime(),
348             0 );
349     }
350     
351     
352     public void testTimes5()
353     {
354         ITFTestData td = createTestData();
355         
356         td.setStartTime( 0L );
357         td.setEndTime( 100L );
358         assertEquals(
359             "runtime is incorrect.",
360             td.getRunTime(),
361             100L );
362     }
363     
364     
365     public void testGetSuccessCount1()
366     {
367         ITFTestData td = createTestData();
368         
369         assertEquals(
370             "number of successful TCs incorrect.",
371             td.getSuccessCount(),
372             0 );
373     }
374     
375     
376     public void testGetSuccessCount2()
377     {
378         ITFTestData td = createTestData();
379         
380         td.addError( new Throwable JavaDoc() );
381         
382         assertEquals(
383             "number of successful TCs incorrect.",
384             td.getSuccessCount(),
385             0 );
386     }
387     
388     
389     public void testGetSuccessCount3()
390     {
391         ITFTestData td = createTestData();
392         
393         td.addFailure( new AssertionFailedError( "ignore" ) );
394         
395         assertEquals(
396             "number of successful TCs incorrect.",
397             td.getSuccessCount(),
398             0 );
399     }
400     
401     
402     public void testGetSuccessCount4()
403     {
404         ITFTestData td = createTestData();
405         
406         td.addError( new Throwable JavaDoc() );
407         td.addFailure( new AssertionFailedError( "ignore" ) );
408         
409         assertEquals(
410             "number of successful TCs incorrect.",
411             td.getSuccessCount(),
412             0 );
413     }
414     
415     
416     public void testGetSuccessCount5()
417     {
418         ITFTestData td = createTestData();
419         
420         td.addTest();
421         td.addError( new Throwable JavaDoc() );
422         td.addFailure( new AssertionFailedError( "ignore" ) );
423         
424         assertEquals(
425             "number of successful TCs incorrect.",
426             td.getSuccessCount(),
427             0 );
428     }
429     
430     
431     public void testGetSuccessCount6()
432     {
433         ITFTestData td = createTestData();
434         
435         td.addTest();
436         
437         assertEquals(
438             "number of successful TCs incorrect.",
439             td.getSuccessCount(),
440             1 );
441     }
442     
443     
444     public void testGetSuccessCount6a()
445     {
446         ITFTestData td = createTestData();
447         
448         td.addTest();
449         td.addTest();
450         td.addTest();
451         td.addTest();
452         
453         assertEquals(
454             "number of successful TCs incorrect.",
455             td.getSuccessCount(),
456             4 );
457     }
458     
459     
460     public void testGetSuccessCount7()
461     {
462         ITFTestData td = createTestData();
463         
464         td.addTest();
465         td.addTest();
466         td.addTest();
467         td.addTest();
468         td.addError( new Throwable JavaDoc() );
469         td.addError( new Throwable JavaDoc() );
470         
471         assertEquals(
472             "number of successful TCs incorrect.",
473             td.getSuccessCount(),
474             2 );
475     }
476     
477     
478     public void testGetSuccessCount8()
479     {
480         ITFTestData td = createTestData();
481         
482         td.addTest();
483         td.addTest();
484         td.addTest();
485         td.addTest();
486         td.addFailure( new AssertionFailedError( "ignore" ) );
487         td.addFailure( new AssertionFailedError( "ignore" ) );
488         
489         assertEquals(
490             "number of successful TCs incorrect.",
491             td.getSuccessCount(),
492             2 );
493     }
494     
495     
496     public void testGetSuccessCount9()
497     {
498         ITFTestData td = createTestData();
499         
500         td.addTest();
501         td.addTest();
502         td.addTest();
503         td.addTest();
504         td.addError( new Throwable JavaDoc() );
505         td.addFailure( new AssertionFailedError( "ignore" ) );
506         
507         assertEquals(
508             "number of successful TCs incorrect.",
509             td.getSuccessCount(),
510             2 );
511     }
512     
513     
514     public void testGetSuccessCount10()
515     {
516         ITFTestData td = createTestData();
517         
518         td.addTest();
519         td.addTest();
520         td.addTest();
521         td.addTest();
522         td.addError( new Throwable JavaDoc() );
523         td.addError( new Throwable JavaDoc() );
524         td.addFailure( new AssertionFailedError( "ignore" ) );
525         
526         assertEquals(
527             "number of successful TCs incorrect.",
528             td.getSuccessCount(),
529             1 );
530     }
531     
532     
533     public void testGetSuccessCount11()
534     {
535         ITFTestData td = createTestData();
536         
537         td.addTest();
538         td.addTest();
539         td.addTest();
540         td.addTest();
541         td.addError( new Throwable JavaDoc() );
542         td.addFailure( new AssertionFailedError( "ignore" ) );
543         td.addFailure( new AssertionFailedError( "ignore" ) );
544         
545         assertEquals(
546             "number of successful TCs incorrect.",
547             td.getSuccessCount(),
548             1 );
549     }
550     
551     
552     
553     //-------------------------------------------------------------------------
554
// Helpers
555

556     
557     protected ITFTestData createTestData()
558     {
559         ITFTestData td = new ITFTestData( new DefaultTestInfo( "a", "b" ) );
560         return td;
561     }
562     
563     
564     //-------------------------------------------------------------------------
565
// Standard JUnit declarations
566

567     
568     public static Test suite()
569     {
570         InterfaceTestSuite suite = TestDataUTestI.suite();
571         suite.addTestSuite( THIS_CLASS );
572         suite.addFactory( new CxFactory( "A" ) {
573             public Object JavaDoc createImplObject() {
574                 return new ITFTestData( new DefaultTestInfo( "a", "b" ) );
575             }
576         } );
577         
578         return suite;
579     }
580     
581     public static void main( String JavaDoc[] args )
582     {
583         String JavaDoc[] name = { THIS_CLASS.getName() };
584         
585         // junit.textui.TestRunner.main( name );
586
// junit.swingui.TestRunner.main( name );
587

588         junit.textui.TestRunner.main( name );
589     }
590     
591     
592     /**
593      *
594      * @exception Exception thrown under any exceptional condition.
595      */

596     protected void tearDown() throws Exception JavaDoc
597     {
598         // tear ourself down
599

600         
601         super.tearDown();
602     }
603 }
604
605
Popular Tags