KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

65     public void testWriteAnalysisModuleSet1() throws Exception JavaDoc
66     {
67         AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
68         StringWriter JavaDoc sw = new StringWriter JavaDoc();
69         AnalysisModuleSet ams = new AnalysisModuleSet();
70         
71         amsio.writeAnalysisModuleSet( ams, sw );
72         
73         String JavaDoc res = sw.toString();
74         DOC.getLog().info( "Wrote module set ["+res+"]" );
75         assertEquals(
76             "Incorrect result format.",
77             "0{}",
78             res );
79     }
80     
81     public void testWriteAnalysisModuleSet2() throws Exception JavaDoc
82     {
83         AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
84         StringWriter JavaDoc sw = new StringWriter JavaDoc();
85         AnalysisModuleSet ams = createAnalysisModuleSet(
86             new IAnalysisModule[] {
87                 createIAnalysisModule( "n", "u", "m" ),
88             } );
89         
90         amsio.writeAnalysisModuleSet( ams, sw );
91         
92         String JavaDoc res = sw.toString();
93         DOC.getLog().info( "Wrote module set ["+res+"]" );
94         assertEquals(
95             "Incorrect result format.",
96             "1{[0;11;1:n,1:u,1:m]}",
97             res );
98     }
99     
100     public void testWriteAnalysisModuleSet3() throws Exception JavaDoc
101     {
102         AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
103         StringWriter JavaDoc sw = new StringWriter JavaDoc();
104         AnalysisModuleSet ams = createAnalysisModuleSet(
105             new IAnalysisModule[] {
106                 createIAnalysisModule( "n", "u", "m" ),
107                 createIAnalysisModule( "", "", "" ),
108                 createIAnalysisModule( "aaaa", "bbbb", "1234" ),
109             } );
110         
111         amsio.writeAnalysisModuleSet( ams, sw );
112         
113         String JavaDoc res = sw.toString();
114         DOC.getLog().info( "Wrote module set ["+res+"]" );
115         assertEquals(
116             "Incorrect result format.",
117             "3{[0;11;1:n,1:u,1:m][1;8;0:,0:,0:][2;20;4:aaaa,4:bbbb,4:1234]}",
118             res );
119     }
120     
121     
122     public void testReadAnalysisModuleSet1() throws Exception JavaDoc
123     {
124         AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
125         StringReader JavaDoc sr = new StringReader JavaDoc( "0{}" );
126         AnalysisModuleSet ams = amsio.readAnalysisModuleSet( sr );
127         IAnalysisModule[] amL = ams.getAnalysisModules();
128         assertNotNull(
129             "Returned null data list.",
130             amL );
131         assertEquals(
132             "Did not return an empty data set.",
133             0,
134             amL.length );
135     }
136     
137     
138     public void testReadAnalysisModuleSet2() throws Exception JavaDoc
139     {
140         AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
141         StringReader JavaDoc sr = new StringReader JavaDoc( "1{[0;11;1:n,1:u,1:m]}" );
142         AnalysisModuleSet ams = amsio.readAnalysisModuleSet( sr );
143         IAnalysisModule[] amL = ams.getAnalysisModules();
144         assertNotNull(
145             "Returned null data list.",
146             amL );
147         assertEquals(
148             "Did not return an empty data set.",
149             1,
150             amL.length );
151         IAnalysisModule am = amL[0];
152         assertNotNull(
153             "Returned null module 0.",
154             am );
155         assertEquals(
156             "name incorrect.",
157             "n",
158             am.getMeasureName() );
159         assertEquals(
160             "unit incorrect.",
161             "u",
162             am.getMeasureUnit() );
163         assertEquals(
164             "encoding incorrect.",
165             "m",
166             am.getMimeEncoding() );
167     }
168     
169     
170     public void testReadAnalysisModuleSet3() throws Exception JavaDoc
171     {
172         AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
173         StringReader JavaDoc sr = new StringReader JavaDoc(
174             "2{[0;11;1:n,1:u,1:m][1;8;0:,0:,0:]}" );
175         AnalysisModuleSet ams = amsio.readAnalysisModuleSet( sr );
176         IAnalysisModule[] amL = ams.getAnalysisModules();
177         assertNotNull(
178             "Returned null data list.",
179             amL );
180         assertEquals(
181             "Did not return an empty data set.",
182             2,
183             amL.length );
184         
185         IAnalysisModule am = amL[0];
186         assertNotNull(
187             "Returned null module 0.",
188             am );
189         assertEquals(
190             "0: name incorrect.",
191             "n",
192             am.getMeasureName() );
193         assertEquals(
194             "0: unit incorrect.",
195             "u",
196             am.getMeasureUnit() );
197         assertEquals(
198             "0: encoding incorrect.",
199             "m",
200             am.getMimeEncoding() );
201         
202         am = amL[1];
203         assertNotNull(
204             "Returned null module 1.",
205             am );
206         assertEquals(
207             "1: name incorrect.",
208             "",
209             am.getMeasureName() );
210         assertEquals(
211             "1: unit incorrect.",
212             "",
213             am.getMeasureUnit() );
214         assertEquals(
215             "1: encoding incorrect.",
216             "",
217             am.getMimeEncoding() );
218     }
219     
220     
221     public void testReadAnalysisModuleSet4() throws Exception JavaDoc
222     {
223         AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
224         StringReader JavaDoc sr = new StringReader JavaDoc(
225             "{}" );
226         try
227         {
228             amsio.readAnalysisModuleSet( sr );
229             fail( "Did not throw IOException." );
230         }
231         catch (IOException JavaDoc ioe)
232         {
233             // test exception
234
}
235     }
236     
237     
238     //-------------------------------------------------------------------------
239
// Helpers
240

241     protected AnalysisModuleSet createAnalysisModuleSet( IAnalysisModule amL[] )
242     {
243         return CCCreatorUtil.createAnalysisModuleSet( amL );
244     }
245     
246     protected IAnalysisModule createIAnalysisModule( String JavaDoc name, String JavaDoc unit,
247             String JavaDoc mime )
248     {
249         return CCCreatorUtil.createIAnalysisModule( name, unit, mime );
250     }
251     
252     
253     //-------------------------------------------------------------------------
254
// Standard JUnit declarations
255

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

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

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

292     protected void tearDown() throws Exception JavaDoc
293     {
294         // tear ourself down
295

296         
297         super.tearDown();
298     }
299 }
300
301
Popular Tags