tests: decrease "Caused by" chain by using runInEdtAndWaitRethrowing

This commit is contained in:
peter
2016-12-09 08:24:51 +01:00
parent ac73093cbd
commit 0ef6e4e8b3
3 changed files with 20 additions and 3 deletions
@@ -17,6 +17,7 @@ package com.intellij.testFramework
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.impl.ApplicationImpl
import com.intellij.util.ExceptionUtil
import com.intellij.util.ThrowableRunnable
import org.jetbrains.annotations.TestOnly
import java.lang.reflect.InvocationTargetException
@@ -24,9 +25,25 @@ import javax.swing.SwingUtilities
class EdtTestUtil {
companion object {
@JvmStatic fun runInEdtAndWait(runnable: ThrowableRunnable<Throwable>) {
@TestOnly @JvmStatic fun runInEdtAndWait(runnable: ThrowableRunnable<Throwable>) {
runInEdtAndWait { runnable.run() }
}
/**
* Same as {@link #runInEdtAndWait}, but when an unchecked exception happens inside runnable, its just rethrown without being wrapped.
* Can be useful to decrease "Caused by" chain for cases when the stack trace of the calling thread is not important or obvious.
*/
@TestOnly @JvmStatic fun runInEdtAndWaitRethrowing(runnable: ThrowableRunnable<Throwable>) {
var exception: Throwable? = null
runInEdtAndWait {
try {
runnable.run()
} catch (e: Throwable) {
exception = e
}
}
ExceptionUtil.rethrowAllAsUnchecked(exception)
}
}
}
@@ -496,7 +496,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
}
TestRunnerUtil.replaceIdeEventQueueSafely();
EdtTestUtil.runInEdtAndWait(() -> {
EdtTestUtil.runInEdtAndWaitRethrowing(() -> {
try {
ourTestThread = Thread.currentThread();
startRunAndTear();
@@ -414,7 +414,7 @@ public abstract class UsefulTestCase extends TestCase {
if (runInDispatchThread()) {
TestRunnerUtil.replaceIdeEventQueueSafely();
EdtTestUtil.runInEdtAndWait(this::defaultRunBare);
EdtTestUtil.runInEdtAndWaitRethrowing(this::defaultRunBare);
}
else {
defaultRunBare();