Skip to content
Permalink
Browse files

[JENKINS-43507] Fix test case in AbstractGitSCMSourceTest

  • Loading branch information...
stephenc committed May 2, 2017
1 parent 9504dd1 commit 3f8f67491cb5bff1b79fde8c4321320465e12050
@@ -36,6 +36,27 @@ public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listene
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
return o instanceof CleanBeforeCheckout;
}

@Override
public int hashCode() {
return CleanBeforeCheckout.class.hashCode();
}

@Override
public String toString() {
return "CleanBeforeCheckout{}";
}

@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
@Override
@@ -32,6 +32,27 @@ public void onCheckoutCompleted(GitSCM scm, Run<?, ?> build, GitClient git, Task
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
return o instanceof CleanCheckout;
}

@Override
public int hashCode() {
return CleanCheckout.class.hashCode();
}

@Override
public String toString() {
return "CleanCheckout{}";
}

@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
@Override
@@ -15,6 +15,27 @@
public IgnoreNotifyCommit() {
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
return o instanceof IgnoreNotifyCommit;
}

@Override
public int hashCode() {
return IgnoreNotifyCommit.class.hashCode();
}

@Override
public String toString() {
return "IgnoreNotifyCommit{}";
}

@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
@Override
@@ -1,5 +1,6 @@
package hudson.plugins.git.extensions.impl;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.Extension;
import hudson.Util;
import hudson.plugins.git.extensions.FakeGitSCMExtension;
@@ -16,17 +17,46 @@
* @author Kohsuke Kawaguchi
*/
public class LocalBranch extends FakeGitSCMExtension {
@CheckForNull
private String localBranch;

@DataBoundConstructor
public LocalBranch(String localBranch) {
public LocalBranch(@CheckForNull String localBranch) {
this.localBranch = Util.fixEmptyAndTrim(localBranch);
}

@CheckForNull
public String getLocalBranch() {
return localBranch;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

LocalBranch that = (LocalBranch) o;

return localBranch != null ? localBranch.equals(that.localBranch) : that.localBranch == null;
}

@Override
public int hashCode() {
return localBranch != null ? localBranch.hashCode() : 0;
}

@Override
public String toString() {
return "LocalBranch{" +
(localBranch == null || "**".equals(localBranch) ? "same-as-remote" : "localBranch='"+localBranch+"'")
+ '}';
}


@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
@Override
@@ -623,15 +623,26 @@ protected GitSCMBuilder newBuilder(@NonNull SCMHead head, @CheckForNull SCMRevis
@NonNull
@Override
public SCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) {
return newBuilder(head, revision)
GitSCMBuilder builder = newBuilder(head, revision)
.withRemote(getRemote())
.withCredentials(getCredentialsId())
.withExtensions(getExtensions()) // in case a legacy non-trait aware older sub-class has overridden
.withBrowser(getBrowser()) // in case a legacy non-trait aware older sub-class has overridden
.withGitTool(getGitTool()) // in case a legacy non-trait aware older sub-class has overridden
.withRefSpecs(getRefSpecs()) // in case a legacy non-trait aware older sub-class has overridden
.withTraits(getTraits())
.build();
.withCredentials(getCredentialsId());
if (Util.isOverridden(AbstractGitSCMSource.class, getClass(), "getExtensions")) {
builder.withExtensions(getExtensions());
}
if (Util.isOverridden(AbstractGitSCMSource.class, getClass(), "getBrowser")) {
builder.withBrowser(getBrowser());
}
if (Util.isOverridden(AbstractGitSCMSource.class, getClass(), "getGitTool")) {
builder.withGitTool(getGitTool());
}
if (Util.isOverridden(AbstractGitSCMSource.class, getClass(), "getGitTool")) {
List<String> specs = new ArrayList<>();
for (RefSpec spec: getRefSpecs()) {
specs.add(spec.toString());
}
builder.withRefSpecs(specs);
}
return builder.withTraits(getTraits()).build();
}

@Deprecated
@@ -7,6 +7,7 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.git.UserRemoteConfig;
import hudson.plugins.git.extensions.impl.IgnoreNotifyCommit;
import hudson.scm.SCMRevisionState;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.GitSCMExtension;
@@ -27,6 +28,8 @@

import jenkins.scm.api.SCMSourceOwner;
import jenkins.scm.api.metadata.PrimaryInstanceMetadataAction;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
@@ -257,20 +260,36 @@ public void testSpecificRevisionBuildChooser() throws Exception {
extensions.add(localBranchExtension);
source.setExtensions(extensions);
assertEquals(source.getExtensions(), extensions);
TaskListener listener = StreamTaskListener.fromStderr();

SCMHead head = new SCMHead("master");
SCMRevision revision = new AbstractGitSCMSource.SCMRevisionImpl(head, "beaded4deed2bed4feed2deaf78933d0f97a5a34");

// because we are ignoring push notifications we also ignore commits
extensions.add(new IgnoreNotifyCommit());

/* Check that BuildChooserSetting not added to extensions by build() */
GitSCM scm = (GitSCM) source.build(head);
assertEquals(extensions, scm.getExtensions());
List<GitSCMExtension> scmExtensions = scm.getExtensions();
assertThat(scmExtensions, Matchers.<List<GitSCMExtension>>allOf(
not(Matchers.<GitSCMExtension>hasItem(instanceOf(BuildChooserSetting.class))),
containsInAnyOrder(extensions.toArray(new GitSCMExtension[extensions.size()]))
));


/* Check that BuildChooserSetting has been added to extensions by build() */
GitSCM scmRevision = (GitSCM) source.build(head, revision);
assertEquals(extensions.get(0), scmRevision.getExtensions().get(0));
assertTrue(scmRevision.getExtensions().get(1) instanceof BuildChooserSetting);
assertEquals(2, scmRevision.getExtensions().size());
scmExtensions = scmRevision.getExtensions();
for (GitSCMExtension e: scmExtensions) {
if (e instanceof BuildChooserSetting) {
extensions.add(e);
break;
}
}
assertThat(scmExtensions, Matchers.<List<GitSCMExtension>>allOf(
Matchers.<GitSCMExtension>hasSize(3),
containsInAnyOrder(extensions.toArray(new GitSCMExtension[extensions.size()])),
Matchers.<GitSCMExtension>hasItem(instanceOf(BuildChooserSetting.class))
));
}


0 comments on commit 3f8f674

Please sign in to comment.
You can’t perform that action at this time.