1 26 27 package net.sourceforge.groboutils.util.throwable.v1; 28 29 import java.io.PrintStream ; 30 import java.io.PrintWriter ; 31 import java.io.StringWriter ; 32 import java.io.ByteArrayOutputStream ; 33 import org.easymock.EasyMock; 34 import org.easymock.MockControl; 35 import junit.framework.Test; 36 import junit.framework.TestCase; 37 import junit.framework.TestSuite; 38 39 40 47 public class ChainableExceptionHelperUTest extends TestCase 48 { 49 52 private static final Class THIS_CLASS = 53 ChainableExceptionHelperUTest.class; 54 55 public ChainableExceptionHelperUTest( String name ) 56 { 57 super( name ); 58 } 59 60 61 64 68 protected void setUp() throws Exception 69 { 70 super.setUp(); 71 72 } 74 75 76 79 80 public void testConstructor1a() 81 { 82 Throwable source = new Throwable (); 83 new ChainableExceptionHelper( source ); 84 } 85 86 87 public void testConstructor1b() 88 { 89 try 90 { 91 new ChainableExceptionHelper( null ); 92 fail("Did not throw IllegalArgumentException"); 93 } 94 catch (IllegalArgumentException iae) 95 { 96 } 98 } 99 100 101 public void testConstructor2a() 102 { 103 Throwable source = new Throwable (); 104 Throwable cause = new Throwable (); 105 new ChainableExceptionHelper( source, null ); 106 } 107 108 109 public void testConstructor2b() 110 { 111 Throwable source = new Throwable (); 112 Throwable cause = new Throwable (); 113 new ChainableExceptionHelper( source, cause ); 114 } 115 116 117 public void testConstructor2c() 118 { 119 Throwable source = new Throwable (); 120 Throwable cause = new Throwable (); 121 try 122 { 123 new ChainableExceptionHelper( null, null ); 124 fail("Did not throw IllegalArgumentException"); 125 } 126 catch (IllegalArgumentException iae) 127 { 128 } 130 } 131 132 133 public void testConstructor2d() 134 { 135 Throwable source = new Throwable (); 136 Throwable cause = new Throwable (); 137 try 138 { 139 new ChainableExceptionHelper( null, cause ); 140 fail("Did not throw IllegalArgumentException"); 141 } 142 catch (IllegalArgumentException iae) 143 { 144 } 146 } 147 148 149 public void testConstructor2e() 150 { 151 Throwable source = new Throwable (); 152 Throwable cause = new Throwable (); 153 try 154 { 155 new ChainableExceptionHelper( source, source ); 156 fail("Did not throw IllegalArgumentException"); 157 } 158 catch (IllegalArgumentException iae) 159 { 160 } 162 } 163 164 165 public void testGetCause1() 166 { 167 Throwable source = new Throwable (); 168 Throwable cause = new Throwable (); 169 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 170 source ); 171 172 assertNull( 173 "Does not have a null cause.", 174 ceh.getCause() ); 175 } 176 177 178 public void testGetCause2() 179 { 180 Throwable source = new Throwable (); 181 Throwable cause = new Throwable (); 182 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 183 source, null ); 184 185 assertNull( 186 "Does not have a null cause.", 187 ceh.getCause() ); 188 } 189 190 191 public void testGetCause3() 192 { 193 Throwable source = new Throwable (); 194 Throwable cause = new Throwable (); 195 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 196 source, cause ); 197 198 assertEquals( 199 "Does not have right cause.", 200 ceh.getCause(), 201 cause ); 202 } 203 204 205 public void testInitCause1() 206 { 207 Throwable source = new Throwable (); 208 Throwable cause = new Throwable (); 209 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 210 source ); 211 212 assertEquals( 213 "Did not return right exception.", 214 ceh.initCause( cause ), 215 source ); 216 } 217 218 219 public void testInitCause2() 220 { 221 Throwable source = new Throwable (); 222 Throwable cause = new Throwable (); 223 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 224 source ); 225 226 assertEquals( 227 "Did not return right exception.", 228 ceh.initCause( null ), 229 source ); 230 } 231 232 233 public void testInitCause3() 234 { 235 Throwable source = new Throwable (); 236 Throwable cause = new Throwable (); 237 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 238 source, cause ); 239 240 try 241 { 242 ceh.initCause( cause ); 243 fail("Did not throw IllegalStateException"); 244 } 245 catch (IllegalStateException ise) 246 { 247 } 249 } 250 251 252 public void testInitGetCause1() 253 { 254 Throwable source = new Throwable (); 255 Throwable cause = new Throwable (); 256 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 257 source ); 258 259 ceh.initCause( cause ); 260 assertEquals( 261 "Did not return right cause.", 262 ceh.getCause(), 263 cause ); 264 } 265 266 267 public void testInitGetCause2() 268 { 269 Throwable source = new Throwable (); 270 Throwable cause = new Throwable (); 271 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 272 source ); 273 274 ceh.initCause( null ); 275 assertNull( 276 "Did not return right cause.", 277 ceh.getCause() ); 278 } 279 280 281 public void testInitGetCause3() 282 { 283 Throwable source = new Throwable (); 284 Throwable cause = new Throwable (); 285 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 286 source, cause ); 287 288 assertEquals( 289 "Did not return right cause.", 290 ceh.getCause(), 291 cause ); 292 } 293 294 295 public void testInitGetCause4() 296 { 297 Throwable source = new Throwable (); 298 Throwable cause = new Throwable (); 299 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 300 source, null ); 301 302 assertNull( 303 "Did not return right cause.", 304 ceh.getCause() ); 305 } 306 307 308 public void testPrintStackTrace1() 309 { 310 Throwable source = new Throwable (); 311 Throwable cause = new Throwable (); 312 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 313 source ); 314 315 StringWriter sw = new StringWriter (); 316 ceh.printStackTrace( new PrintWriter ( sw, true ) ); 317 318 assertTrue( 320 "Not a valid length", 321 sw.toString().length() > 0 ); 322 } 323 324 325 public void testPrintStackTrace2() 326 { 327 Throwable source = new Throwable (); 328 Throwable cause = new Throwable (); 329 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 330 source ); 331 332 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 333 ceh.printStackTrace( new PrintStream ( baos, true ) ); 334 335 assertTrue( 337 "Not a valid length", 338 baos.toString().length() > 0 ); 339 } 340 341 342 public void testPrintStackTrace3() 343 { 344 Throwable source = new Throwable (); 345 Throwable cause = new Throwable (); 346 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 347 source ); 348 349 ceh.initCause( cause ); 350 StringWriter sw = new StringWriter (); 351 ceh.printStackTrace( new PrintWriter ( sw, true ) ); 352 353 assertTrue( 355 "Not a valid length", 356 sw.toString().length() > 0 ); 357 } 358 359 360 public void testPrintStackTrace4() 361 { 362 Throwable source = new Throwable (); 363 Throwable cause = new Throwable (); 364 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 365 source ); 366 367 ceh.initCause( cause ); 368 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 369 ceh.printStackTrace( new PrintStream ( baos, true ) ); 370 371 assertTrue( 373 "Not a valid length", 374 baos.toString().length() > 0 ); 375 } 376 377 378 public void testInitGetCause5() 379 { 380 Throwable source = new Throwable (); 381 Throwable cause = new Throwable (); 382 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 383 source ); 384 385 ceh.initCause( null ); 386 StringWriter sw = new StringWriter (); 387 ceh.printStackTrace( new PrintWriter ( sw, true ) ); 388 389 assertTrue( 391 "Not a valid length", 392 sw.toString().length() > 0 ); 393 } 394 395 396 public void testInitGetCause6() 397 { 398 Throwable source = new Throwable (); 399 Throwable cause = new Throwable (); 400 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 401 source ); 402 403 ceh.initCause( null ); 404 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 405 ceh.printStackTrace( new PrintStream ( baos, true ) ); 406 407 assertTrue( 409 "Not a valid length", 410 baos.toString().length() > 0 ); 411 } 412 413 414 public void testInitGetCause7() 415 { 416 Throwable source = new Throwable (); 417 Throwable cause = new Throwable (); 418 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 419 source, cause ); 420 421 StringWriter sw = new StringWriter (); 422 ceh.printStackTrace( new PrintWriter ( sw, true ) ); 423 424 assertTrue( 426 "Not a valid length", 427 sw.toString().length() > 0 ); 428 } 429 430 431 public void testInitGetCause8() 432 { 433 Throwable source = new Throwable (); 434 Throwable cause = new Throwable (); 435 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 436 source, cause ); 437 438 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 439 ceh.printStackTrace( new PrintStream ( baos, true ) ); 440 441 assertTrue( 443 "Not a valid length", 444 baos.toString().length() > 0 ); 445 } 446 447 448 public void testInitGetCause9() 449 { 450 Throwable source = new Throwable (); 451 Throwable cause = new Throwable (); 452 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 453 source, null ); 454 455 StringWriter sw = new StringWriter (); 456 ceh.printStackTrace( new PrintWriter ( sw, true ) ); 457 458 assertTrue( 460 "Not a valid length", 461 sw.toString().length() > 0 ); 462 } 463 464 465 public void testInitGetCause10() 466 { 467 Throwable source = new Throwable (); 468 Throwable cause = new Throwable (); 469 ChainableExceptionHelper ceh = new ChainableExceptionHelper( 470 source, null ); 471 472 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 473 ceh.printStackTrace( new PrintStream ( baos, true ) ); 474 475 assertTrue( 477 "Not a valid length", 478 baos.toString().length() > 0 ); 479 } 480 481 482 485 486 489 490 public static Test suite() 491 { 492 TestSuite suite = new TestSuite( THIS_CLASS ); 493 494 505 506 return suite; 507 } 508 509 public static void main( String [] args ) 510 { 511 String [] name = { THIS_CLASS.getName() }; 512 513 516 junit.textui.TestRunner.main( name ); 517 } 518 519 520 524 protected void tearDown() throws Exception 525 { 526 528 529 super.tearDown(); 530 } 531 } 532 533 | Popular Tags |