55import integration .harness .BasicDummyStepBranchProperty ;
66import integration .harness .BasicMultiBranchProject ;
77import jenkins .model .Jenkins ;
8- import jenkins .scm .api .SCMSource ;
98import jenkins .scm .impl .mock .MockSCMController ;
9+ import jenkins .scm .impl .mock .MockSCMDiscoverBranches ;
1010import jenkins .scm .impl .mock .MockSCMDiscoverChangeRequests ;
1111import jenkins .scm .impl .mock .MockSCMSource ;
1212import org .junit .ClassRule ;
@@ -42,12 +42,13 @@ public void testObjectNameStrategy() throws Exception {
4242
4343 public void testNamingStrategy (final MultiBranchProjectDisplayNamingStrategy namingStrategy ) throws Exception {
4444 final Jenkins jenkinsInstance = r .jenkins ;
45+ final String mainBranch = "master" ;
4546 final String projectName = String .format ("Project_%s" , namingStrategy .name ());
4647
4748 try (final MockSCMController mockScm = MockSCMController .create ()) {
4849 mockScm .createRepository (REPO_NAME );
4950
50- final Integer crNumber = mockScm .openChangeRequest (REPO_NAME , "master" );
51+ final Integer crNumber = mockScm .openChangeRequest (REPO_NAME , mainBranch );
5152 final String crName = String .format ("CR-%s" , crNumber );
5253 final String crTitle = String .format ("Change request #%s" , crNumber );
5354
@@ -58,6 +59,7 @@ public void testNamingStrategy(final MultiBranchProjectDisplayNamingStrategy nam
5859 final MockSCMSource scmSource = new MockSCMSource (
5960 mockScm ,
6061 REPO_NAME ,
62+ new MockSCMDiscoverBranches (),
6163 new MockSCMDiscoverChangeRequests (),
6264 new MultiBranchProjectDisplayNamingTrait (namingStrategy )
6365 );
@@ -67,14 +69,23 @@ public void testNamingStrategy(final MultiBranchProjectDisplayNamingStrategy nam
6769 project .getSourcesList ().add (source );
6870 r .configRoundtrip (project );
6971
72+ final FreeStyleProject branchProject = jenkinsInstance .getItemByFullName (
73+ String .format ("%s/%s" , projectName , mainBranch ),
74+ FreeStyleProject .class
75+ );
76+
77+ final String expectedBranchProjectName = namingStrategy .generateName (mainBranch , "" );
78+ assertNotNull (branchProject , "No job was created for the main branch" );
79+ assertEquals (expectedBranchProjectName , branchProject .getDisplayName (), "The job name doesn't match the naming strategy" );
80+
7081 final FreeStyleProject crProject = jenkinsInstance .getItemByFullName (
7182 String .format ("%s/%s" , projectName , crName ),
7283 FreeStyleProject .class
7384 );
7485
75- final String expectedName = namingStrategy .generateName (crName , crTitle );
86+ final String expectedCrProjectName = namingStrategy .generateName (crName , crTitle );
7687 assertNotNull (crProject , "No job was created for the pull request" );
77- assertEquals (expectedName , crProject .getDisplayName (), "The job name doesn't match the naming strategy" );
88+ assertEquals (expectedCrProjectName , crProject .getDisplayName (), "The job name doesn't match the naming strategy" );
7889 }
7990 }
8091}
0 commit comments