private static void throwing() { assertThrows(RuntimeException.class, () -> immediateFuture(null)); assertThrows( RuntimeException.class, () -> { immediateFuture(null); }); assertThrows( RuntimeException.class, new ThrowingRunnable() { @Override public void run() throws Throwable { immediateFuture(null); } }); }
/** * Wraps the given {@link ThrowingRunnable} in a {@link Runnable} that transforms all {@link * Throwable throwables} to a {@link RuntimeException}. */ private static Runnable wrap(ThrowingRunnable runnable) { return () -> { try { runnable.run(); } catch (Throwable throwable) { throw new RuntimeException(throwable); } }; }
/** Runs the given {@link ThrowingRunnable} as a write action on the main thread. */ private static void writeOnMainThread(ThrowingRunnable runnable) { ApplicationManager.getApplication() .invokeAndWait(() -> ApplicationManager.getApplication().runWriteAction(wrap(runnable))); }