Skip to content

Commit

Permalink
Merge pull request #851 from rishabhBudhouliya/UserIdentityTest
Browse files Browse the repository at this point in the history
[GSoC] Add UserIdentityTest to improve code coverage in git-plugin
  • Loading branch information
MarkEWaite authored Mar 9, 2020
2 parents f46eebf + 5f4f05b commit a1c761b
Showing 1 changed file with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,61 @@
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.TestGitRepo;
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 org.jvnet.hudson.test.WithoutJenkins;

public class UserIdentityTest {
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() {
// do nothing
}

@Override
protected GitSCMExtension getExtension() {
return new UserIdentity("Jane Doe", "[email protected]");
}

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

FreeStyleProject projectWithMaster = setupBasicProject(repo);
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("[email protected]", is(envVars.get("GIT_AUTHOR_EMAIL")));
}

@Test
@WithoutJenkins
public void testGetNameAndEmail(){
UserIdentity userIdentity = new UserIdentity("Jane Doe", "[email protected]");

assertThat("Jane Doe", is(userIdentity.getName()));
assertThat("[email protected]", is(userIdentity.getEmail()));
}

@Test
@WithoutJenkins
public void equalsContract() {
EqualsVerifier.forClass(UserIdentity.class)
.usingGetClass()
Expand Down

0 comments on commit a1c761b

Please sign in to comment.