-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #851 from rishabhBudhouliya/UserIdentityTest
[GSoC] Add UserIdentityTest to improve code coverage in git-plugin
- Loading branch information
Showing
1 changed file
with
51 additions
and
1 deletion.
There are no files selected for viewing
52 changes: 51 additions & 1 deletion
52
src/test/java/hudson/plugins/git/extensions/impl/UserIdentityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|