KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)DirClassMetaDataReaderUTest.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 java.io.IOException JavaDoc;
30 import java.util.Vector JavaDoc;
31
32 import junit.framework.Test;
33 import junit.framework.TestCase;
34 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
35 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
36 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
37 import net.sourceforge.groboutils.codecoverage.v2.compiler.ModifiedClass;
38 import net.sourceforge.groboutils.junit.v1.iftc.CxFactory;
39 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite;
40
41
42 /**
43  * Tests the DirClassMetaDataReader 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:28 $
47  * @since January 22, 2003
48  */

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

54     private static final Class JavaDoc THIS_CLASS = DirClassMetaDataReaderUTest.class;
55     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
56     
57     public DirClassMetaDataReaderUTest( 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 DirClassMetaDataReader( null, null );
72             fail( "Did not throw IllegalArgumentException." );
73         }
74         catch (IllegalArgumentException JavaDoc ex)
75         {
76             // test exception
77
}
78     }
79     
80     
81     public void testConstructor2() throws Exception JavaDoc
82     {
83         try
84         {
85             new DirClassMetaDataReader(
86                 createIAnalysisModule( "A", "B", "C" ), null );
87             fail( "Did not throw IllegalArgumentException." );
88         }
89         catch (IllegalArgumentException JavaDoc ex)
90         {
91             // test exception
92
}
93     }
94     
95     
96     public void testConstructor3() throws Exception JavaDoc
97     {
98         try
99         {
100             new DirClassMetaDataReader( null,
101                 createDirMetaDataIO( createIAnalysisModule( "A", "B", "C" ) ) );
102             fail( "Did not throw IllegalArgumentException." );
103         }
104         catch (IllegalArgumentException JavaDoc ex)
105         {
106             // test exception
107
}
108     }
109     
110     
111     public void testGetClassSignatures1() throws Exception JavaDoc
112     {
113         IAnalysisModule am = createIAnalysisModule( "A", "B", "C" );
114         DirMetaDataIO dmdio = createDirMetaDataIO( am );
115         String JavaDoc sig1 = addClassRecord( dmdio, THIS_CLASS, am );
116         
117         DirClassMetaDataReader dcmdr = new DirClassMetaDataReader(
118             am, dmdio );
119         String JavaDoc[] sigs = dcmdr.getClassSignatures();
120         assertNotNull(
121             "Returned null signatures.",
122             sigs );
123         assertEquals(
124             "Returned incorrect number of signatures.",
125             1,
126             sigs.length );
127         assertEquals(
128             "Did not return the correct sig.",
129             sig1,
130             sigs[0] );
131     }
132     
133     
134     public void testReadClass1() throws Exception JavaDoc
135     {
136         IAnalysisModule am = createIAnalysisModule( "A", "B", "C" );
137         DirMetaDataIO dmdio = createDirMetaDataIO( am );
138         String JavaDoc sig1 = addClassRecord( dmdio, THIS_CLASS, am );
139         
140         DirClassMetaDataReader dcmdr = new DirClassMetaDataReader(
141             am, dmdio );
142         ClassRecord cr = dcmdr.readClass( sig1 );
143         assertNotNull(
144             "Returned null class record.",
145             cr );
146         assertEquals(
147             "Returned incorrect class record.",
148             sig1,
149             cr.getClassSignature() );
150     }
151     
152     
153     public void testClose1() throws Exception JavaDoc
154     {
155         IAnalysisModule am = createIAnalysisModule( "A", "B", "C" );
156         DirMetaDataIO dmdio = createDirMetaDataIO( am );
157         DirClassMetaDataReader dcmdr = new DirClassMetaDataReader(
158             am, dmdio );
159         
160         dcmdr.close();
161         
162         assertFalse(
163             "Reader closed the underlying IO object.",
164             dmdio.isClosed() );
165     }
166     
167     
168     //-------------------------------------------------------------------------
169
// Helpers
170

