@@ -356,12 +356,14 @@ public void assertError(Class<? extends Throwable> clazz) {
356356 throw new AssertionError ("No errors" );
357357 } else
358358 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 ;
361362 } else
362363 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 ;
365367 }
366368 }
367369
@@ -380,12 +382,14 @@ public void assertError(Throwable throwable) {
380382 throw new AssertionError ("No errors" );
381383 } else
382384 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 ;
385388 } else
386389 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 ;
389393 }
390394 }
391395
@@ -404,11 +408,13 @@ public void assertNoTerminalEvent() {
404408 throw new AssertionError ("Found " + err .size () + " errors and " + s + " completion events instead of none" );
405409 } else
406410 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 ;
409414 } 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 ;
412418 }
413419 }
414420 }
0 commit comments