diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatform4TestCase.kt b/platform/testFramework/src/com/intellij/testFramework/LightPlatform4TestCase.kt index e7956b9fc42e..fe486c6760fe 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatform4TestCase.kt +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatform4TestCase.kt @@ -3,13 +3,13 @@ package com.intellij.testFramework import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.util.text.StringUtil +import com.intellij.util.ExceptionUtil import org.junit.Rule import org.junit.internal.AssumptionViolatedException import org.junit.rules.TestRule import org.junit.runner.RunWith import org.junit.runners.JUnit4 import org.junit.runners.model.Statement -import java.util.concurrent.atomic.AtomicReference @RunWith(JUnit4::class) abstract class LightPlatform4TestCase : LightPlatformTestCase() { @@ -23,47 +23,23 @@ abstract class LightPlatform4TestCase : LightPlatformTestCase() { setName(if (name.startsWith("test")) name else "test" + StringUtil.capitalize(name)) setUp() - - /* - * Allows to throw the original exceptions rather than them being wrapped into a RuntimeException. - */ - val failedAssumption: AtomicReference = AtomicReference() - val failure: AtomicReference = AtomicReference() - - ApplicationManager.getApplication().invokeAndWait { - try { - base.evaluate() - } - catch (ave: AssumptionViolatedException) { - failedAssumption.set(ave) - } - catch (t: Throwable) { - /* - * This is either a failed assertion (AssertionError) or an unexpected failure. - */ - failure.set(t) - } - finally { + try { + ApplicationManager.getApplication().invokeAndWait { try { + base.evaluate() + } + finally { tearDown() - } catch (tearDownFailure: Throwable) { - when (val firstFailure = failure.get()) { - null -> failure.set(tearDownFailure) - else -> firstFailure.addSuppressed(tearDownFailure) - } } } } - - /* - * 1. Throw a failure, if any. - */ - failure.get()?.let { throw it } - - /* - * 2. Throw a failed assumption, if any. - */ - failedAssumption.get()?.let { throw it } + catch (e: Throwable) { + // invokeAndWait() can wrap the real exception into RuntimeException. + ExceptionUtil.findCause(e, AssumptionViolatedException::class.java)?.let { ave -> + throw ave + } + throw e + } } } }