KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > datastore > AnalysisModuleSetUTest


1 /*
2  * @(#)AnalysisModuleSetUTest.java
3  *
4  * Copyright (C) 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.codecoverage.v2.datastore;
28
29 import junit.framework.Test;
30 import junit.framework.TestCase;
31 import junit.framework.TestSuite;
32 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
33 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
34 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
35
36
37 /**
38  * Tests the AnalysisModuleSet class.
39  *
40  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
41  * @version $Date: 2004/04/15 05:48:28 $
42  * @since January 22, 2003
43  */

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

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

61     
62     public void testConstructor1()
63     {
64         try
65         {
66             new AnalysisModuleSet( (IAnalysisModule[])null );
67             fail( "Did not throw IllegalArgumentException." );
68         }
69         catch (IllegalArgumentException JavaDoc ex)
70         {
71             // check exception
72
}
73     }
74     
75     
76     public void testConstructor2()
77     {
78         try
79         {
80             new AnalysisModuleSet( (AnalysisModuleSet)null );
81             fail( "Did not throw IllegalArgumentException." );
82         }
83         catch (IllegalArgumentException JavaDoc ex)
84         {
85             // check exception
86
}
87     }
88     
89     
90     public void testConstructor3()
91     {
92         try
93         {
94             new AnalysisModuleSet( new IAnalysisModule[1] );
95             fail( "Did not throw IllegalArgumentException." );
96         }
97         catch (IllegalArgumentException JavaDoc ex)
98         {
99             // check exception
100
}
101     }
102     
103     
104     public void testConstructor4()
105     {
106         try
107         {
108             new AnalysisModuleSet( new IAnalysisModule[] {
109                 createIAnalysisModule( "0" ), null } );
110             fail( "Did not throw IllegalArgumentException." );
111         }
112         catch (IllegalArgumentException JavaDoc ex)
113         {
114             // check exception
115
}
116     }
117     
118     
119     public void testConstructor5()
120     {
121         new AnalysisModuleSet( new AnalysisModuleSet() );
122     }
123     
124     
125     public void testAddAnalysisModule1()
126     {
127         AnalysisModuleSet ams = new AnalysisModuleSet();
128         IAnalysisModule a1 = createIAnalysisModule( "a" );
129         IAnalysisModule a2 = createIAnalysisModule( "a" );
130         assertEquals( a1.getMeasureName(), a2.getMeasureName() );
131         ams.addAnalysisModule( a1 );
132         try
133         {
134             ams.addAnalysisModule( a2 );
135             fail( "Did not throw IllegalStateException." );
136         }
137         catch (IllegalStateException JavaDoc ex)
138         {
139             // test exception
140
}
141     }
142     
143     
144     public void testAddAnalysisModule2()
145     {
146         AnalysisModuleSet ams = new AnalysisModuleSet();
147         try
148         {
149             ams.addAnalysisModule( null );
150             fail( "Did not throw IllegalStateException." );
151         }
152         catch (IllegalArgumentException JavaDoc iae)
153         {
154             // check exception
155
}
156     }
157     
158     
159     public void testJoinAnalysisModuleSet1()
160     {
161         AnalysisModuleSet ams = new AnalysisModuleSet();
162         try
163         {
164             ams.joinAnalysisModuleSet( null );
165             fail( "Did not throw IllegalStateException." );
166         }
167         catch (IllegalArgumentException JavaDoc iae)
168         {
169             // check exception
170
}
171     }
172     
173     
174     public void testJoinAnalysisModuleSet2()
175     {
176         IAnalysisModule a1 = createIAnalysisModule( "a" );
177         AnalysisModuleSet ams = new AnalysisModuleSet(
178             new IAnalysisModule[] { a1 } );
179         ams.joinAnalysisModuleSet( ams );
180     }
181     
182     
183     public void testJoinAnalysisModuleSet3()
184     {
185         IAnalysisModule a1 = createIAnalysisModule( "a" );
186         IAnalysisModule a2 = createIAnalysisModule( "b" );
187         AnalysisModuleSet ams = new AnalysisModuleSet(
188             new IAnalysisModule[] { a1 } );
189         ams.joinAnalysisModuleSet( new AnalysisModuleSet(
190             new IAnalysisModule[] { a2 } ) );
191         assertEquals(
192             "Did not store correct number of modules.",
193             2,
194             ams.getAnalysisModuleCount() );
195     }
196     
197     
198     /* this test takes a VERY long time, and as such is not suitable for
199     unit tests. If you want to increase unit test coverage, though,
200     include this test to get 1 more branch and 1 more line. Not only that,
201     but this is a rarely encountered situation, and encountering this situation
202     may be a sign of a bug elsewhere.
203     public void testAddAnalysisModule2()
204     {
205         // test the limits of the short index vs. int internal structure
206         // counting system.
207         AnalysisModuleSet ams = new AnalysisModuleSet();
208         IAnalysisModule amL[] = CCCreatorUtil.createAnalysisModules(
209             (int)Short.MAX_VALUE );
210         ams.addAnalysisModules( amL );
211         IAnalysisModule a1 = createIAnalysisModule( "a" );
212         try
213         {
214             ams.addAnalysisModule( a1 );
215             fail( "Did not throw IllegalStateException." );
216         }
217         catch (IllegalStateException ex)
218         {
219             // test exception
220         }
221     }
222     */

