1 26 27 package net.sourceforge.groboutils.codecoverage.v2.datastore; 28 29 import java.io.IOException ; 30 import java.io.Reader ; 31 import java.io.StringReader ; 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 46 public class ReadUtilUTest extends TestCase 47 { 48 51 private static final Class THIS_CLASS = ReadUtilUTest.class; 52 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 53 54 public ReadUtilUTest( String name ) 55 { 56 super( name ); 57 } 58 59 60 63 public void testReadTo1() 64 { 65 Reader r = new StringReader ( "" ); 66 try 67 { 68 ReadUtil.readTo( r, 'c' ); 69 } 70 catch (IOException ex) 71 { 72 assertTrue( 73 "Did not reference 'c'.", 74 ex.getMessage().indexOf( "'c'" ) >= 0 ); 75 } 76 } 77 78 public void testReadTo2() throws Exception 79 { 80 Reader r = new StringReader ( "c" ); 81 String s = ReadUtil.readTo( r, 'c' ); 82 assertEquals( 83 "Didn't read correct string.", 84 "", 85 s ); 86 } 87 88 public void testReadTo3() throws Exception 89 { 90 Reader r = new StringReader ( "ccc" ); 91 String s = ReadUtil.readTo( r, 'c' ); 92 assertEquals( 93 "Didn't read correct string.", 94 "", 95 s ); 96 } 97 98 public void testReadTo4() throws Exception 99 { 100 Reader r = new StringReader ( "abc" ); 101 String 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 r = new StringReader ( "" ); 111 try 112 { 113 ReadUtil.readCount( r, 1 ); 114 } 115 catch (IOException ex) 116 { 117 assertTrue( 118 "Didn't reference count.", 119 ex.getMessage().indexOf( " 1 " ) >= 0 ); 120 } 121 } 122 123 public void testReadCount2() throws Exception 124 { 125 Reader r = new StringReader ( "a" ); 126 try 127 { 128 ReadUtil.readCount( r, 4 ); 129 } 130 catch (IOException ex) 131 { 132 assertTrue( 133 "Didn't reference count.", 134 ex.getMessage().indexOf( " 3 " ) >= 0 ); 135 } 136 } 137 138 public void testReadCount3() throws Exception 139 { 140 Reader r = new StringReader ( "" ); 141 String s = ReadUtil.readCount( r, 0 ); 142 assertEquals( 143 "Did not return expected string.", 144 "", 145 s ); 146 } 147 148 public void testReadCount4() throws Exception 149 { 150 Reader r = new StringReader ( "a" ); 151 String 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 159 { 160 Reader r = new StringReader ( "abc" ); 161 String 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 169 { 170 Reader r = new StringReader ( "abc" ); 171 String 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 179 { 180 assertEquals( 181 "Didn't convert right.", 182 -1, 183 ReadUtil.toInt( "-1" ) ); 184 } 185 186 public void testToInt2() throws Exception 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 ex) 201 { 202 } 204 } 205 206 public void testToInt4() 207 { 208 try 209 { 210 ReadUtil.toInt( null ); 211 } 212 catch (IOException ex) 213 { 214 } 216 } 217 218 public void testToInt5() 219 { 220 try 221 { 222 ReadUtil.toInt( "ab" ); 223 } 224 catch (IOException ex) 225 { 226 } 228 } 229 230 public void testToLong1() throws Exception 231 { 232 assertEquals( 233 "Didn't convert right.", 234 -1L, 235 ReadUtil.toLong( "-1" ) ); 236 } 237 238 public void testToLong2() throws Exception 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 ex) 253 { 254 } 256 } 257 258 public void testToLong4() 259 { 260 try 261 { 262 ReadUtil.toLong( null ); 263 } 264 catch (IOException ex) 265 { 266 } 268 } 269 270 public void testToLong5() 271 { 272 try 273 { 274 ReadUtil.toLong( "ab" ); 275 } 276 catch (IOException ex) 277 { 278 } 280 } 281 282 283 284 287 288 289 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 [] args ) 301 { 302 String [] name = { THIS_CLASS.getName() }; 303 304 307 junit.textui.TestRunner.main( name ); 308 } 309 310 311 315 protected void setUp() throws Exception 316 { 317 super.setUp(); 318 319 320 } 322 323 324 328 protected void tearDown() throws Exception 329 { 330 332 333 super.tearDown(); 334 } 335 } 336 337 | Popular Tags |