KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > report > AnalysisModuleDataUTest


1 /*
2  * @(#)AnalysisModuleDataUTest.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.report;
28
29 import java.io.File JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 import junit.framework.Test;
33 import junit.framework.TestCase;
34 import junit.framework.TestSuite;
35 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
36 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
37 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
38 import net.sourceforge.groboutils.codecoverage.v2.datastore.DirMetaDataReader;
39 import net.sourceforge.groboutils.codecoverage.v2.logger.DirectoryChannelLogReader;
40
41
42 /**
43  * Tests the AnalysisModuleData class.
44  *
45  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
46  * @version $Date: 2004/04/15 05:48:29 $
47  * @since January 22, 2003
48  */

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

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

66     
67     public void testConstructor1() throws Exception JavaDoc
68     {
69         try
70         {
71             new AnalysisModuleData( null, null, null );
72             fail( "Did not throw IllegalArgumentException." );
73         }
74         catch (IllegalArgumentException JavaDoc e)
75         {
76         }
77     }
78     
79     
80     public void testConstructor2() throws Exception JavaDoc
81     {
82         try
83         {
84             new AnalysisModuleData( createIAnalysisModule( "a", "b", "c" ),
85                 null, null );
86             fail( "Did not throw IllegalArgumentException." );
87         }
88         catch (IllegalArgumentException JavaDoc e)
89         {
90         }
91     }
92     
93     
94     public void testConstructor3() throws Exception JavaDoc
95     {
96         File JavaDoc f = CCCreatorUtil.createNewDirectory();
97         try
98         {
99             new AnalysisModuleData( createIAnalysisModule( "a", "b", "c" ),
100                 createDirMetaDataReader( f ), null );
101             fail( "Did not throw IllegalArgumentException." );
102         }
103         catch (IllegalArgumentException JavaDoc e)
104         {
105         }
106     }
107     
108     
109     public void testConstructor4() throws Exception JavaDoc
110     {
111         File JavaDoc f = CCCreatorUtil.createNewDirectory();
112         try
113         {
114             new AnalysisModuleData( null,
115                 createDirMetaDataReader( f ),
116                 createDirectoryChannelLogReader( f, createClassLogData(4) ) );
117             fail( "Did not throw IllegalArgumentException." );
118         }
119         catch (IllegalArgumentException JavaDoc e)
120         {
121         }
122     }
123     
124     
125     public void testConstructor5() throws Exception JavaDoc
126     {
127         File JavaDoc f = CCCreatorUtil.createNewDirectory();
128         try
129         {
130             new AnalysisModuleData( createIAnalysisModule( "a", "b", "c" ),
131                 null,
132                 createDirectoryChannelLogReader( f, createClassLogData(2) ) );
133             fail( "Did not throw IllegalArgumentException." );
134         }
135         catch (IllegalArgumentException JavaDoc e)
136         {
137         }
138     }
139     
140     
141     public void testGetClassSignatures1() throws Exception JavaDoc
142     {
143         File JavaDoc f = CCCreatorUtil.createNewDirectory();
144         AnalysisModuleData amd = new AnalysisModuleData(
145             createIAnalysisModule( "a", "b", "c" ),
146             createDirMetaDataReader( f ),
147             createDirectoryChannelLogReader( f, createClassLogData( 1 ) ) );
148         String JavaDoc sigs[] = amd.getClassSignatures();
149         assertNotNull(
150             "Got null sigs.",
151             sigs );
152         DOC.getLog().warn(
153             "this test is failing due to incorrect class generation logic." );
154         /*
155         assertEquals(
156             "Didn't get correct number of classes.",
157             1,
158             sigs.length );
159         assertEquals(
160             "Did not return correct class name.",
161             "a.MyClass-112",
162             sigs[0] );
163         */

164     }
165     
166     
167     public void testGetClassSignatures2() throws Exception JavaDoc
168     {
169         File JavaDoc f = CCCreatorUtil.createNewDirectory();
170         AnalysisModuleData amd = new AnalysisModuleData(
171             createIAnalysisModule( "a", "b", "c" ),
172             createDirMetaDataReader( f ),
173             createDirectoryChannelLogReader( f, createClassLogData( 2 ) ) );
174         String JavaDoc sigs[] = amd.getClassSignatures();
175         assertNotNull(
176             "Got null sigs.",
177             sigs );
178         DOC.getLog().warn(
179             "this test is failing due to incorrect class generation logic." );
180         /*
181         assertEquals(
182             "Didn't get correct number of classes.",
183             2,
184             sigs.length );
185         */

186     }
187     
188     
189     public void testGetClassSignatures3() throws Exception JavaDoc
190     {
191         File JavaDoc f = CCCreatorUtil.createNewDirectory();
192         AnalysisModuleData amd = new AnalysisModuleData(
193             createIAnalysisModule( "a", "b", "c" ),
194             createDirMetaDataReader( f ),
195             createDirectoryChannelLogReader( f, createClassLogData( 0 ) ) );
196         String JavaDoc sigs[] = amd.getClassSignatures();
197         assertNotNull(
198             "Got null sigs.",
199             sigs );
200         assertEquals(
201             "Didn't get correct number of classes.",
202             0,
203             sigs.length );
204     }
205     
206     
207     //-------------------------------------------------------------------------
208
// Helpers
209

