| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.test.runners; |
| 17 | |
|
| 18 | |
import org.apache.commons.beanutils.MethodUtils; |
| 19 | |
import org.junit.runner.notification.RunNotifier; |
| 20 | |
import org.junit.runners.BlockJUnit4ClassRunner; |
| 21 | |
import org.junit.runners.model.FrameworkMethod; |
| 22 | |
import org.junit.runners.model.InitializationError; |
| 23 | |
import org.kuali.rice.test.MethodAware; |
| 24 | |
|
| 25 | |
import java.lang.reflect.Method; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 0 | public class RiceUnitTestClassRunner extends BlockJUnit4ClassRunner { |
| 35 | |
private Method currentMethod; |
| 36 | |
|
| 37 | |
public RiceUnitTestClassRunner(final Class<?> testClass) throws InitializationError { |
| 38 | 0 | super(testClass); |
| 39 | |
|
| 40 | 0 | } |
| 41 | |
|
| 42 | |
@Override |
| 43 | |
protected void runChild(FrameworkMethod method, RunNotifier runNotifier) { |
| 44 | 0 | this.currentMethod = method.getMethod(); |
| 45 | |
try { |
| 46 | 0 | super.runChild(method, runNotifier); |
| 47 | |
} finally { |
| 48 | 0 | this.currentMethod = null; |
| 49 | 0 | } |
| 50 | 0 | } |
| 51 | |
|
| 52 | |
@Override |
| 53 | |
protected Object createTest() throws Exception { |
| 54 | 0 | Object test = super.createTest(); |
| 55 | 0 | setTestName(test, currentMethod); |
| 56 | 0 | setTestMethod(test, currentMethod); |
| 57 | 0 | return test; |
| 58 | |
} |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
protected void setTestMethod(Object test, Method method) { |
| 66 | 0 | if (test instanceof MethodAware) { |
| 67 | 0 | ((MethodAware) test).setTestMethod(method); |
| 68 | |
} |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
protected void setTestName(final Object test, final Method testMethod) throws Exception { |
| 72 | 0 | String name = testMethod == null ? "" : testMethod.getName(); |
| 73 | 0 | final Method setNameMethod = MethodUtils.getAccessibleMethod(test.getClass(), "setName", new Class[]{String.class}); |
| 74 | 0 | if (setNameMethod != null) { |
| 75 | 0 | setNameMethod.invoke(test, name); |
| 76 | |
} |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
} |