223     
224     
225     public void testGetAnalysisModules1()
226     {
227         AnalysisModuleSet ams = new AnalysisModuleSet();
228         IAnalysisModule[] amL = ams.getAnalysisModules();
229         assertNotNull(
230             "Returned null module list.",
231             amL );
232         assertEquals(
233             "Returned invalid module array length.",
234             0,
235             amL.length );
236     }
237     
238     
239     public void testGetAnalysisModules2()
240     {
241         IAnalysisModule orig = createIAnalysisModule( "a" );
242         AnalysisModuleSet ams = new AnalysisModuleSet(
243             new IAnalysisModule[] { orig } );
244         IAnalysisModule[] amL = ams.getAnalysisModules();
245         assertNotNull(
246             "Returned null module list.",
247             amL );
248         assertEquals(
249             "Returned invalid module array length.",
250             1,
251             amL.length );
252         assertSame(
253             "Returned invalid module.",
254             orig,
255             amL[0] );
256     }
257     
258     
259     public void testGetMeasureIndex1()
260     {
261         AnalysisModuleSet ams = new AnalysisModuleSet();
262         short i = ams.getMeasureIndex( "b" );
263         assertEquals(
264             "Returned invalid index.",
265             -1,
266             i );
267     }
268     
269     
270     public void testGetMeasureIndex2()
271     {
272         IAnalysisModule orig = createIAnalysisModule( "b" );
273         AnalysisModuleSet ams = new AnalysisModuleSet(
274             new IAnalysisModule[] { orig } );
275         short i = ams.getMeasureIndex( "b" );
276         assertEquals(
277             "Returned invalid index.",
278             0,
279             i );
280     }
281     
282     
283     public void testGetMeasureIndex3()
284     {
285         AnalysisModuleSet ams = new AnalysisModuleSet();
286         try
287         {
288             ams.getMeasureIndex( null );
289             fail( "Did not throw IllegalArgumentException." );
290         }
291         catch (IllegalArgumentException JavaDoc ex)
292         {
293             // test exception
294
}
295     }
296     
297     
298     public void testGetAnalysisModuleIndex1()
299     {
300         AnalysisModuleSet ams = new AnalysisModuleSet();
301         try
302         {
303             ams.getAnalysisModuleIndex( null );
304             fail( "Did not throw IllegalArgumentException." );
305         }
306         catch (IllegalArgumentException JavaDoc ex)
307         {
308             // test exception
309
}
310     }
311     
312     
313     public void testGetAnalysisModuleIndex2()
314     {
315         IAnalysisModule orig = createIAnalysisModule( "b" );
316         AnalysisModuleSet ams = new AnalysisModuleSet();
317         short i = ams.getAnalysisModuleIndex( orig );
318         assertEquals(
319             "Did not return correct index.",
320             -1,
321             i );
322     }
323     
324     
325     public void testGetAnalysisModuleIndex3()
326     {
327         IAnalysisModule orig = createIAnalysisModule( "b" );
328         IAnalysisModule a = createIAnalysisModule( "a" );
329         AnalysisModuleSet ams = new AnalysisModuleSet(
330             new IAnalysisModule[] { a } );
331         short i = ams.getAnalysisModuleIndex( orig );
332         assertEquals(
333             "Did not return correct index.",
334             -1,
335             i );
336     }
337     
338     
339     public void testGetAnalysisModuleIndex4()
340     {
341         IAnalysisModule orig1 = createIAnalysisModule( "b" );
342         AnalysisModuleSet ams = new AnalysisModuleSet(
343             new IAnalysisModule[] { orig1 } );
344         short i = ams.getAnalysisModuleIndex( orig1 );
345         assertEquals(
346             "Did not return correct index.",
347             0,
348             i );
349     }
350     
351     
352     public void testGetAnalysisModuleCount1()
353     {
354         AnalysisModuleSet ams = new AnalysisModuleSet();
355         assertEquals(
356             "Did not return correct count.",
357             0,
358             ams.getAnalysisModuleCount() );
359     }
360     
361     
362     public void testGetAnalysisModuleCount2()
363     {
364         AnalysisModuleSet ams = new AnalysisModuleSet(
365             CCCreatorUtil.createAnalysisModules( 15 ) );
366         assertEquals(
367             "Did not return correct count.",
368             15,
369             ams.getAnalysisModuleCount() );
370     }
371     
372     
373     
374     
375     
376     
377     //-------------------------------------------------------------------------
378
// Helpers
379

380     
381     protected IAnalysisModule createIAnalysisModule( String JavaDoc name )
382     {
383         return CCCreatorUtil.createIAnalysisModule( name, "u", "m" );
384     }
385     
386     
387     
388     //-------------------------------------------------------------------------
389
// Standard JUnit declarations
390

391     
392     public static Test suite()
393     {
394         TestSuite suite = new TestSuite( THIS_CLASS );
395         
396         return suite;
397     }
398     
399     public static void main( String JavaDoc[] args )
400     {
401         String JavaDoc[] name = { THIS_CLASS.getName() };
402         
403         // junit.textui.TestRunner.main( name );
404
// junit.swingui.TestRunner.main( name );
405

406         junit.textui.TestRunner.main( name );
407     }
408     
409     
410     /**
411      *
412      * @exception Exception thrown under any exceptional condition.
413      */

414     protected void setUp() throws Exception JavaDoc
415     {
416         super.setUp();
417
418        
419         // set ourself up
420
}
421     
422     
423     /**
424      *
425      * @exception Exception thrown under any exceptional condition.
426      */

427     protected void tearDown() throws Exception JavaDoc
428     {
429         // tear ourself down
430

431         
432         super.tearDown();
433     }
434 }
435
436
Popular Tags