@@ -356,12 +356,14 @@ public void assertError(Class<? extends Throwable> clazz) {
356
356
throw new AssertionError ("No errors" );
357
357
} else
358
358
if (err .size () > 1 ) {
359
- // can't use AssertionError because (message, cause) doesn't exist until Java 7
360
- throw new RuntimeException ("Multiple errors: " + err .size (), new CompositeException (err ));
359
+ AssertionError ae = new AssertionError ("Multiple errors: " + err .size ());
360
+ ae .initCause (new CompositeException (err ));
361
+ throw ae ;
361
362
} else
362
363
if (!clazz .isInstance (err .get (0 ))) {
363
- // can't use AssertionError because (message, cause) doesn't exist until Java 7
364
- throw new RuntimeException ("Exceptions differ; expected: " + clazz + ", actual: " + err .get (0 ), err .get (0 ));
364
+ AssertionError ae = new AssertionError ("Exceptions differ; expected: " + clazz + ", actual: " + err .get (0 ));
365
+ ae .initCause (err .get (0 ));
366
+ throw ae ;
365
367
}
366
368
}
367
369
@@ -380,12 +382,14 @@ public void assertError(Throwable throwable) {
380
382
throw new AssertionError ("No errors" );
381
383
} else
382
384
if (err .size () > 1 ) {
383
- // can't use AssertionError because (message, cause) doesn't exist until Java 7
384
- throw new RuntimeException ("Multiple errors: " + err .size (), new CompositeException (err ));
385
+ AssertionError ae = new AssertionError ("Multiple errors: " + err .size ());
386
+ ae .initCause (new CompositeException (err ));
387
+ throw ae ;
385
388
} else
386
389
if (!throwable .equals (err .get (0 ))) {
387
- // can't use AssertionError because (message, cause) doesn't exist until Java 7
388
- throw new RuntimeException ("Exceptions differ; expected: " + throwable + ", actual: " + err .get (0 ), err .get (0 ));
390
+ AssertionError ae = new AssertionError ("Exceptions differ; expected: " + throwable + ", actual: " + err .get (0 ));
391
+ ae .initCause (err .get (0 ));
392
+ throw ae ;
389
393
}
390
394
}
391
395
@@ -404,11 +408,13 @@ public void assertNoTerminalEvent() {
404
408
throw new AssertionError ("Found " + err .size () + " errors and " + s + " completion events instead of none" );
405
409
} else
406
410
if (err .size () == 1 ) {
407
- // can't use AssertionError because (message, cause) doesn't exist until Java 7
408
- throw new RuntimeException ("Found " + err .size () + " errors and " + s + " completion events instead of none" , err .get (0 ));
411
+ AssertionError ae = new AssertionError ("Found " + err .size () + " errors and " + s + " completion events instead of none" );
412
+ ae .initCause (err .get (0 ));
413
+ throw ae ;
409
414
} else {
410
- // can't use AssertionError because (message, cause) doesn't exist until Java 7
411
- throw new RuntimeException ("Found " + err .size () + " errors and " + s + " completion events instead of none" , new CompositeException (err ));
415
+ AssertionError ae = new AssertionError ("Found " + err .size () + " errors and " + s + " completion events instead of none" );
416
+ ae .initCause (new CompositeException (err ));
417
+ throw ae ;
412
418
}
413
419
}
414
420
}
0 commit comments