Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC] Add UserIdentityTest to improve code coverage in git-plugin #851

Merged
merged 3 commits into from
Mar 9, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
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.GitSCM;
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;

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() 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", "[email protected]");
}

@Test
public void testUserIdentity() throws Exception {
FreeStyleProject projectWithMaster = setupBasicProject(repo);
UserIdentity userIdentity = new UserIdentity("Jane Doe", "[email protected]");
((GitSCM)projectWithMaster.getScm()).getExtensions().add(userIdentity);
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved

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
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
public void testGetNameAndEmail(){
UserIdentity userIdentity = new UserIdentity("Jane Doe", "[email protected]");

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

@Test
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
public void equalsContract() {
Expand Down