Skip to content
Permalink
Browse files

[JENKINS-43507] Refactoring MockSCM to traits

  • Loading branch information...
stephenc committed Apr 12, 2017
1 parent 809ea04 commit 8c21a790a41b714e80c4f6a3334db0fe0738b6c0
@@ -66,7 +66,7 @@

<properties>
<jenkins.version>1.642.3</jenkins.version>
<scm-api.version>2.2.0-20170420.134709-5</scm-api.version>
<scm-api.version>2.2.0-SNAPSHOT</scm-api.version>
</properties>

<repositories>
@@ -49,6 +49,7 @@
import jenkins.scm.api.SCMSourceEvent;
import jenkins.scm.api.metadata.ObjectMetadataAction;
import jenkins.scm.impl.mock.MockSCMController;
import jenkins.scm.impl.mock.MockSCMDiscoverBranches;
import jenkins.scm.impl.mock.MockSCMLink;
import jenkins.scm.impl.mock.MockSCMNavigator;
import jenkins.scm.impl.mock.MockSCMSource;
@@ -100,7 +101,7 @@ public void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfter
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
@@ -115,7 +116,7 @@ public void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfter
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
fire(new MockSCMSourceEvent(SCMEvent.Type.UPDATED, c, "foo"));
r.waitUntilNoActivity();
@@ -130,7 +131,7 @@ public void given_multibranch_when_branches_then_branchBrandingPresent()
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItem("master").getAction(MockSCMLink.class), hasProperty("id", is("branch")));
@@ -144,7 +145,7 @@ public void given_multibranch_when_branches_then_runBrandingPresent()
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
@@ -171,7 +172,7 @@ public void given_multibranch_when_sourceHasNonSafeNames_then_branchDisplayNameN

BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
@@ -235,7 +236,7 @@ public void given_multibranch_when_sourceHasI18nNames_then_branchDisplayNameNotM

BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
@@ -318,7 +319,7 @@ public void given_orgFolder_when_navigatorDefined_then_navigatorBrandingPresentA
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
@@ -338,7 +339,7 @@ public void given_orgFolderWithI18nRepos_when_indexing_then_repoNamesEncoded()
c.createRepository("España");
c.createRepository("대한민국");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "multicultural");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
@@ -410,7 +411,7 @@ public void given_orgFolderWithNonSafeRepos_when_indexing_then_repoNamesEncoded(
c.createRepository("a*");
c.createRepository("a/b");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "multicultural");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
@@ -453,7 +454,7 @@ public void given_orgFolder_when_navigatorDefined_then_sourceBrandingPresentAfte
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
@@ -468,7 +469,7 @@ public void given_orgFolder_when_navigatorDefined_then_branchBrandingPresentAfte
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
@@ -484,7 +485,7 @@ public void given_orgFolder_when_navigatorDefined_then_revisionBrandingPresentAf
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getAction(MockSCMLink.class), nullValue());
prj.scheduleBuild2(0).getFuture().get();
@@ -502,7 +503,7 @@ public void given_multibranch_when_decoratedSourceDefined_then_descriptionPresen
c.setDescription("foo", "The Foo Project of Manchu");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getDescription(), nullValue());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
@@ -518,7 +519,7 @@ public void given_multibranch_when_decoratedSourceDefined_then_displayNamePresen
c.setDisplayName("foo", "Foo Project");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getDisplayName(), is("foo"));
assertThat(prj.getDisplayNameOrNull(), nullValue());
assertThat(prj.getAction(ObjectMetadataAction.class), nullValue());
@@ -537,7 +538,7 @@ public void given_orgFolder_when_decoratedSourceDefined_then_descriptionLinkPres
c.setDescription("foo", "The Foo Project of Manchu");
c.setUrl("foo", "http://foo.manchu.example.com/");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
@@ -561,7 +562,7 @@ public void given_multibranch_when_decoratedSourceDefined_then_folderIconPresent
c.setRepoIconClassName("icon-star");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
assertThat(prj.getIcon().getIconClassName(), not(is("icon-star")));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
@@ -576,7 +577,7 @@ public void given_orgFolder_when_decoratedOrganizationDefined_then_folderIconPre
c.createRepository("foo");
c.setOrgIconClassName("icon-star");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getIcon().getIconClassName(), not(is("icon-star")));
prj.scheduleBuild2(0).getFuture().get();
@@ -592,7 +593,7 @@ public void given_orgFolder_when_decoratedOrganizationDefined_then_displayNamePr
c.createRepository("foo");
c.setDisplayName("Foo Organization");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
assertThat(prj.getDisplayName(), is("foo"));
prj.scheduleBuild2(0).getFuture().get();
@@ -609,7 +610,7 @@ public void given_orgFolder_when_decoratedOrganizationDefined_then_descriptionLi
c.setDescription("The Foo of Manchu");
c.setUrl("http://foo.manchu.example.com/");
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getSCMNavigators().add(new MockSCMNavigator(c, new MockSCMDiscoverBranches()));
prj.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
@@ -35,6 +35,9 @@
import jenkins.scm.impl.TagSCMHeadCategory;
import jenkins.scm.impl.UncategorizedSCMHeadCategory;
import jenkins.scm.impl.mock.MockSCMController;
import jenkins.scm.impl.mock.MockSCMDiscoverBranches;
import jenkins.scm.impl.mock.MockSCMDiscoverChangeRequests;
import jenkins.scm.impl.mock.MockSCMDiscoverTags;
import jenkins.scm.impl.mock.MockSCMSource;
import org.junit.Before;
import org.junit.ClassRule;
@@ -85,7 +88,7 @@ public void given_multibranch_when_atLeastOneSourceDefinedButNoItems_then_welcom
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
assertThat("We have no items", prj.getItems(), empty());
assertThat("We have the empty view when no items", prj.getViews(),
contains(instanceOf(MultiBranchProjectEmptyView.class)));
@@ -100,7 +103,7 @@ public void given_multibranch_when_onlyUncategorizedCategory_then_onlyUncategori
Integer crNum = c.openChangeRequest("foo", "master");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches())));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItems(),
@@ -127,7 +130,7 @@ public void given_multibranch_when_changeRequestsWanted_then_onlyUncategorizedAn
Integer crNum = c.openChangeRequest("foo", "master");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, true)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches(), new MockSCMDiscoverChangeRequests())));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItems(),
@@ -161,7 +164,7 @@ public void given_multibranch_when_tagsWanted_then_onlyUncategorizedAndTagsViews
Integer crNum = c.openChangeRequest("foo", "master");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, true, false)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches(), new MockSCMDiscoverTags())));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItems(),
@@ -195,7 +198,7 @@ public void given_multibranch_when_noBranchesWanted_then_uncategorizedViewPresen
Integer crNum = c.openChangeRequest("foo", "master");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", false, true, true)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests())));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItems(),
@@ -241,7 +244,7 @@ public void given_multibranch_when_wantsEverything_then_hasEverything()
c.addFile("foo", "change-request/" + crNum2, "propose change", "CHANGE", "proposed".getBytes());
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, true, true)));
prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", new MockSCMDiscoverBranches(), new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests())));
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getItems(),
Oops, something went wrong.

0 comments on commit 8c21a79

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