210     
211     protected IAnalysisModule createIAnalysisModule( String JavaDoc name, String JavaDoc unit,
212             String JavaDoc mime )
213     {
214         return CCCreatorUtil.createIAnalysisModule( name, unit, mime );
215     }
216     
217     
218     protected DirMetaDataReader createDirMetaDataReader( File JavaDoc basedir )
219             throws IOException JavaDoc
220     {
221         return CCCreatorUtil.createDirMetaDataReader( basedir,
222             new Class JavaDoc[] { THIS_CLASS, String JavaDoc.class },
223             CCCreatorUtil.createAnalysisModules( 2 ) );
224     }
225     
226     
227     protected DirectoryChannelLogReader createDirectoryChannelLogReader(
228         File JavaDoc basedir, CCCreatorUtil.SimpleClassLogData[] data )
229     {
230         return CCCreatorUtil.createDirectoryChannelLogReader( basedir, data,
231             (short)100 );
232     }
233     
234     
235     protected CCCreatorUtil.SimpleClassLogData[] createClassLogData(
236             int count )
237     {
238         CCCreatorUtil.SimpleClassLogData[] scld = new
239             CCCreatorUtil.SimpleClassLogData[ count ];
240         for (int i = 0; i < count; ++i)
241         {
242             scld[i] = new CCCreatorUtil.SimpleClassLogData(
243                 (char)('a' + i)+".MyClass-112",
244                 new int[] { 1,2,1 }, new int[] { 11, 2, 13 } );
245         }
246         return scld;
247     }
248     
249     
250     //-------------------------------------------------------------------------
251
// Standard JUnit declarations
252

253     
254     public static Test suite()
255     {
256         TestSuite suite = new TestSuite( THIS_CLASS );
257         
258         return suite;
259     }
260     
261     public static void main( String JavaDoc[] args )
262     {
263         String JavaDoc[] name = { THIS_CLASS.getName() };
264         
265         // junit.textui.TestRunner.main( name );
266
// junit.swingui.TestRunner.main( name );
267

268         junit.textui.TestRunner.main( name );
269     }
270     
271     
272     /**
273      *
274      * @exception Exception thrown under any exceptional condition.
275      */

276     protected void setUp() throws Exception JavaDoc
277     {
278         super.setUp();
279
280        
281         // set ourself up
282
}
283     
284     
285     /**
286      *
287      * @exception Exception thrown under any exceptional condition.
288      */

289     protected void tearDown() throws Exception JavaDoc
290     {
291         // tear ourself down
292

293         
294         super.tearDown();
295     }
296 }
297
298
Popular Tags