KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)AnalysisMetaDataIOUTest.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 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.IAnalysisMetaData;
39
40
41 /**
42  * Tests the AnalysisMetaDataIO 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 December 28, 2002
47  */

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

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

65     public void testWriteAnalysisMetaData1() throws Exception JavaDoc
66     {
67         AnalysisMetaDataIO amdio = new AnalysisMetaDataIO();
68         StringWriter JavaDoc sw = new StringWriter JavaDoc();
69         IAnalysisMetaData amd = createIAnalysisMetaData(
70             "c", "n", (byte)-1 );
71         
72         amdio.writeAnalysisMetaData( amd, sw );
73         
74         String JavaDoc res = sw.toString();
75         DOC.getLog().info( "Wrote meta-data ["+res+"]" );
76         assertEquals(
77             "Incorrect result format.",
78             "1:c,1:n,-1,",
79             res );
80     }
81     
82     public void testWriteAnalysisMetaData2() throws Exception JavaDoc
83     {
84         AnalysisMetaDataIO amdio = new AnalysisMetaDataIO();
85         StringWriter JavaDoc sw = new StringWriter JavaDoc();
86         IAnalysisMetaData amd = createIAnalysisMetaData(
87             "123", "12345", (byte)100 );
88         
89         amdio.writeAnalysisMetaData( amd, sw );
90         
91         String JavaDoc res = sw.toString();
92         DOC.getLog().info( "Wrote meta-data ["+res+"]" );
93         assertEquals(
94             "Incorrect result format.",
95             "3:123,5:12345,100,",
96             res );
97     }
98     
99     
100     public void testReadAnalysisMetaData1() throws Exception JavaDoc
101     {
102         AnalysisMetaDataIO amdio = new AnalysisMetaDataIO();
103         StringReader JavaDoc sr = new StringReader JavaDoc( "1:c,1:n,-1," );
104         IAnalysisMetaData amd = amdio.readAnalysisMetaData( sr );
105         assertNotNull(
106             "Returned null data.",
107             amd );
108         assertEquals(
109             "Covered formatted text incorrect.",
110             "c",
111             amd.getCoveredFormattedText() );
112         assertEquals(
113             "Not covered formatted text incorrect.",
114             "n",
115             amd.getNotCoveredFormattedText() );
116         assertEquals(
117             "instruction weight incorrect.",
118             (byte)-1,
119             amd.getInstructionWeight() );
120     }
121     
122     
123     public void testReadAnalysisMetaData2() throws Exception JavaDoc
124     {
125         AnalysisMetaDataIO amdio = new AnalysisMetaDataIO();
126         StringReader JavaDoc sr = new StringReader JavaDoc( "3:123,5:12345,100," );
127         IAnalysisMetaData amd = amdio.readAnalysisMetaData( sr );
128         assertNotNull(
129             "Returned null data.",
130             amd );
131         assertEquals(
132             "Covered formatted text incorrect.",
133             "123",
134             amd.getCoveredFormattedText() );
135         assertEquals(
136             "Not covered formatted text incorrect.",
137             "12345",
138             amd.getNotCoveredFormattedText() );
139         assertEquals(
140             "instruction weight incorrect.",
141             (byte)100,
142             amd.getInstructionWeight() );
143     }
144     
145     
146     public void testReadAnalysisMetaData3() throws Exception JavaDoc
147     {
148         AnalysisMetaDataIO amdio = new AnalysisMetaDataIO();
149         StringReader JavaDoc sr = new StringReader JavaDoc( "" );
150         try
151         {
152             amdio.readAnalysisMetaData( sr );
153             fail( "Did not throw IOException." );
154         }
155         catch (IOException JavaDoc ioe)
156         {
157             // verify ioe
158
}
159     }
160     
161     
162     public void testReadAnalysisMetaData4() throws Exception JavaDoc
163     {
164         AnalysisMetaDataIO amdio = new AnalysisMetaDataIO();
165         StringReader JavaDoc sr = new StringReader JavaDoc( "1" );
166         try
167         {
168             amdio.readAnalysisMetaData( sr );
169             fail( "Did not throw IOException." );
170         }
171         catch (IOException JavaDoc ioe)
172         {
173             // verify ioe
174
}
175     }
176     
177     
178     public void testReadAnalysisMetaData5() throws Exception JavaDoc
179     {
180         AnalysisMetaDataIO amdio = new AnalysisMetaDataIO();
181         StringReader JavaDoc sr = new StringReader JavaDoc( "a:a" );
182         try
183         {
184             amdio.readAnalysisMetaData( sr );
185             fail( "Did not throw IOException." );
186         }
187         catch (IOException JavaDoc ioe)
188         {
189             // verify ioe
190
}
191     }
192     
193     
194     //-------------------------------------------------------------------------
195
// Helpers
196

197     protected IAnalysisMetaData createIAnalysisMetaData( String JavaDoc c, String JavaDoc nc,
198             byte w )
199     {
200         return CCCreatorUtil.createIAnalysisMetaData( c, nc, w );
201     }
202     
203     
204     //-------------------------------------------------------------------------
205
// Standard JUnit declarations
206

207     
208     public static Test suite()
209     {
210         TestSuite suite = new TestSuite( THIS_CLASS );
211         
212         return suite;
213     }
214     
215     public static void main( String JavaDoc[] args )
216     {
217         String JavaDoc[] name = { THIS_CLASS.getName() };
218         
219         // junit.textui.TestRunner.main( name );
220
// junit.swingui.TestRunner.main( name );
221

222         junit.textui.TestRunner.main( name );
223     }
224     
225     
226     /**
227      *
228      * @exception Exception thrown under any exceptional condition.
229      */

230     protected void setUp() throws Exception JavaDoc
231     {
232         super.setUp();
233         
234         // set ourself up
235
}
236     
237     
238     /**
239      *
240      * @exception Exception thrown under any exceptional condition.
241      */

242     protected void tearDown() throws Exception JavaDoc
243     {
244         // tear ourself down
245

246         
247         super.tearDown();
248     }
249 }
250
251
Popular Tags