提交 26276d13 编写于 作者: K Kohsuke Kawaguchi

added a backward compatibility with MethodRule.

Without this, I saw:

FAILURE: initializationError(hudson.model.CauseTest)
[INFO] java.lang.Exception: Field j must implement MethodRule
[INFO] 	at org.junit.runners.BlockJUnit4ClassRunner.validateRuleField(BlockJUnit4ClassRunner.java:188)
[INFO] 	at org.junit.runners.BlockJUnit4ClassRunner.validateFields(BlockJUnit4ClassRunner.java:183)
[INFO] 	at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:123)
[INFO] 	at org.junit.runners.ParentRunner.validate(ParentRunner.java:269)
[INFO] 	at org.junit.runners.ParentRunner.<init>(ParentRunner.java:66)
[INFO] 	at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:58)
[INFO] 	at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
[INFO] 	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
[INFO] 	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
[INFO] 	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
[INFO] 	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
[INFO] 	at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
[INFO] 	at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
[INFO] 	at com.sun.maven.junit.LocalTestCaseRunner.buildMethodTestCase(LocalTestCaseRunner.java:121)
[INFO] 	at com.sun.maven.junit.LocalTestCaseRunner.buildTestCase(LocalTestCaseRunner.java:83)
[INFO] 	at com.sun.maven.junit.LocalTestCaseRunner.runTestCase(LocalTestCaseRunner.java:62)
[INFO] 	at com.sun.maven.junit.LocalTestCaseRunner.runTestCase(LocalTestCaseRunner.java:58)
[INFO] 	at sun.reflect.GeneratedMethodAccessor334.invoke(Unknown Source)
[INFO] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[INFO] 	at java.lang.reflect.Method.invoke(Method.java:597)
[INFO] 	at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:274)
[INFO] 	at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:255)
[INFO] 	at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:215)
[INFO] 	at hudson.remoting.UserRequest.perform(UserRequest.java:118)
[INFO] 	at hudson.remoting.UserRequest.perform(UserRequest.java:48)
[INFO] 	at hudson.remoting.Request$2.run(Request.java:270)
[INFO] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
[INFO] 	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
[INFO] 	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
[INFO] 	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
[INFO] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
[INFO] 	at java.lang.Thread.run(Thread.java:662)
上级 7f8fe215
......@@ -132,9 +132,11 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.hamcrest.Matchers;
import org.junit.rules.MethodRule;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.recipes.Recipe;
import org.jvnet.hudson.test.rhino.JavaScriptDebugger;
......@@ -220,7 +222,7 @@ import static org.junit.matchers.JUnitMatchers.containsString;
* @author Stephen Connolly
* @since 1.436
*/
public class JenkinsRule implements TestRule, RootAction {
public class JenkinsRule implements TestRule, MethodRule, RootAction {
private final TestEnvironment env = new TestEnvironment(null);
......@@ -445,6 +447,13 @@ public class JenkinsRule implements TestRule, RootAction {
}
}
/**
* Backward compatibility with JUnit 4.8.
*/
public Statement apply(Statement base, FrameworkMethod method, Object target) {
return apply(base,Description.createTestDescription(method.getMethod().getDeclaringClass(), method.getName(), method.getAnnotations()));
}
public Statement apply(final Statement base, final Description description) {
if (description.getAnnotation(WithoutJenkins.class) != null) {
// request has been made to not create the instance for this test method
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册