Skip to content

Commit 5a35270

Browse files
committed
Replace incomplete implementation with MethodUtils.invokeMethod
1 parent e7ce783 commit 5a35270

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import java.lang.instrument.Instrumentation;
77
import java.lang.reflect.Field;
88
import java.lang.reflect.InvocationTargetException;
9-
import java.lang.reflect.Method;
109
import java.util.Arrays;
1110
import java.util.ServiceLoader;
1211
import java.util.concurrent.Callable;
1312
import java.util.concurrent.ConcurrentMap;
1413

14+
import org.apache.commons.lang3.reflect.MethodUtils;
1515
import org.junit.runner.Description;
1616
import org.junit.runner.notification.RunListener;
1717
import org.junit.runners.model.TestClass;
@@ -258,27 +258,11 @@ static String getSubclassName(Object testObj) {
258258
*/
259259
@SuppressWarnings("unchecked")
260260
static <T> T invoke(Object target, String methodName, Object... parameters) {
261-
Class<?>[] parameterTypes = new Class<?>[parameters.length];
262-
for (int i = 0; i < parameters.length; i++) {
263-
parameterTypes[i] = parameters[i].getClass();
264-
}
265-
266-
Throwable thrown = null;
267-
for (Class<?> current = target.getClass(); current != null; current = current.getSuperclass()) {
268-
try {
269-
Method method = current.getDeclaredMethod(methodName, parameterTypes);
270-
method.setAccessible(true);
271-
return (T) method.invoke(target, parameters);
272-
} catch (NoSuchMethodException e) {
273-
thrown = e;
274-
} catch (SecurityException | IllegalAccessException | IllegalArgumentException
275-
| InvocationTargetException e) {
276-
thrown = e;
277-
break;
278-
}
261+
try {
262+
return (T) MethodUtils.invokeMethod(target, true, methodName, parameters);
263+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
264+
throw UncheckedThrow.throwUnchecked(e);
279265
}
280-
281-
throw UncheckedThrow.throwUnchecked(thrown);
282266
}
283267

284268
/**

0 commit comments

Comments
 (0)