package hudson.plugins.git.extensions.impl;

import hudson.EnvVars;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.plugins.git.BranchSpec;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.TestGitRepo;
import hudson.plugins.git.UserRemoteConfig;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionTest;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class UserIdentityTest extends GitSCMExtensionTest  {

    TestGitRepo repo;
    GitClient git;

    @Override
    public void before() throws Exception {
        repo = new TestGitRepo("repo", tmp.newFolder(), listener);
        git = Git.with(listener, new EnvVars()).in(repo.gitDir).getClient();
    }

    @Override
    protected GitSCMExtension getExtension() {
        return new UserIdentity("Jane Doe", "janeDoe@xyz.com");
    }

    @Test
    public void testUserIdentity() throws Exception {
        FreeStyleProject projectWithMaster = setupBasicProject(repo);
        UserIdentity userIdentity = new UserIdentity("Jane Doe", "janeDoe@xyz.com");
        ((GitSCM)projectWithMaster.getScm()).getExtensions().add(userIdentity);

        git.commit("First commit");

        FreeStyleBuild build = build(projectWithMaster, Result.SUCCESS);
        EnvVars envVars = build.getEnvironment(listener);
        assertThat("Jane Doe", is(envVars.get("GIT_AUTHOR_NAME")));
        assertThat("janeDoe@xyz.com", is(envVars.get("GIT_AUTHOR_EMAIL")));
    }

    @Test
    public void testGetNameAndEmail(){
        UserIdentity userIdentity = new UserIdentity("Jane Doe", "janeDoe@xyz.com");

        assertThat("Jane Doe", is(userIdentity.getName()));
        assertThat("janeDoe@xyz.com", is(userIdentity.getEmail()));
    }

    @Test
    public void equalsContract() {
        EqualsVerifier.forClass(UserIdentity.class)
                .usingGetClass()
                .verify();
    }
}

@@ -167,46 +167,8 @@
 lt;%0A
-import hudson.plugins.git.BranchSpec;%0A
 impo
@@ -240,52 +240,8 @@
 po;%0A
-import hudson.plugins.git.UserRemoteConfig;%0A
 impo
@@ -516,90 +516,8 @@
 t;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0A
 impo

Update UserIdentityTest: Removed unnecessary imports