KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)IClassMetaDataReaderUTestI.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.codecoverage.v2.datastore;
28
29 import java.io.IOException JavaDoc;
30
31 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
32 import net.sourceforge.groboutils.junit.v1.iftc.ImplFactory;
33 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestCase;
34 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite;
35
36
37 /**
38  * Tests the IClassMetaDataReader interface.
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 December 28, 2002
43  */

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

49     private static final Class JavaDoc THIS_CLASS = IClassMetaDataReaderUTestI.class;
50     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
51     
52     public IClassMetaDataReaderUTestI( String JavaDoc name, ImplFactory f )
53     {
54         super( name, IClassMetaDataReader.class, f );
55     }
56
57     
58     public IClassMetaDataReader createIClassMetaDataReader()
59     {
60         return (IClassMetaDataReader)createImplObject();
61     }
62
63
64     //-------------------------------------------------------------------------
65
// Tests
66

67     
68     public void testGetClassSignatures1() throws Exception JavaDoc
69     {
70         IClassMetaDataReader cmdr = createIClassMetaDataReader();
71         String JavaDoc sigs1[] = cmdr.getClassSignatures();
72         assertNotNull(
73             "Returned null sigs.",
74             sigs1 );
75         String JavaDoc sigs2[] = cmdr.getClassSignatures();
76         assertNotNull(
77             "Returned null sigs on second attempt.",
78             sigs2 );
79         assertEquals(
80             "Two consecutive calls returned different class signatures.",
81             sigs1.length,
82             sigs2.length );
83     }
84     
85     
86     public void testGetClassSignatures2() throws Exception JavaDoc
87     {
88         IClassMetaDataReader cmdr = createIClassMetaDataReader();
89         cmdr.close();
90         try
91         {
92             cmdr.getClassSignatures();
93             fail( "Did not throw IOException." );
94         }
95         catch (IOException JavaDoc ioe)
96         {
97             assertNotNull( "Null exception message.", ioe.getMessage() );
98         }
99     }
100     
101     
102     public void testGetClassSignatures3() throws Exception JavaDoc
103     {
104         IClassMetaDataReader cmdr = createIClassMetaDataReader();
105         String JavaDoc sigs1[] = cmdr.getClassSignatures();
106         cmdr.close();
107         try
108         {
109             cmdr.getClassSignatures();
110             fail( "Did not throw IOException." );
111         }
112         catch (IOException JavaDoc ioe)
113         {
114             assertNotNull( "Null exception message.", ioe.getMessage() );
115         }
116     }
117     
118     
119     public void testGetClassSignatures4() throws Exception JavaDoc
120     {
121         IClassMetaDataReader cmdr = createIClassMetaDataReader();
122         String JavaDoc sigs[] = cmdr.getClassSignatures();
123         for (int i = 0; i < sigs.length; ++i)
124         {
125             assertNotNull(
126                 "Returned null signature at index "+i+".",
127                 sigs[i] );
128         }
129     }
130     
131     
132     public void testReadClass1() throws Exception JavaDoc
133     {
134         IClassMetaDataReader cmdr = createIClassMetaDataReader();
135         cmdr.close();
136         try
137         {
138             cmdr.readClass( "a" );
139             fail( "Did not throw IOException." );
140         }
141         catch (IOException JavaDoc ioe)
142         {
143             assertNotNull( "Null exception message.", ioe.getMessage() );
144         }
145     }
146     
147     
148     public void testReadClass2() throws Exception JavaDoc
149     {
150         IClassMetaDataReader cmdr = createIClassMetaDataReader();
151         cmdr.close();
152         try
153         {
154             cmdr.readClass( null );
155             fail( "Did not throw IllegalArgumentException." );
156         }
157         catch (IllegalArgumentException JavaDoc ex)
158         {
159             assertNotNull( "Null exception message.", ex.getMessage() );
160         }
161     }
162     
163     
164     public void testReadClass3() throws Exception JavaDoc
165     {
166         IClassMetaDataReader cmdr = createIClassMetaDataReader();
167         String JavaDoc nonExistClassName = "a";
168         String JavaDoc sigs[] = cmdr.getClassSignatures();
169         boolean inSigs = true;
170         while (inSigs)
171         {
172             nonExistClassName += "1";
173             inSigs = false;
174             for (int i = 0; i < sigs.length; ++i)
175             {
176                 if (sigs[i].equals( nonExistClassName ))
177                 {
178                     inSigs = true;
179                     break;
180                 }
181             }
182         }
183         
184         ClassRecord cr = cmdr.readClass( nonExistClassName );
185         assertNull(
186             "Incorrectly returned a class for a non-existent class "+
187                 "signature '"+nonExistClassName+"'.",
188             cr );
189     }
190     
191     
192     public void testReadAllClasses1() throws Exception JavaDoc
193     {
194         IClassMetaDataReader cmdr = createIClassMetaDataReader();
195         String JavaDoc sigs[] = cmdr.getClassSignatures();
196         assertNotNull(
197             "Returned null sigs.",
198             sigs );
199         for (int i = 0; i < sigs.length; ++i)
200         {
201             ClassRecord cr = cmdr.readClass( sigs[i] );
202             assertNotNull(
203                 "Read null class from returned class signature.",
204                 cr );
205         }
206     }
207     
208     
209     public void testClose1() throws Exception JavaDoc
210     {
211         IClassMetaDataReader cmdr = createIClassMetaDataReader();
212         cmdr.close();
213     }
214     
215     
216     public void testClose2() throws Exception JavaDoc
217     {
218         IClassMetaDataReader cmdr = createIClassMetaDataReader();
219         cmdr.close();
220         try
221         {
222             cmdr.close();
223             fail( "Did not throw IOException." );
224         }
225         catch (IOException JavaDoc ex)
226         {
227             assertNotNull( "Null exception message.", ex.getMessage() );
228         }
229     }
230     
231     
232     
233     //-------------------------------------------------------------------------
234
// Standard JUnit declarations
235

236     
237     public static InterfaceTestSuite suite()
238     {
239         InterfaceTestSuite suite = new InterfaceTestSuite( THIS_CLASS );
240         
241         return suite;
242     }
243     
244     public static void main( String JavaDoc[] args )
245     {
246         String JavaDoc[] name = { THIS_CLASS.getName() };
247         
248         // junit.textui.TestRunner.main( name );
249
// junit.swingui.TestRunner.main( name );
250

251         junit.textui.TestRunner.main( name );
252     }
253     
254     
255     /**
256      *
257      * @exception Exception thrown under any exceptional condition.
258      */

259     protected void setUp() throws Exception JavaDoc
260     {
261         super.setUp();
262         
263         // set ourself up
264
}
265     
266     
267     /**
268      *
269      * @exception Exception thrown under any exceptional condition.
270      */

271     protected void tearDown() throws Exception JavaDoc
272     {
273         // tear ourself down
274

275         
276         super.tearDown();
277     }
278 }
279
280
Popular Tags