public static void assertDoesNotThrow(Action runnable) { try { runnable.run(); } catch (Exception instigatingException) { throw new AssertionError("expected clause not to throw, but it did.", instigatingException); } }
@Nonnull public static <TException extends Throwable> TException assertThrows( Class<TException> expectedException, Action runnable) { assert !expectedException.equals(AssertionError.class) : "cant assert on assertion errors since thats how we fail a test!"; try { runnable.run(); fail("expected action to throw " + expectedException.getSimpleName() + " but it did not."); return null; } catch (Throwable exception) { if (!expectedException.isInstance(exception)) { throw exception; } return expectedException.cast(exception); } }