171     protected static IAnalysisModule createIAnalysisModule( String JavaDoc name,
172             String JavaDoc unit, String JavaDoc mime )
173     {
174         return CCCreatorUtil.createIAnalysisModule( name, unit, mime );
175     }
176     
177     protected static DirMetaDataIO createDirMetaDataIO( IAnalysisModule am )
178             throws IOException JavaDoc
179     {
180         DirMetaDataIO dmd = new DirMetaDataIO(
181             CCCreatorUtil.createNewDirectory() );
182         dmd.putAnalysisModuleSet(
183             new AnalysisModuleSet( new IAnalysisModule[] { am } ) );
184         return dmd;
185     }
186     
187     protected String JavaDoc addClassRecord( DirMetaDataIO dmd, Class JavaDoc c,
188             IAnalysisModule am )
189             throws IOException JavaDoc
190     {
191         ModifiedClass mc = CCCreatorUtil.createModifiedClass( c );
192         ClassRecord cr = mc.createClassRecord( new AnalysisModuleSet(
193             new IAnalysisModule[] { am } ) );
194         dmd.putClassRecord( am, cr );
195         return cr.getClassSignature();
196     }
197     
198     
199     
200     
201     //-------------------------------------------------------------------------
202
// Standard JUnit declarations
203

204     
205     public static Test suite()
206     {
207         InterfaceTestSuite suite = IClassMetaDataReaderUTestI.suite();
208         suite.addTestSuite( THIS_CLASS );
209         suite.addFactory( new CxFactory( "A" ) {
210             Vector JavaDoc v = new Vector JavaDoc();
211             public Object JavaDoc createImplObject() throws IOException JavaDoc {
212                 IAnalysisModule am = createIAnalysisModule( "a", "u",
213                     "text/plain" );
214                 DirMetaDataIO dmd = createDirMetaDataIO( am );
215                 v.addElement( dmd );
216                 return new DirClassMetaDataReader( am, dmd );
217             }
218         } );
219         suite.addFactory( new CxFactory( "B" ) {
220             Vector JavaDoc v = new Vector JavaDoc();
221             public Object JavaDoc createImplObject() throws IOException JavaDoc {
222                 IAnalysisModule am = createIAnalysisModule( "a", "u",
223                     "text/plain" );
224                 DirMetaDataReader dmdr = CCCreatorUtil.createDirMetaDataReader(
225                     CCCreatorUtil.createNewDirectory(),
226                     new Class JavaDoc[0],
227                     new IAnalysisModule[] { am } );
228                 DirClassMetaDataReader dcmdr = (DirClassMetaDataReader)
229                     dmdr.getClassReader( am );
230                 // prevent the closing of the DMDR
231
v.addElement( dmdr );
232                 return dcmdr;
233             }
234         } );
235         suite.addFactory( new CxFactory( "C" ) {
236             Vector JavaDoc v = new Vector JavaDoc();
237             public Object JavaDoc createImplObject() throws IOException JavaDoc {
238                 IAnalysisModule am = createIAnalysisModule( "a", "u",
239                     "text/plain" );
240                 DirMetaDataReader dmdr = CCCreatorUtil.createDirMetaDataReader(
241                     CCCreatorUtil.createNewDirectory(),
242                     new Class JavaDoc[] { THIS_CLASS, String JavaDoc.class, Short JavaDoc.class },
243                     new IAnalysisModule[] { am } );
244                 DirClassMetaDataReader dcmdr = (DirClassMetaDataReader)
245                     dmdr.getClassReader( am );
246                 // prevent the closing of the DMDR
247
v.addElement( dmdr );
248                 return dcmdr;
249             }
250         } );
251         return suite;
252     }
253     
254     public static void main( String JavaDoc[] args )
255     {
256         String JavaDoc[] name = { THIS_CLASS.getName() };
257         
258         // junit.textui.TestRunner.main( name );
259
// junit.swingui.TestRunner.main( name );
260

261         junit.textui.TestRunner.main( name );
262     }
263     
264     
265     /**
266      *
267      * @exception Exception thrown under any exceptional condition.
268      */

269     protected void setUp() throws Exception JavaDoc
270     {
271         super.setUp();
272
273        
274         // set ourself up
275
}
276     
277     
278     /**
279      *
280      * @exception Exception thrown under any exceptional condition.
281      */

282     protected void tearDown() throws Exception JavaDoc
283     {
284         // tear ourself down
285

286         
287         super.tearDown();
288     }
289 }
290
291
Popular Tags