package org.jenkinsci.plugins.github.status.sources;

import hudson.model.Run;
import hudson.model.TaskListener;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.when;

/**
 * @author pupssman (Kalinin Ivan)
 */
@RunWith(MockitoJUnitRunner.class)
public class BuildRefBackrefSourceTest {

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

    @Mock(answer = Answers.RETURNS_MOCKS)
    private Run run;

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

    @Test
    public void shouldReturnRunAbsoluteUrl() throws Exception {
        when(run.getAbsoluteUrl()).thenReturn("ABSOLUTE_URL");

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

}

@@ -47,16 +47,54 @@
 urces;%0A%0A
+import hudson.model.FreeStyleProject;%0A
 import h
@@ -223,16 +223,58 @@
 unWith;%0A
+import org.jvnet.hudson.test.JenkinsRule;%0A
 import o
@@ -722,48 +722,46 @@
 lic 
-MockitoRule mockitoRule = MockitoJUnit.r
+JenkinsRule jenkinsRule = new JenkinsR
 ule(
@@ -822,230 +822,311 @@
 ate 
-Run run;%0A%0A    @Mock(answer = Answers.RETURNS_MOCKS)%0A    private TaskListener listener;%0A%0A    @Test%0A    public void shouldReturnRunAbsoluteUrl() throws Exception %7B%0A        when(run.getAbsoluteUrl()).thenReturn(%22ABSOLUTE_URL%22
+TaskListener listener;%0A%0A    @Test%0A    /**%0A     * Should've used mocked Run, but getAbsoluteUrl is final.%0A     *%0A     * @throws Exception%0A     */%0A    public void shouldReturnRunAbsoluteUrl() throws Exception %7B%0A        Run%3C?, ?%3E run = jenkinsRule.buildAndAssertSuccess(jenkinsRule.createFreeStyleProject()
 );%0A%0A
@@ -1240,22 +1240,28 @@
  is(
-%22ABSOLUTE_URL%22
+run.getAbsoluteUrl()
 ));%0A

Change test to using JenkinsRule