Skip to content

Commit

Permalink
Unwrap InvocationTargetException thrown by QuarkusTest*Callback
Browse files Browse the repository at this point in the history
  • Loading branch information
famod committed Feb 25, 2022
1 parent d14c12e commit 83c3b4b
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ public void beforeEach(ExtensionContext context) throws Exception {
runningQuarkusApplication.getClassLoader().loadClass(TestScopeManager.class.getName())
.getDeclaredMethod("setup", boolean.class).invoke(null, false);
}
} catch (InvocationTargetException e) {
throw e.getCause() instanceof Exception ? (Exception) e.getCause() : e;
} finally {
setCCL(original);
}
Expand Down Expand Up @@ -504,16 +506,18 @@ public void afterEach(ExtensionContext context) throws Exception {
if (!failedBoot) {
popMockContext();
ClassLoader original = setCCL(runningQuarkusApplication.getClassLoader());
for (Object afterEachCallback : afterEachCallbacks) {
Map.Entry<Class<?>, ?> tuple = createQuarkusTestMethodContextTuple(context);
afterEachCallback.getClass().getMethod("afterEach", tuple.getKey())
.invoke(afterEachCallback, tuple.getValue());
}
try {
for (Object afterEachCallback : afterEachCallbacks) {
Map.Entry<Class<?>, ?> tuple = createQuarkusTestMethodContextTuple(context);
afterEachCallback.getClass().getMethod("afterEach", tuple.getKey())
.invoke(afterEachCallback, tuple.getValue());
}
runningQuarkusApplication.getClassLoader().loadClass(RestAssuredURLManager.class.getName())
.getDeclaredMethod("clearURL").invoke(null);
runningQuarkusApplication.getClassLoader().loadClass(TestScopeManager.class.getName())
.getDeclaredMethod("tearDown", boolean.class).invoke(null, false);
} catch (InvocationTargetException e) {
throw e.getCause() instanceof Exception ? (Exception) e.getCause() : e;
} finally {
setCCL(original);
}
Expand Down Expand Up @@ -711,6 +715,8 @@ public <T> T interceptTestClassConstructor(Invocation<T> invocation,
beforeClassCallback.getClass().getMethod("beforeClass", Class.class).invoke(beforeClassCallback,
runningQuarkusApplication.getClassLoader().loadClass(requiredTestClass.getName()));
}
} catch (InvocationTargetException e) {
throw e.getCause();
} finally {
Thread.currentThread().setContextClassLoader(old);
}
Expand Down Expand Up @@ -783,7 +789,8 @@ private void initTestState(ExtensionContext extensionContext, ExtensionState sta
}
}
} catch (Exception e) {
throw new TestInstantiationException("Failed to create test instance", e);
throw new TestInstantiationException("Failed to create test instance",
e instanceof InvocationTargetException ? e.getCause() : e);
}
}

Expand Down Expand Up @@ -1089,6 +1096,8 @@ private void runAfterAllCallbacks(ExtensionContext context) throws Exception {
afterAllCallback.getClass().getMethod("afterAll", quarkusTestContextClass)
.invoke(afterAllCallback, quarkusTestContextInstance);
}
} catch (InvocationTargetException e) {
throw e.getCause() instanceof Exception ? (Exception) e.getCause() : e;
} finally {
setCCL(original);
}
Expand Down

0 comments on commit 83c3b4b

Please sign in to comment.