Skip to content

Commit cdb46e7

Browse files
committed
More progress
1 parent f036d1f commit cdb46e7

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,10 @@ public static Object getRunnerFor(TestClass testClass) {
210210
throw new IllegalStateException("No associated runner was for for specified test class");
211211
}
212212

213-
public static Description getDescription(Object instance, Object target) {
213+
public static Description describeChild(Object instance, Object child) {
214214
TestClass testClass = getTestClassFor(instance);
215215
Object runner = getRunnerFor(testClass);
216-
217-
218-
return invoke(runner, "getDescription", target);
216+
return invoke(runner, "describeChild", child);
219217
}
220218

221219
/**

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import org.junit.runners.model.FrameworkMethod;
1414

15+
import com.nordstrom.common.base.UncheckedThrow;
16+
1517
import net.bytebuddy.implementation.bind.annotation.BindingPriority;
1618
import net.bytebuddy.implementation.bind.annotation.Origin;
1719
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
@@ -43,15 +45,14 @@ private MethodInterceptor() {
4345
* @param clazz "enhanced" class upon which the method was invoked
4446
* @param method {@link Method} object for the invoked method
4547
* @param proxy call-able proxy for the intercepted method
46-
* @return {@code anything} (the result of invoking the intercepted method)
4748
* @throws Exception {@code anything} (exception thrown by the intercepted method)
4849
*/
4950
@RuntimeType
5051
@BindingPriority(1)
51-
public static Object intercept(@Origin Class<?> clazz, @Origin Method method, @SuperCall Callable<?> proxy) throws Exception {
52-
Object result;
52+
public static void intercept(@Origin Class<?> clazz, @Origin Method method, @SuperCall Callable<?> proxy) throws Exception {
5353
attachWatchers(clazz);
5454

55+
Throwable thrown = null;
5556
FrameworkMethod member = new FrameworkMethod(method);
5657
synchronized(methodWatchers2) {
5758
for (MethodWatcher2 watcher : methodWatchers2) {
@@ -60,16 +61,20 @@ public static Object intercept(@Origin Class<?> clazz, @Origin Method method, @S
6061
}
6162

6263
try {
63-
result = proxy.call();
64+
proxy.call();
65+
} catch (Throwable t) {
66+
thrown = t;
6467
} finally {
6568
synchronized(methodWatchers2) {
6669
for (MethodWatcher2 watcher : methodWatchers2) {
67-
watcher.afterInvocation(member);
70+
watcher.afterInvocation(member, thrown);
6871
}
6972
}
7073
}
7174

72-
return result;
75+
if (thrown != null) {
76+
throw UncheckedThrow.throwUnchecked(thrown);
77+
}
7378
}
7479

7580
/**
@@ -78,15 +83,13 @@ public static Object intercept(@Origin Class<?> clazz, @Origin Method method, @S
7883
* @param obj "enhanced" object upon which the method was invoked
7984
* @param method {@link Method} object for the invoked method
8085
* @param proxy call-able proxy for the intercepted method
81-
* @return {@code anything} (the result of invoking the intercepted method)
8286
* @throws Exception {@code anything} (exception thrown by the intercepted method)
8387
*/
8488
@RuntimeType
8589
@BindingPriority(2)
86-
public static Object intercept(@This Object obj, @Origin Method method, @SuperCall Callable<?> proxy) throws Exception
90+
public static void intercept(@This Object obj, @Origin Method method, @SuperCall Callable<?> proxy) throws Exception
8791
{
88-
Object result;
89-
92+
Throwable thrown = null;
9093
FrameworkMethod member = new FrameworkMethod(method);
9194
synchronized(methodWatchers) {
9295
for (MethodWatcher watcher : methodWatchers) {
@@ -100,23 +103,27 @@ public static Object intercept(@This Object obj, @Origin Method method, @SuperCa
100103
}
101104

102105
try {
103-
result = proxy.call();
106+
proxy.call();
107+
} catch (Throwable t) {
108+
thrown = t;
104109
} finally {
105110
synchronized(watchers) {
106111
synchronized(methodWatchers) {
107112
for (MethodWatcher watcher : methodWatchers) {
108-
watcher.afterInvocation(obj, member);
113+
watcher.afterInvocation(obj, member, thrown);
109114
}
110115
}
111116
synchronized(methodWatchers2) {
112117
for (MethodWatcher2 watcher : methodWatchers2) {
113-
watcher.afterInvocation(obj, member);
118+
watcher.afterInvocation(obj, member, thrown);
114119
}
115120
}
116121
}
117122
}
118123

119-
return result;
124+
if (thrown != null) {
125+
throw UncheckedThrow.throwUnchecked(thrown);
126+
}
120127
}
121128

122129
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public interface MethodWatcher {
2121
*
2222
* @param obj "enhanced" object upon which the method was invoked
2323
* @param method {@link FrameworkMethod} object for the invoked method
24+
* @param thrown exception thrown by method; {@code null} on normal completion
2425
*/
25-
void afterInvocation(Object obj, FrameworkMethod method);
26+
void afterInvocation(Object obj, FrameworkMethod method, Throwable thrown);
2627
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public interface MethodWatcher2 extends MethodWatcher {
1919
* Invoked after each class-level configuration method is invoked
2020
*
2121
* @param method {@link FrameworkMethod} object for the invoked method
22+
* @param thrown exception thrown by method; {@code null} on normal completion
2223
*/
23-
void afterInvocation(FrameworkMethod method);
24+
void afterInvocation(FrameworkMethod method, Throwable thrown);
2425
}

src/test/java/com/nordstrom/automation/junit/UnitTestWatcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void beforeInvocation(Object obj, FrameworkMethod method) {
3737
}
3838

3939
@Override
40-
public void afterInvocation(Object obj, FrameworkMethod method) {
40+
public void afterInvocation(Object obj, FrameworkMethod method, Throwable thrown) {
4141
if (null != method.getAnnotation(Before.class)) {
4242
m_leaveBeforeMethod.add(method.getName());
4343
} else if (null != method.getAnnotation(Test.class)) {
@@ -57,7 +57,7 @@ public void beforeInvocation(FrameworkMethod method) {
5757
}
5858

5959
@Override
60-
public void afterInvocation(FrameworkMethod method) {
60+
public void afterInvocation(FrameworkMethod method, Throwable thrown) {
6161
if (null != method.getAnnotation(BeforeClass.class)) {
6262
m_leaveBeforeClass.add(method.getName());
6363
} else if (null != method.getAnnotation(AfterClass.class)) {

0 commit comments

Comments
 (0)