Skip to content

Commit fb3dd70

Browse files
committed
Change test to using JenkinsRule
1 parent 8e23c4c commit fb3dd70

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/test/java/org/jenkinsci/plugins/github/status/sources/BuildRefBackrefSourceTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.jenkinsci.plugins.github.status.sources;
22

3+
import hudson.model.FreeStyleProject;
34
import hudson.model.Run;
45
import hudson.model.TaskListener;
56
import org.junit.Rule;
67
import org.junit.Test;
78
import org.junit.runner.RunWith;
9+
import org.jvnet.hudson.test.JenkinsRule;
810
import org.mockito.Answers;
911
import org.mockito.Mock;
1012
import org.mockito.junit.MockitoJUnit;
@@ -22,20 +24,22 @@
2224
public class BuildRefBackrefSourceTest {
2325

2426
@Rule
25-
public MockitoRule mockitoRule = MockitoJUnit.rule();
26-
27-
@Mock(answer = Answers.RETURNS_MOCKS)
28-
private Run run;
27+
public JenkinsRule jenkinsRule = new JenkinsRule();
2928

3029
@Mock(answer = Answers.RETURNS_MOCKS)
3130
private TaskListener listener;
3231

3332
@Test
33+
/**
34+
* Should've used mocked Run, but getAbsoluteUrl is final.
35+
*
36+
* @throws Exception
37+
*/
3438
public void shouldReturnRunAbsoluteUrl() throws Exception {
35-
when(run.getAbsoluteUrl()).thenReturn("ABSOLUTE_URL");
39+
Run<?, ?> run = jenkinsRule.buildAndAssertSuccess(jenkinsRule.createFreeStyleProject());
3640

3741
String result = new BuildRefBackrefSource().get(run, listener);
38-
assertThat("state", result, is("ABSOLUTE_URL"));
42+
assertThat("state", result, is(run.getAbsoluteUrl()));
3943
}
4044

4145
}

0 commit comments

Comments
 (0)