Converted ExtensionFinderTest to JenkinsRule.
@@ -25,29 +25,36 @@ package hudson;
import com.google.inject.AbstractModule;
import hudson.model.PageDecorator;
-import org.jvnet.hudson.test.HudsonTestCase;
-import org.jvnet.hudson.test.TestEnvironment;
-import org.jvnet.hudson.test.TestExtension;
-
-import javax.inject.Inject;
-import javax.inject.Qualifier;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import javax.inject.Inject;
+import javax.inject.Qualifier;
+import static org.junit.Assert.*;
+import org.junit.Rule;
+import org.junit.Test;
+import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.TestEnvironment;
+import org.jvnet.hudson.test.TestExtension;
/**
* @author Kohsuke Kawaguchi
*/
-public class ExtensionFinderTest extends HudsonTestCase {
+public class ExtensionFinderTest {
+
+ @Rule
+ public JenkinsRule r = new JenkinsRule();
+
/**
* It's OK for some extensions to fail to load. The system needs to tolerate that.
*/
- public void testFailingInstance() {
+ @Test
+ public void failingInstance() {
FailingExtension i = PageDecorator.all().get(FailingExtension.class);
assertNull("Instantiation should have failed",i);
assertTrue("Instantiation should have been attempted", FailingExtension.error);
}
- @TestExtension("testFailingInstance")
+ @TestExtension("failingInstance")
public static class FailingExtension extends PageDecorator {
public FailingExtension() {
super(FailingExtension.class);
@@ -64,13 +71,14 @@ public class ExtensionFinderTest extends HudsonTestCase {
/**
* Extensions are Guice components, so it should support injection.
*/
- public void testInjection() {
+ @Test
+ public void injection() {
InjectingExtension i = PageDecorator.all().get(InjectingExtension.class);
assertNotNull(i.foo);
assertEquals("lion king",i.value);
}
- @TestExtension("testInjection")
+ @TestExtension("injection")
public static class InjectingExtension extends PageDecorator {
@Inject
Foo foo;
@@ -94,7 +102,7 @@ public class ExtensionFinderTest extends HudsonTestCase {
protected void configure() {
TestEnvironment environment = TestEnvironment.get();
// JMH benchmarks do not initialize TestEnvironment, so check for null
- if (environment != null && environment.testCase instanceof ExtensionFinderTest) {
+ if (environment != null && ExtensionFinderTest.class.getName().equals(environment.description().getClassName()) && "injection".equals(environment.description().getMethodName())) {
bind(String.class).annotatedWith(LionKing.class).toInstance("lion king");
}
}
@@ -106,12 +114,13 @@ public class ExtensionFinderTest extends HudsonTestCase {
*
* One failure in binding definition shouldn't prevent Jenkins from booting.
*/
- public void testErrorRecovery() {
+ @Test
+ public void errorRecovery() {
BrokenExtension i = PageDecorator.all().get(BrokenExtension.class);
assertNull(i);
}
- @TestExtension("testErrorRecovery")
+ @TestExtension("errorRecovery")
public static class BrokenExtension extends PageDecorator {
public BrokenExtension() {
super(InjectingExtension.class);
