KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > ant > FailOnReportStyleUTest


1 /*
2  * @(#)FailOnReportStyleUTest.java
3  *
4  * Copyright (C) 2004 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.codecoverage.v2.ant;
28
29 import java.io.File JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.util.Properties JavaDoc;
32
33 import junit.framework.Test;
34 import junit.framework.TestSuite;
35 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
36
37 import org.apache.tools.ant.BuildException;
38
39
40 /**
41  * Tests the FailOnReportStyle class.
42  *
43  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
44  * @version $Date: 2004/07/07 09:39:12 $
45  * @since March 19, 2004
46  */

47 public class FailOnReportStyleUTest extends AntTestA
48 {
49     //-------------------------------------------------------------------------
50
// Standard JUnit Class-specific declarations
51

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

64     //...........................
65
// Non-ant tests
66

67     public void testClassFilterConstructor1()
68     {
69         try
70         {
71             FailOnReportStyle.ClassFilter cf =
72                 new FailOnReportStyle.ClassFilter( null );
73             fail( "Did not throw a BuildException." );
74         }
75         catch (BuildException be)
76         {
77             assertTrue(
78                 "Does not contain correct exception text.",
79                 be.getMessage().indexOf( "Invalid class filter '" ) >= 0 );
80         }
81     }
82     
83     public void testClassFilterConstructor2()
84     {
85         try
86         {
87             FailOnReportStyle.ClassFilter cf =
88                 new FailOnReportStyle.ClassFilter( ".a" );
89             fail( "Did not throw a BuildException." );
90         }
91         catch (BuildException be)
92         {
93             assertTrue(
94                 "Does not contain correct exception text.",
95                 be.getMessage().indexOf( "Invalid class filter '" ) >= 0 );
96         }
97     }
98     
99     public void testClassFilterConstructor3()
100     {
101         try
102         {
103             FailOnReportStyle.ClassFilter cf =
104                 new FailOnReportStyle.ClassFilter( "" );
105             fail( "Did not throw a BuildException." );
106         }
107         catch (BuildException be)
108         {
109             assertTrue(
110                 "Does not contain correct exception text.",
111                 be.getMessage().indexOf( "Invalid class filter '" ) >= 0 );
112         }
113     }
114     
115     public void testClassFilterConstructor4()
116     {
117         try
118         {
119             FailOnReportStyle.ClassFilter cf =
120                 new FailOnReportStyle.ClassFilter( "a..b" );
121             fail( "Did not throw a BuildException." );
122         }
123         catch (BuildException be)
124         {
125             assertTrue(
126                 "Does not contain correct exception text.",
127                 be.getMessage().indexOf( "Invalid class filter '" ) >= 0 );
128         }
129     }
130     
131     public void testClassFilterConstructor5()
132     {
133         try
134         {
135             FailOnReportStyle.ClassFilter cf =
136                 new FailOnReportStyle.ClassFilter( "a//b" );
137             fail( "Did not throw a BuildException." );
138         }
139         catch (BuildException be)
140         {
141             assertTrue(
142                 "Does not contain correct exception text.",
143                 be.getMessage().indexOf( "Invalid class filter '" ) >= 0 );
144         }
145     }
146     
147     public void testClassFilterConstructor6()
148     {
149         try
150         {
151             FailOnReportStyle.ClassFilter cf =
152                 new FailOnReportStyle.ClassFilter( "a." );
153             fail( "Did not throw a BuildException." );
154         }
155         catch (BuildException be)
156         {
157             assertTrue(
158                 "Does not contain correct exception text.",
159                 be.getMessage().indexOf( "Invalid class filter '" ) >= 0 );
160         }
161     }
162     
163     public void testClassFilterConstructor7()
164     {
165         try
166         {
167             FailOnReportStyle.ClassFilter cf =
168                 new FailOnReportStyle.ClassFilter( "a.b*c" );
169             fail( "Did not throw a BuildException." );
170         }
171         catch (BuildException be)
172         {
173             assertTrue(
174                 "Does not contain correct exception text.",
175                 be.getMessage().indexOf(
176                     "Invalid class filter: a wildcard may "+
177                     "only be present before and after a text part." ) >= 0 );
178         }
179     }
180     
181     public void testClassFilterConstructor8()
182     {
183         try
184         {
185             FailOnReportStyle.ClassFilter cf =
186                 new FailOnReportStyle.ClassFilter( "a.b**.c" );
187             fail( "Did not throw a BuildException." );
188         }
189         catch (BuildException be)
190         {
191             assertTrue(
192                 "Does not contain correct exception text.",
193                 be.getMessage().indexOf( "Invalid class filter: "+
194                     "only 1 wildcard may be present between delimiters." ) >= 0 );
195         }
196     }
197     
198     public void testClassFilterConstructor9()
199     {
200         try
201         {
202             FailOnReportStyle.ClassFilter cf =
203                 new FailOnReportStyle.ClassFilter( "a/" );
204             fail( "Did not throw a BuildException." );
205         }
206         catch (BuildException be)
207         {
208             assertTrue(
209                 "Does not contain correct exception text.",
210                 be.getMessage().indexOf( "Invalid class filter '" ) >= 0 );
211         }
212     }
213     
214     public void testClassFilterMatch1()
215     {
216         FailOnReportStyle.ClassFilter cf =
217             new FailOnReportStyle.ClassFilter( "a.B" );
218         assertFalse(
219             "Incorrectly matched the filter.",
220             cf.match( "a.B$C" ) );
221     }
222     
223     public void testClassFilterMatch2()
224     {
225         FailOnReportStyle.ClassFilter cf =
226             new FailOnReportStyle.ClassFilter( "a.B" );
227         assertFalse(
228             "Incorrectly matched the filter.",
229             cf.match( "a.B.c" ) );
230     }
231     
232     public void testClassFilterMatch3()
233     {
234         FailOnReportStyle.ClassFilter cf =
235             new FailOnReportStyle.ClassFilter( "a.B" );
236         assertTrue(
237             "Should have matched the filter.",
238             cf.match( "a.B" ) );
239     }
240     
241     public void testClassFilterMatch4()
242     {
243         FailOnReportStyle.ClassFilter cf =
244             new FailOnReportStyle.ClassFilter( "a.*" );
245         assertTrue(
246             "Should have matched the filter.",
247             cf.match( "a.B" ) );
248     }
249     
250     public void testClassFilterMatch5()
251     {
252         FailOnReportStyle.ClassFilter cf =
253             new FailOnReportStyle.ClassFilter( "a.*" );
254         assertTrue(
255             "Should have matched the filter.",
256             cf.match( "a.B$C" ) );
257     }
258     
259     public void testClassFilterMatch6()
260     {
261         FailOnReportStyle.ClassFilter cf =
262             new FailOnReportStyle.ClassFilter( "a.*" );
263         assertFalse(
264             "Incorrectly matched the filter.",
265             cf.match( "a.B.C" ) );
266     }
267     
268     public void testClassFilterMatch7()
269     {
270         FailOnReportStyle.ClassFilter cf =
271             new FailOnReportStyle.ClassFilter( "a.*.C" );
272         assertFalse(
273             "Incorrectly matched the filter.",
274             cf.match( "a.b.c.C" ) );
275     }
276     
277     public void testClassFilterMatch8()
278     {
279         FailOnReportStyle.ClassFilter cf =
280             new FailOnReportStyle.ClassFilter( "a.*.C" );
281         assertFalse(
282             "Incorrectly matched the filter.",
283             cf.match( "a.b.C$" ) );
284     }
285     
286     public void testClassFilterMatch9()
287     {
288         FailOnReportStyle.ClassFilter cf =
289             new FailOnReportStyle.ClassFilter( "a.*.C" );
290         assertTrue(
291             "Did not matched the filter.",
292             cf.match( "a.b.C" ) );
293     }
294     
295     public void testClassFilterMatch10()
296     {
297         FailOnReportStyle.ClassFilter cf =
298             new FailOnReportStyle.ClassFilter( "a.b*.C" );
299         assertTrue(
300             "Did not matched the filter.",
301             cf.match( "a.b.C" ) );
302     }
303     
304     public void testClassFilterMatch11()
305     {
306         FailOnReportStyle.ClassFilter cf =
307             new FailOnReportStyle.ClassFilter( "a.b*.C" );
308         assertTrue(
309             "Did not matched the filter.",
310             cf.match( "a.bc.C" ) );
311     }
312     
313     public void testClassFilterMatch12()
314     {
315         FailOnReportStyle.ClassFilter cf =
316             new FailOnReportStyle.ClassFilter( "a.b*.C" );
317         assertFalse(
318             "Incorrectly matched the filter.",
319             cf.match( "a.ab.C" ) );
320     }
321     
322     public void testClassFilterMatch13()
323     {
324         FailOnReportStyle.ClassFilter cf =
325             new FailOnReportStyle.ClassFilter( "a.b*.C" );
326         assertFalse(
327             "Incorrectly matched the filter.",
328             cf.match( "a.ba.D" ) );
329     }
330     
331     public void testClassFilterMatch14()
332     {
333         FailOnReportStyle.ClassFilter cf =
334             new FailOnReportStyle.ClassFilter( "a.*bc.C" );
335         assertFalse(
336             "Incorrectly matched the filter.",
337             cf.match( "a.bca.C" ) );
338     }
339     
340     public void testClassFilterMatch15()
341     {
342         FailOnReportStyle.ClassFilter cf =
343             new FailOnReportStyle.ClassFilter( "a.*bc.C" );
344         assertFalse(
345             "Incorrectly matched the filter.",
346             cf.match( "a.b.C" ) );
347     }
348     
349     public void testClassFilterMatch16()
350     {
351         FailOnReportStyle.ClassFilter cf =
352             new FailOnReportStyle.ClassFilter( "a.*bc.C" );
353         assertFalse(
354             "Incorrectly matched the filter.",
355             cf.match( "a.bc.D" ) );
356     }
357     
358     public void testClassFilterMatch17()
359     {
360         FailOnReportStyle.ClassFilter cf =
361             new FailOnReportStyle.ClassFilter( "a.*bc.C" );
362         assertFalse(
363             "Incorrectly matched the filter.",
364             cf.match( "a.bc.CD" ) );
365     }
366     
367     public void testClassFilterMatch18()
368     {
369         FailOnReportStyle.ClassFilter cf =
370             new FailOnReportStyle.ClassFilter( "a.*bc.C" );
371         assertTrue(
372             "Did not matched the filter.",
373             cf.match( "a.bc.C" ) );
374     }
375     
376     public void testClassFilterMatch19()
377     {
378         FailOnReportStyle.ClassFilter cf =
379             new FailOnReportStyle.ClassFilter( "a.*bc.C" );
380         assertTrue(
381             "Did not matched the filter.",
382             cf.match( "a.adbbc.C" ) );
383     }
384     
385     public void testClassFilterMatch20()
386     {
387         FailOnReportStyle.ClassFilter cf =
388             new FailOnReportStyle.ClassFilter( "a.**.C" );
389         assertTrue(
390             "Did not matched the filter.",
391             cf.match( "a.adbbc.C" ) );
392     }
393     
394     /**
395      * Special case!!!!
396      */

397     public void testClassFilterMatch21()
398     {
399         FailOnReportStyle.ClassFilter cf =
400             new FailOnReportStyle.ClassFilter( "a.**.C" );
401         assertTrue(
402             "Did not matched the filter.",
403             cf.match( "a.C" ) );
404     }
405     
406     public void testClassFilterMatch22()
407     {
408         FailOnReportStyle.ClassFilter cf =
409             new FailOnReportStyle.ClassFilter( "a.**.C" );
410         assertTrue(
411             "Did not matched the filter.",
412             cf.match( "a.B.a.a.a.a.a.a.a.a.a.a.C" ) );
413     }
414     
415     public void testClassFilterMatch23()
416     {
417         FailOnReportStyle.ClassFilter cf =
418             new FailOnReportStyle.ClassFilter( "a.**.C" );
419         assertFalse(
420             "Incorrectly matched the filter.",
421             cf.match( "a.B.a.C.a.a.a.a.a.a.a.a.C" ) );
422     }
423     
424     public void testClassFilterMatch24()
425     {
426         FailOnReportStyle.ClassFilter cf =
427             new FailOnReportStyle.ClassFilter( "a.**" );
428         assertTrue(
429             "Did not matched the filter.",
430             cf.match( "a.B.a.a.a.a.a.a.a.a.a.a.C" ) );
431     }
432     
433     public void testClassFilterMatch25()
434     {
435         FailOnReportStyle.ClassFilter cf =
436             new FailOnReportStyle.ClassFilter( "a.**" );
437         assertFalse(
438             "Incorrectly matched the filter.",
439             cf.match( "b.C" ) );
440     }
441     
442     public void testClassFilterMatch26()
443     {
444         FailOnReportStyle.ClassFilter cf =
445             new FailOnReportStyle.ClassFilter( "a.**" );
446         assertFalse(
447             "Incorrectly matched the filter.",
448             cf.match( "a" ) );
449     }
450     
451     
452     //...........................
453
// Tests that pass
454

455     
456     public void testFailon1()
457     {
458         try
459         {
460             executeTarget( "failon-1" );
461         }
462         finally
463         {
464             System.out.println( "--------------------------------" );
465             System.out.println( "failon-1:" );
466             System.out.println( getFullLog() );
467         }
468     }
469     
470     public void testFailon2()
471     {
472         executeTarget( "failon-2" );
473     }
474     
475     public void testFailon3()
476     {
477         executeTarget( "failon-3" );
478     }
479     
480     public void testFailon4()
481     {
482         executeTarget( "failon-4" );
483     }
484     
485     public void testFailon5()
486     {
487         try
488         {
489             executeTarget( "failon-5" );
490         }
491         finally
492         {
493             System.out.println( "--------------------------------" );
494             System.out.println( "failon-5:" );
495             System.out.println( getFullLog() );
496         }
497     }
498     
499     
500     //...........................
501
// Tests that fail
502

503     
504     public void testFFailon1()
505     {
506         expectBuildException( "f-failon-1",
507             "Did not fail for below coverage numbers." );
508     }
509     
510     public void testFFailon2()
511     {
512         expectBuildExceptionContaining( "f-failon-2",
513             "Did not fail for invalid filter.",
514             "Invalid class filter '" );
515     }
516     
517     public void testFFailon3()
518     {
519         expectBuildExceptionContaining( "f-failon-3",
520             "Did not fail for invalid filter.",
521             "Invalid class filter '" );
522     }
523     
524     public void testFFailon4()
525     {
526         expectBuildExceptionContaining( "f-failon-4",
527             "Did not fail for invalid filter.",
528             "Invalid class filter '" );
529     }
530     
531     public void testFFailon5()
532     {
533         expectBuildExceptionContaining( "f-failon-5",
534             "Did not fail for invalid filter.",
535             "Invalid class filter '" );
536     }
537     
538     public void testFFailon6()
539     {
540         expectBuildExceptionContaining( "f-failon-6",
541             "Did not fail for invalid filter.",
542             "Invalid class filter '" );
543     }
544     
545     public void testFFailon7()
546     {
547         expectBuildExceptionContaining( "f-failon-7",
548             "Did not fail for nothing specified.",
549             "One of 'module' or 'class' attributes must be specified in an include element." );
550     }
551     
552     public void testFFailon8()
553     {
554         expectBuildException( "f-failon-8",
555             "Did not fail for below coverage numbers." );
556     }
557     
558     
559     //-------------------------------------------------------------------------
560
// Helpers
561

562     
563     protected void assertEquals( String JavaDoc text, Properties JavaDoc expected,
564             Properties JavaDoc actual )
565     {
566         PropertyCheckUtil.assertEquals( text, expected, actual );
567     }
568     
569
570     protected Properties JavaDoc loadGroboProperties()
571             throws IOException JavaDoc
572     {
573         return loadProperties(
574             (new File JavaDoc( getCoverageDir(),
575                 "classes" + File.separator + "grobocoverage.properties")).
576             getAbsolutePath() );
577     }
578     
579     
580     protected Properties JavaDoc loadProperties( String JavaDoc file )
581             throws IOException JavaDoc
582     {
583         return PropertyCheckUtil.loadProperties( file );
584     }
585     
586     
587     protected File JavaDoc getCoverageDir()
588     {
589         return new File JavaDoc( getProjectDir(), "instrument" +
590             File.separator + "coverage" );
591     }
592     
593     
594     //-------------------------------------------------------------------------
595
// Standard JUnit declarations
596

597     
598     public static Test suite()
599     {
600         TestSuite suite = new TestSuite( THIS_CLASS );
601         
602         return suite;
603     }
604     
605     public static void main( String JavaDoc[] args )
606     {
607         String JavaDoc[] name = { THIS_CLASS.getName() };
608         
609         // junit.textui.TestRunner.main( name );
610
// junit.swingui.TestRunner.main( name );
611

612         junit.textui.TestRunner.main( name );
613     }
614     
615     
616     /**
617      *
618      * @exception Exception thrown under any exceptional condition.
619      */

620     protected void setUp() throws Exception JavaDoc
621     {
622         super.setUp();
623         
624         // set ourself up
625
configureProject( "failon.xml" );
626     }
627     
628     
629     /**
630      *
631      * @exception Exception thrown under any exceptional condition.
632      */

633     protected void tearDown() throws Exception JavaDoc
634     {
635         // tear ourself down
636
executeTarget( "test-teardown" );
637         
638         super.tearDown();
639     }
640 }
641
642
Popular Tags