Skip to content

Commit 14e8bf8

Browse files
authored
Merge pull request #15 from Nordstrom/pr/unwrap-invocation-target-exception
Unwrap InvocationTargetException failures to propagate original cause
2 parents 81926e6 + 38b814d commit 14e8bf8

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

src/main/java/com/nordstrom/automation/junit/CreateTestClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class CreateTestClass {
4343
public static TestClass intercept(@This final Object runner, @SuperCall final Callable<?> proxy)
4444
throws Exception {
4545

46-
TestClass testClass = (TestClass) proxy.call();
46+
TestClass testClass = (TestClass) LifecycleHooks.callProxy(proxy);
4747
TESTCLASS_TO_RUNNER.put(testClass, runner);
4848

4949
for (Object method : testClass.getAnnotatedMethods()) {

src/main/java/com/nordstrom/automation/junit/LifecycleHooks.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static void intercept(@This final Object runner, @SuperCall final Callabl
163163
watcher.runStarted(runner);
164164
}
165165

166-
proxy.call();
166+
callProxy(proxy);
167167

168168
for (RunnerWatcher watcher : runnerWatcherLoader) {
169169
watcher.runFinished(runner);
@@ -206,7 +206,7 @@ public static class CreateTest {
206206
@RuntimeType
207207
public static Object intercept(@This final Object runner,
208208
@SuperCall final Callable<?> proxy) throws Exception {
209-
Object testObj = proxy.call();
209+
Object testObj = callProxy(proxy);
210210
TARGET_TO_TESTCLASS.put(testObj, getTestClassOf(runner));
211211
applyTimeout(testObj);
212212

@@ -459,4 +459,21 @@ static void setFieldValue(Object target, String name, Object value) throws Illeg
459459
field.setAccessible(true);
460460
field.set(target, value);
461461
}
462+
463+
/**
464+
* Invoke an intercepted method through its callable proxy.
465+
* <p>
466+
* <b>NOTE</b>: If the invoked method throws an exception, this method re-throws the original exception.
467+
*
468+
* @param proxy callable proxy for the intercepted method
469+
* @return {@code anything} - value returned by the intercepted method
470+
* @throws Exception {@code anything} (exception thrown by the intercepted method)
471+
*/
472+
static Object callProxy(final Callable<?> proxy) throws Exception {
473+
try {
474+
return proxy.call();
475+
} catch (InvocationTargetException e) {
476+
throw UncheckedThrow.throwUnchecked(e.getCause());
477+
}
478+
}
462479
}

src/main/java/com/nordstrom/automation/junit/RunChild.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void intercept(@This final Object runner, @SuperCall final Callabl
3636
}
3737

3838
if (count == 0) {
39-
proxy.call();
39+
LifecycleHooks.callProxy(proxy);
4040
} else if (!isIgnored) {
4141
RetryHandler.runChildWithRetry(runner, method, notifier, count);
4242
}

src/main/java/com/nordstrom/automation/junit/RunReflectiveCall.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static Object intercept(@This final Object callable, @SuperCall final Cal
7272
}
7373

7474
if (method == null) {
75-
return proxy.call();
75+
return LifecycleHooks.callProxy(proxy);
7676
}
7777

7878
Object result = null;
@@ -82,7 +82,7 @@ public static Object intercept(@This final Object callable, @SuperCall final Cal
8282
}
8383

8484
try {
85-
result = proxy.call();
85+
result = LifecycleHooks.callProxy(proxy);
8686
} catch (Throwable t) {
8787
thrown = t;
8888
} finally {

0 commit comments

Comments
 (0)