Skip to content

Commit

Permalink
Change test to using JenkinsRule
Browse files Browse the repository at this point in the history
  • Loading branch information
pupssman committed Sep 19, 2016
1 parent 8e23c4c commit fb3dd70
Showing 1 changed file with 10 additions and 6 deletions.
@@ -1,10 +1,12 @@
package org.jenkinsci.plugins.github.status.sources;

import hudson.model.FreeStyleProject;
import hudson.model.Run;
import hudson.model.TaskListener;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.jvnet.hudson.test.JenkinsRule;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
Expand All @@ -22,20 +24,22 @@
public class BuildRefBackrefSourceTest {

@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();

@Mock(answer = Answers.RETURNS_MOCKS)
private Run run;
public JenkinsRule jenkinsRule = new JenkinsRule();

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

@Test
/**
* Should've used mocked Run, but getAbsoluteUrl is final.
*
* @throws Exception
*/
public void shouldReturnRunAbsoluteUrl() throws Exception {
when(run.getAbsoluteUrl()).thenReturn("ABSOLUTE_URL");
Run<?, ?> run = jenkinsRule.buildAndAssertSuccess(jenkinsRule.createFreeStyleProject());

String result = new BuildRefBackrefSource().get(run, listener);
assertThat("state", result, is("ABSOLUTE_URL"));
assertThat("state", result, is(run.getAbsoluteUrl()));
}

}

0 comments on commit fb3dd70

Please sign in to comment.