package org.jenkinsci.plugins.gittagmessage;

import hudson.Util;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.plugins.git.BranchSpec;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.SubmoduleConfig;
import hudson.plugins.git.UserRemoteConfig;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.tasks.Shell;

import java.util.Collections;

import static org.jenkinsci.plugins.gittagmessage.GitTagMessageAction.ENV_VAR_NAME_MESSAGE;
import static org.jenkinsci.plugins.gittagmessage.GitTagMessageAction.ENV_VAR_NAME_TAG;

public class GitTagMessageExtensionTest extends AbstractGitTagMessageExtensionTest<FreeStyleProject, FreeStyleBuild> {

    /**
     * @param refSpec The refspec to check out.
     * @param branchSpec The branch spec to build.
     * @param useMostRecentTag true to use the most recent tag rather than the exact one.
     * @return A job configured with the test Git repo, given settings, and the Git Tag Message extension.
     */
    protected FreeStyleProject configureGitTagMessageJob(String refSpec, String branchSpec, boolean useMostRecentTag) throws Exception {
        UserRemoteConfig remote = new UserRemoteConfig(repoDir.getRoot().getAbsolutePath(), "origin", refSpec, null);
        GitSCM scm = new GitSCM(
                Collections.singletonList(remote),
                Collections.singletonList(new BranchSpec(branchSpec)),
                false, Collections.<SubmoduleConfig>emptyList(),
                null, null,
                Collections.<GitSCMExtension>singletonList(new GitTagMessageExtension(useMostRecentTag)));

        FreeStyleProject job = jenkins.createFreeStyleProject();
        job.getBuildersList().add(new Shell("echo \"tag='${" + ENV_VAR_NAME_TAG + "}'\""));
        job.getBuildersList().add(new Shell("echo \"msg='${" + ENV_VAR_NAME_MESSAGE + "}'\""));
        job.setScm(scm);
        return job;
    }

    /** Asserts that the given build exported tag information, or not, if {@code null}. */
    protected void assertBuildEnvironment(FreeStyleBuild build, String expectedName, String expectedMessage)
            throws Exception {
        // In the freestyle shell step, unknown environment variables are returned as empty strings
        jenkins.assertLogContains(String.format("tag='%s'", Util.fixNull(expectedName)), build);
        jenkins.assertLogContains(String.format("msg='%s'", Util.fixNull(expectedMessage)), build);
    }

}
@@ -1147,32 +1147,162 @@
 ows Exception %7B%0A
+        GitTagMessageExtension extension = new GitTagMessageExtension();%0A        extension.setUseMostRecentTag(useMostRecentTag);%0A
         UserRemo
@@ -1714,52 +1714,17 @@
 ist(
-new GitTagMessageExtension(useMostRecentTag)
+extension
 ));%0A

Fix creation of the extension in test case.