KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)AnalysisModuleIOUTest.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 AnalysisModuleIO 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 AnalysisModuleIOUTest extends TestCase
49 {
50     //-------------------------------------------------------------------------
51
// Standard JUnit Class-specific declarations
52

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

65     public void testWriteAnalysisModule1() throws Exception JavaDoc
66     {
67         AnalysisModuleIO amio = new AnalysisModuleIO();
68         StringWriter JavaDoc sw = new StringWriter JavaDoc();
69         IAnalysisModule am = createIAnalysisModule(
70             "n", "u", "m" );
71         
72         amio.writeAnalysisModule( am, sw );
73         
74         String JavaDoc res = sw.toString();
75         DOC.getLog().info( "Wrote module ["+res+"]" );
76         assertEquals(
77             "Incorrect result format.",
78             "1:n,1:u,1:m",
79             res );
80     }
81     
82     public void testWriteAnalysisModule2() throws Exception JavaDoc
83     {
84         AnalysisModuleIO amio = new AnalysisModuleIO();
85         StringWriter JavaDoc sw = new StringWriter JavaDoc();
86         IAnalysisModule am = createIAnalysisModule(
87             "", "", "" );
88         
89         amio.writeAnalysisModule( am, sw );
90         
91         String JavaDoc res = sw.toString();
92         DOC.getLog().info( "Wrote module ["+res+"]" );
93         assertEquals(
94             "Incorrect result format.",
95             "0:,0:,0:",
96             res );
97     }
98     
99     public void testWriteAnalysisModule3() throws Exception JavaDoc
100     {
101         AnalysisModuleIO amio = new AnalysisModuleIO();
102         StringWriter JavaDoc sw = new StringWriter JavaDoc();
103         IAnalysisModule am = createIAnalysisModule(
104             "aaaa", "bbbb", "1234" );
105         
106         amio.writeAnalysisModule( am, sw );
107         
108         String JavaDoc res = sw.toString();
109         DOC.getLog().info( "Wrote module ["+res+"]" );
110         assertEquals(
111             "Incorrect result format.",
112             "4:aaaa,4:bbbb,4:1234",
113             res );
114     }
115     
116     
117     public void testReadAnalysisModule1() throws Exception JavaDoc
118     {
119         AnalysisModuleIO amio = new AnalysisModuleIO();
120         StringReader JavaDoc sr = new StringReader JavaDoc( "1:n,1:u,1:m" );
121         IAnalysisModule am = amio.readAnalysisModule( sr );
122         assertNotNull(
123             "Returned null data.",
124             am );
125         assertEquals(
126             "name incorrect.",
127             "n",
128             am.getMeasureName() );
129         assertEquals(
130             "unit incorrect.",
131             "u",
132             am.getMeasureUnit() );
133         assertEquals(
134             "instruction weight incorrect.",
135             "m",
136             am.getMimeEncoding() );
137     }
138     
139     
140     public void testReadAnalysisMetaData2() throws Exception JavaDoc
141     {
142         AnalysisModuleIO amio = new AnalysisModuleIO();
143         StringReader JavaDoc sr = new StringReader JavaDoc( "0: ,0:,0:asdf," );
144         IAnalysisModule am = amio.readAnalysisModule( sr );
145         assertNotNull(
146             "Returned null data.",
147             am );
148         assertEquals(
149             "name incorrect.",
150             "",
151             am.getMeasureName() );
152         assertEquals(
153             "unit incorrect.",
154             "",
155             am.getMeasureUnit() );
156         assertEquals(
157             "instruction weight incorrect.",
158             "",
159             am.getMimeEncoding() );
160     }
161     
162     
163     public void testReadAnalysisMetaData3() throws Exception JavaDoc
164     {
165         AnalysisModuleIO amio = new AnalysisModuleIO();
166         StringReader JavaDoc sr = new StringReader JavaDoc( "" );
167         try
168         {
169             amio.readAnalysisModule( sr );
170             fail( "Did not throw IOException." );
171         }
172         catch (IOException JavaDoc ioe)
173         {
174             // verify ioe
175
}
176     }
177     
178     
179     public void testReadAnalysisMetaData4() throws Exception JavaDoc
180     {
181         AnalysisModuleIO amio = new AnalysisModuleIO();
182         StringReader JavaDoc sr = new StringReader JavaDoc( "1" );
183         try
184         {
185             amio.readAnalysisModule( sr );
186             fail( "Did not throw IOException." );
187         }
188         catch (IOException JavaDoc ioe)
189         {
190             // verify ioe
191
}
192     }
193     
194     
195     public void testReadAnalysisMetaData5() throws Exception JavaDoc
196     {
197         AnalysisModuleIO amio = new AnalysisModuleIO();
198         StringReader JavaDoc sr = new StringReader JavaDoc( "a:a,1:1,1:1" );
199         try
200         {
201             amio.readAnalysisModule( sr );
202             fail( "Did not throw IOException." );
203         }
204         catch (IOException JavaDoc ioe)
205         {
206             // verify ioe
207
}
208     }
209     
210     
211     //-------------------------------------------------------------------------
212
// Helpers
213

214     protected IAnalysisModule createIAnalysisModule( String JavaDoc name, String JavaDoc unit,
215             String JavaDoc mime )
216     {
217         return CCCreatorUtil.createIAnalysisModule( name, unit, mime );
218     }
219     
220     
221     //-------------------------------------------------------------------------
222
// Standard JUnit declarations
223

224     
225     public static Test suite()
226     {
227         TestSuite suite = new TestSuite( THIS_CLASS );
228         
229         return suite;
230     }
231     
232     public static void main( String JavaDoc[] args )
233     {
234         String JavaDoc[] name = { THIS_CLASS.getName() };
235         
236         // junit.textui.TestRunner.main( name );
237
// junit.swingui.TestRunner.main( name );
238

239         junit.textui.TestRunner.main( name );
240     }
241     
242     
243     /**
244      *
245      * @exception Exception thrown under any exceptional condition.
246      */

247     protected void setUp() throws Exception JavaDoc
248     {
249         super.setUp();
250         
251         // set ourself up
252
}
253     
254     
255     /**
256      *
257      * @exception Exception thrown under any exceptional condition.
258      */

259     protected void tearDown() throws Exception JavaDoc
260     {
261         // tear ourself down
262

263         
264         super.tearDown();
265     }
266 }
267
268
Popular Tags