KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)ReadUtilUTest.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.Reader JavaDoc;
31 import java.io.StringReader 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
38
39 /**
40  * Tests the ReadUtil class.
41  *
42  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
43  * @version $Date: 2004/04/15 05:48:28 $
44  * @since January 22, 2003
45  */

46 public class ReadUtilUTest extends TestCase
47 {
48     //-------------------------------------------------------------------------
49
// Standard JUnit Class-specific declarations
50

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

63     public void testReadTo1()
64     {
65         Reader JavaDoc r = new StringReader JavaDoc( "" );
66         try
67         {
68             ReadUtil.readTo( r, 'c' );
69         }
70         catch (IOException JavaDoc ex)
71         {
72             assertTrue(
73                 "Did not reference 'c'.",
74                 ex.getMessage().indexOf( "'c'" ) >= 0 );
75         }
76     }
77     
78     public void testReadTo2() throws Exception JavaDoc
79     {
80         Reader JavaDoc r = new StringReader JavaDoc( "c" );
81         String JavaDoc s = ReadUtil.readTo( r, 'c' );
82         assertEquals(
83             "Didn't read correct string.",
84             "",
85             s );
86     }
87     
88     public void testReadTo3() throws Exception JavaDoc
89     {
90         Reader JavaDoc r = new StringReader JavaDoc( "ccc" );
91         String JavaDoc s = ReadUtil.readTo( r, 'c' );
92         assertEquals(
93             "Didn't read correct string.",
94             "",
95             s );
96     }
97     
98     public void testReadTo4() throws Exception JavaDoc
99     {
100         Reader JavaDoc r = new StringReader JavaDoc( "abc" );
101         String JavaDoc s = ReadUtil.readTo( r, 'c' );
102         assertEquals(
103             "Didn't read correct string.",
104             "ab",
105             s );
106     }
107     
108     public void testReadCount1()
109     {
110         Reader JavaDoc r = new StringReader JavaDoc( "" );
111         try
112         {
113             ReadUtil.readCount( r, 1 );
114         }
115         catch (IOException JavaDoc ex)
116         {
117             assertTrue(
118                 "Didn't reference count.",
119                 ex.getMessage().indexOf( " 1 " ) >= 0 );
120         }
121     }
122     
123     public void testReadCount2() throws Exception JavaDoc
124     {
125         Reader JavaDoc r = new StringReader JavaDoc( "a" );
126         try
127         {
128             ReadUtil.readCount( r, 4 );
129         }
130         catch (IOException JavaDoc ex)
131         {
132             assertTrue(
133                 "Didn't reference count.",
134                 ex.getMessage().indexOf( " 3 " ) >= 0 );
135         }
136     }
137     
138     public void testReadCount3() throws Exception JavaDoc
139     {
140         Reader JavaDoc r = new StringReader JavaDoc( "" );
141         String JavaDoc s = ReadUtil.readCount( r, 0 );
142         assertEquals(
143             "Did not return expected string.",
144             "",
145             s );
146     }
147     
148     public void testReadCount4() throws Exception JavaDoc
149     {
150         Reader JavaDoc r = new StringReader JavaDoc( "a" );
151         String JavaDoc s = ReadUtil.readCount( r, 1 );
152         assertEquals(
153             "Did not return expected string.",
154             "a",
155             s );
156     }
157     
158     public void testReadCount5() throws Exception JavaDoc
159     {
160         Reader JavaDoc r = new StringReader JavaDoc( "abc" );
161         String JavaDoc s = ReadUtil.readCount( r, 1 );
162         assertEquals(
163             "Did not return expected string.",
164             "a",
165             s );
166     }
167     
168     public void testReadCount6() throws Exception JavaDoc
169     {
170         Reader JavaDoc r = new StringReader JavaDoc( "abc" );
171         String JavaDoc s = ReadUtil.readCount( r, 3 );
172         assertEquals(
173             "Did not return expected string.",
174             "abc",
175             s );
176     }
177
178     public void testToInt1() throws Exception JavaDoc
179     {
180         assertEquals(
181             "Didn't convert right.",
182             -1,
183             ReadUtil.toInt( "-1" ) );
184     }
185
186     public void testToInt2() throws Exception JavaDoc
187     {
188         assertEquals(
189             "Didn't convert right.",
190             0,
191             ReadUtil.toInt( "0" ) );
192     }
193     
194     public void testToInt3()
195     {
196         try
197         {
198             ReadUtil.toInt( "" );
199         }
200         catch (IOException JavaDoc ex)
201         {
202             // test exception
203
}
204     }
205     
206     public void testToInt4()
207     {
208         try
209         {
210             ReadUtil.toInt( null );
211         }
212         catch (IOException JavaDoc ex)
213         {
214             // test exception
215
}
216     }
217     
218     public void testToInt5()
219     {
220         try
221         {
222             ReadUtil.toInt( "ab" );
223         }
224         catch (IOException JavaDoc ex)
225         {
226             // test exception
227
}
228     }
229     
230     public void testToLong1() throws Exception JavaDoc
231     {
232         assertEquals(
233             "Didn't convert right.",
234             -1L,
235             ReadUtil.toLong( "-1" ) );
236     }
237
238     public void testToLong2() throws Exception JavaDoc
239     {
240         assertEquals(
241             "Didn't convert right.",
242             0L,
243             ReadUtil.toLong( "0" ) );
244     }
245     
246     public void testToLong3()
247     {
248         try
249         {
250             ReadUtil.toLong( "" );
251         }
252         catch (IOException JavaDoc ex)
253         {
254             // test exception
255
}
256     }
257     
258     public void testToLong4()
259     {
260         try
261         {
262             ReadUtil.toLong( null );
263         }
264         catch (IOException JavaDoc ex)
265         {
266             // test exception
267
}
268     }
269     
270     public void testToLong5()
271     {
272         try
273         {
274             ReadUtil.toLong( "ab" );
275         }
276         catch (IOException JavaDoc ex)
277         {
278             // test exception
279
}
280     }
281     
282     
283     
284     //-------------------------------------------------------------------------
285
// Helpers
286

287     
288     
289     //-------------------------------------------------------------------------
290
// Standard JUnit declarations
291

292     
293     public static Test suite()
294     {
295         TestSuite suite = new TestSuite( THIS_CLASS );
296         
297         return suite;
298     }
299     
300     public static void main( String JavaDoc[] args )
301     {
302         String JavaDoc[] name = { THIS_CLASS.getName() };
303         
304         // junit.textui.TestRunner.main( name );
305
// junit.swingui.TestRunner.main( name );
306

307         junit.textui.TestRunner.main( name );
308     }
309     
310     
311     /**
312      *
313      * @exception Exception thrown under any exceptional condition.
314      */

315     protected void setUp() throws Exception JavaDoc
316     {
317         super.setUp();
318
319        
320         // set ourself up
321
}
322     
323     
324     /**
325      *
326      * @exception Exception thrown under any exceptional condition.
327      */

328     protected void tearDown() throws Exception JavaDoc
329     {
330         // tear ourself down
331

332         
333         super.tearDown();
334     }
335 }
336
337
Popular Tags