Skip to content

Commit e53c08b

Browse files
Migrate tests to JUnit5
* Migrate annotations and imports * Migrate assertions * Remove public visibility for test classes and methods * Minor code cleanup
1 parent 1044884 commit e53c08b

33 files changed

+956
-779
lines changed

pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@
111111
<artifactId>mockito-core</artifactId>
112112
<scope>test</scope>
113113
</dependency>
114-
<dependency>
115-
<groupId>pl.pragmatists</groupId>
116-
<artifactId>JUnitParams</artifactId>
117-
<version>1.1.1</version>
118-
<scope>test</scope>
119-
</dependency>
120114
<dependency>
121115
<groupId>org.jenkins-ci.plugins</groupId>
122116
<artifactId>scm-api</artifactId>
@@ -139,11 +133,6 @@
139133
<classifier>tests</classifier>
140134
<scope>test</scope>
141135
</dependency>
142-
<dependency>
143-
<groupId>org.jenkins-ci.plugins</groupId>
144-
<artifactId>junit</artifactId>
145-
<scope>test</scope>
146-
</dependency>
147136
</dependencies>
148137

149138
<repositories>

src/test/java/integration/BrandingTest.java

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
package integration;
2727

28-
import org.htmlunit.html.HtmlAnchor;
29-
import org.htmlunit.html.HtmlPage;
3028
import edu.umd.cs.findbugs.annotations.NonNull;
3129
import hudson.Extension;
3230
import hudson.model.Action;
@@ -42,11 +40,6 @@
4240
import hudson.views.WeatherColumn;
4341
import integration.harness.BasicMultiBranchProject;
4442
import integration.harness.BasicMultiBranchProjectFactory;
45-
import java.io.IOException;
46-
import java.util.ArrayList;
47-
import java.util.Arrays;
48-
import java.util.Collections;
49-
import java.util.List;
5043
import jenkins.branch.Branch;
5144
import jenkins.branch.BranchIndexingCause;
5245
import jenkins.branch.BranchSource;
@@ -65,11 +58,20 @@
6558
import jenkins.scm.impl.mock.MockSCMNavigator;
6659
import jenkins.scm.impl.mock.MockSCMSource;
6760
import jenkins.scm.impl.mock.MockSCMSourceEvent;
68-
import org.junit.Before;
69-
import org.junit.ClassRule;
70-
import org.junit.Test;
61+
import org.htmlunit.html.HtmlAnchor;
62+
import org.htmlunit.html.HtmlPage;
63+
import org.junit.jupiter.api.BeforeAll;
64+
import org.junit.jupiter.api.BeforeEach;
65+
import org.junit.jupiter.api.Test;
7166
import org.jvnet.hudson.test.Issue;
7267
import org.jvnet.hudson.test.JenkinsRule;
68+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
69+
70+
import java.io.IOException;
71+
import java.util.ArrayList;
72+
import java.util.Arrays;
73+
import java.util.Collections;
74+
import java.util.List;
7375

7476
import static org.hamcrest.MatcherAssert.assertThat;
7577
import static org.hamcrest.Matchers.allOf;
@@ -82,24 +84,29 @@
8284
import static org.hamcrest.Matchers.notNullValue;
8385
import static org.hamcrest.Matchers.nullValue;
8486

85-
public class BrandingTest {
87+
@WithJenkins
88+
class BrandingTest {
8689

8790
/**
8891
* All tests in this class only create items and do not affect other global configuration, thus we trade test
8992
* execution time for the restriction on only touching items.
9093
*/
91-
@ClassRule
92-
public static JenkinsRule r = new JenkinsRule();
94+
private static JenkinsRule r;
95+
96+
@BeforeAll
97+
static void setUp(JenkinsRule rule) {
98+
r = rule;
99+
}
93100

94-
@Before
95-
public void cleanOutAllItems() throws Exception {
101+
@BeforeEach
102+
void setUp() throws Exception {
96103
for (TopLevelItem i : r.getInstance().getItems()) {
97104
i.delete();
98105
}
99106
}
100107

101108
@Test
102-
public void given_multibranch_when_noSourcesDefined_then_noSourceBrandingPresent() throws Exception {
109+
void given_multibranch_when_noSourcesDefined_then_noSourceBrandingPresent() throws Exception {
103110
try (MockSCMController c = MockSCMController.create()) {
104111
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
105112
prj.setCriteria(null);
@@ -108,7 +115,7 @@ public void given_multibranch_when_noSourcesDefined_then_noSourceBrandingPresent
108115
}
109116

110117
@Test
111-
public void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfterIndexing()
118+
void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfterIndexing()
112119
throws Exception {
113120
try (MockSCMController c = MockSCMController.create()) {
114121
c.createRepository("foo");
@@ -123,7 +130,7 @@ public void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfter
123130
}
124131

125132
@Test
126-
public void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfterSourceEvent()
133+
void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfterSourceEvent()
127134
throws Exception {
128135
try (MockSCMController c = MockSCMController.create()) {
129136
c.createRepository("foo");
@@ -138,7 +145,7 @@ public void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfter
138145
}
139146

140147
@Test
141-
public void given_multibranch_when_branches_then_branchBrandingPresent()
148+
void given_multibranch_when_branches_then_branchBrandingPresent()
142149
throws Exception {
143150
try (MockSCMController c = MockSCMController.create()) {
144151
c.createRepository("foo");
@@ -152,7 +159,7 @@ public void given_multibranch_when_branches_then_branchBrandingPresent()
152159
}
153160

154161
@Test
155-
public void given_multibranch_when_branches_then_runBrandingPresent()
162+
void given_multibranch_when_branches_then_runBrandingPresent()
156163
throws Exception {
157164
try (MockSCMController c = MockSCMController.create()) {
158165
c.createRepository("foo");
@@ -169,7 +176,7 @@ public void given_multibranch_when_branches_then_runBrandingPresent()
169176

170177
@Test
171178
@Issue("JENKINS-48090")
172-
public void given_multibranch_when_runBrandingIncludesAdditionalCauses_then_causesMerged() throws Exception {
179+
void given_multibranch_when_runBrandingIncludesAdditionalCauses_then_causesMerged() throws Exception {
173180
try (MockSCMController c = MockSCMController.create()) {
174181
c.createRepository("foo");
175182
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
@@ -188,15 +195,15 @@ public void given_multibranch_when_runBrandingIncludesAdditionalCauses_then_caus
188195
}
189196

190197
@Test
191-
public void given_orgFolder_when_noNavigatorsDefined_then_noNavigatorBrandingPresent() throws Exception {
198+
void given_orgFolder_when_noNavigatorsDefined_then_noNavigatorBrandingPresent() throws Exception {
192199
try (MockSCMController c = MockSCMController.create()) {
193200
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
194201
assertThat(prj.getAction(MockSCMLink.class), nullValue());
195202
}
196203
}
197204

198205
@Test
199-
public void given_multibranch_when_sourceHasNonSafeNames_then_branchDisplayNameNotMangled() throws Exception {
206+
void given_multibranch_when_sourceHasNonSafeNames_then_branchDisplayNameNotMangled() throws Exception {
200207
try (MockSCMController c = MockSCMController.create()) {
201208
c.createRepository("foo");
202209
c.createBranch("foo", ".");
@@ -258,7 +265,7 @@ public void given_multibranch_when_sourceHasNonSafeNames_then_branchDisplayNameN
258265
}
259266

260267
@Test
261-
public void given_multibranch_when_sourceHasI18nNames_then_branchDisplayNameNotMangled() throws Exception {
268+
void given_multibranch_when_sourceHasI18nNames_then_branchDisplayNameNotMangled() throws Exception {
262269
try (MockSCMController c = MockSCMController.create()) {
263270
c.createRepository("foo");
264271
c.createBranch("foo","特征/新");
@@ -347,7 +354,7 @@ public void given_multibranch_when_sourceHasI18nNames_then_branchDisplayNameNotM
347354
}
348355

349356
@Test
350-
public void given_orgFolder_when_navigatorDefined_then_navigatorBrandingPresentAfterIndexing()
357+
void given_orgFolder_when_navigatorDefined_then_navigatorBrandingPresentAfterIndexing()
351358
throws Exception {
352359
try (MockSCMController c = MockSCMController.create()) {
353360
c.createRepository("foo");
@@ -362,7 +369,7 @@ public void given_orgFolder_when_navigatorDefined_then_navigatorBrandingPresentA
362369
}
363370

364371
@Test
365-
public void given_orgFolderWithI18nRepos_when_indexing_then_repoNamesEncoded()
372+
void given_orgFolderWithI18nRepos_when_indexing_then_repoNamesEncoded()
366373
throws Exception {
367374
try (MockSCMController c = MockSCMController.create()) {
368375
c.createRepository("England");
@@ -437,7 +444,7 @@ public void given_orgFolderWithI18nRepos_when_indexing_then_repoNamesEncoded()
437444
}
438445

439446
@Test
440-
public void given_orgFolderWithNonSafeRepos_when_indexing_then_repoNamesEncoded()
447+
void given_orgFolderWithNonSafeRepos_when_indexing_then_repoNamesEncoded()
441448
throws Exception {
442449
try (MockSCMController c = MockSCMController.create()) {
443450
c.createRepository("a?");
@@ -482,7 +489,7 @@ public void given_orgFolderWithNonSafeRepos_when_indexing_then_repoNamesEncoded(
482489
}
483490

484491
@Test
485-
public void given_orgFolder_when_navigatorDefined_then_sourceBrandingPresentAfterIndexing()
492+
void given_orgFolder_when_navigatorDefined_then_sourceBrandingPresentAfterIndexing()
486493
throws Exception {
487494
try (MockSCMController c = MockSCMController.create()) {
488495
c.createRepository("foo");
@@ -497,7 +504,7 @@ public void given_orgFolder_when_navigatorDefined_then_sourceBrandingPresentAfte
497504
}
498505

499506
@Test
500-
public void given_orgFolder_when_navigatorDefined_then_branchBrandingPresentAfterIndexing()
507+
void given_orgFolder_when_navigatorDefined_then_branchBrandingPresentAfterIndexing()
501508
throws Exception {
502509
try (MockSCMController c = MockSCMController.create()) {
503510
c.createRepository("foo");
@@ -513,7 +520,7 @@ public void given_orgFolder_when_navigatorDefined_then_branchBrandingPresentAfte
513520
}
514521

515522
@Test
516-
public void given_orgFolder_when_navigatorDefined_then_revisionBrandingPresentAfterIndexing()
523+
void given_orgFolder_when_navigatorDefined_then_revisionBrandingPresentAfterIndexing()
517524
throws Exception {
518525
try (MockSCMController c = MockSCMController.create()) {
519526
c.createRepository("foo");
@@ -529,7 +536,7 @@ public void given_orgFolder_when_navigatorDefined_then_revisionBrandingPresentAf
529536
}
530537

531538
@Test
532-
public void given_multibranch_when_decoratedSourceDefined_then_descriptionPresentAfterIndexing()
539+
void given_multibranch_when_decoratedSourceDefined_then_descriptionPresentAfterIndexing()
533540
throws Exception {
534541
try (MockSCMController c = MockSCMController.create()) {
535542
c.createRepository("foo");
@@ -545,7 +552,7 @@ public void given_multibranch_when_decoratedSourceDefined_then_descriptionPresen
545552
}
546553

547554
@Test
548-
public void given_multibranch_when_decoratedSourceDefined_then_displayNamePresentAfterIndexing()
555+
void given_multibranch_when_decoratedSourceDefined_then_displayNamePresentAfterIndexing()
549556
throws Exception {
550557
try (MockSCMController c = MockSCMController.create()) {
551558
c.createRepository("foo");
@@ -564,7 +571,7 @@ public void given_multibranch_when_decoratedSourceDefined_then_displayNamePresen
564571
}
565572

566573
@Test
567-
public void given_orgFolder_when_decoratedSourceDefined_then_descriptionLinkPresentAfterIndexing()
574+
void given_orgFolder_when_decoratedSourceDefined_then_descriptionLinkPresentAfterIndexing()
568575
throws Exception {
569576
try (MockSCMController c = MockSCMController.create()) {
570577
c.createRepository("foo");
@@ -588,7 +595,7 @@ public void given_orgFolder_when_decoratedSourceDefined_then_descriptionLinkPres
588595
}
589596

590597
@Test
591-
public void given_multibranch_when_decoratedSourceDefined_then_folderIconPresentAfterIndexing()
598+
void given_multibranch_when_decoratedSourceDefined_then_folderIconPresentAfterIndexing()
592599
throws Exception {
593600
try (MockSCMController c = MockSCMController.create()) {
594601
c.createRepository("foo");
@@ -604,7 +611,7 @@ public void given_multibranch_when_decoratedSourceDefined_then_folderIconPresent
604611
}
605612

606613
@Test
607-
public void given_orgFolder_when_decoratedOrganizationDefined_then_folderIconPresentAfterIndexing()
614+
void given_orgFolder_when_decoratedOrganizationDefined_then_folderIconPresentAfterIndexing()
608615
throws Exception {
609616
try (MockSCMController c = MockSCMController.create()) {
610617
c.createRepository("foo");
@@ -620,7 +627,7 @@ public void given_orgFolder_when_decoratedOrganizationDefined_then_folderIconPre
620627
}
621628

622629
@Test
623-
public void given_orgFolder_when_decoratedOrganizationDefined_then_displayNamePresentAfterIndexing()
630+
void given_orgFolder_when_decoratedOrganizationDefined_then_displayNamePresentAfterIndexing()
624631
throws Exception {
625632
try (MockSCMController c = MockSCMController.create()) {
626633
c.createRepository("foo");
@@ -636,7 +643,7 @@ public void given_orgFolder_when_decoratedOrganizationDefined_then_displayNamePr
636643
}
637644

638645
@Test
639-
public void given_orgFolder_when_decoratedOrganizationDefined_then_descriptionLinkPresentAfterIndexing()
646+
void given_orgFolder_when_decoratedOrganizationDefined_then_descriptionLinkPresentAfterIndexing()
640647
throws Exception {
641648
try (MockSCMController c = MockSCMController.create()) {
642649
c.createRepository("foo");

src/test/java/integration/CategorizationTest.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
import jenkins.scm.impl.mock.MockSCMDiscoverChangeRequests;
4040
import jenkins.scm.impl.mock.MockSCMDiscoverTags;
4141
import jenkins.scm.impl.mock.MockSCMSource;
42-
import org.junit.Before;
43-
import org.junit.ClassRule;
44-
import org.junit.Test;
42+
import org.junit.jupiter.api.BeforeAll;
43+
import org.junit.jupiter.api.BeforeEach;
44+
import org.junit.jupiter.api.Test;
4545
import org.jvnet.hudson.test.JenkinsRule;
46+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
4647

4748
import static org.hamcrest.MatcherAssert.assertThat;
4849
import static org.hamcrest.Matchers.allOf;
@@ -54,24 +55,29 @@
5455
import static org.hamcrest.Matchers.instanceOf;
5556
import static org.hamcrest.Matchers.is;
5657

57-
public class CategorizationTest {
58+
@WithJenkins
59+
class CategorizationTest {
5860

5961
/**
6062
* All tests in this class only create items and do not affect other global configuration, thus we trade test
6163
* execution time for the restriction on only touching items.
6264
*/
63-
@ClassRule
64-
public static JenkinsRule r = new JenkinsRule();
65+
private static JenkinsRule r;
6566

66-
@Before
67-
public void cleanOutAllItems() throws Exception {
67+
@BeforeAll
68+
static void setUp(JenkinsRule rule) {
69+
r = rule;
70+
}
71+
72+
@BeforeEach
73+
void setUp() throws Exception {
6874
for (TopLevelItem i : r.getInstance().getItems()) {
6975
i.delete();
7076
}
7177
}
7278

7379
@Test
74-
public void given_multibranch_when_noSourcesDefined_then_welcomeViewPresent() throws Exception {
80+
void given_multibranch_when_noSourcesDefined_then_welcomeViewPresent() throws Exception {
7581
try (MockSCMController c = MockSCMController.create()) {
7682
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
7783
prj.setCriteria(null);
@@ -82,7 +88,7 @@ public void given_multibranch_when_noSourcesDefined_then_welcomeViewPresent() th
8288
}
8389

8490
@Test
85-
public void given_multibranch_when_atLeastOneSourceDefinedButNoItems_then_welcomeViewPresent()
91+
void given_multibranch_when_atLeastOneSourceDefinedButNoItems_then_welcomeViewPresent()
8692
throws Exception {
8793
try (MockSCMController c = MockSCMController.create()) {
8894
c.createRepository("foo");
@@ -96,7 +102,7 @@ public void given_multibranch_when_atLeastOneSourceDefinedButNoItems_then_welcom
96102
}
97103

98104
@Test
99-
public void given_multibranch_when_onlyUncategorizedCategory_then_onlyUncategorizedViewPresent() throws Exception {
105+
void given_multibranch_when_onlyUncategorizedCategory_then_onlyUncategorizedViewPresent() throws Exception {
100106
try (MockSCMController c = MockSCMController.create()) {
101107
c.createRepository("foo");
102108
c.createTag("foo", "master", "master-1.0");
@@ -122,7 +128,7 @@ public void given_multibranch_when_onlyUncategorizedCategory_then_onlyUncategori
122128
}
123129

124130
@Test
125-
public void given_multibranch_when_changeRequestsWanted_then_onlyUncategorizedAndChangeRequetsViewsPresent()
131+
void given_multibranch_when_changeRequestsWanted_then_onlyUncategorizedAndChangeRequetsViewsPresent()
126132
throws Exception {
127133
try (MockSCMController c = MockSCMController.create()) {
128134
c.createRepository("foo");
@@ -156,7 +162,7 @@ public void given_multibranch_when_changeRequestsWanted_then_onlyUncategorizedAn
156162
}
157163

158164
@Test
159-
public void given_multibranch_when_tagsWanted_then_onlyUncategorizedAndTagsViewsPresent()
165+
void given_multibranch_when_tagsWanted_then_onlyUncategorizedAndTagsViewsPresent()
160166
throws Exception {
161167
try (MockSCMController c = MockSCMController.create()) {
162168
c.createRepository("foo");
@@ -190,7 +196,7 @@ public void given_multibranch_when_tagsWanted_then_onlyUncategorizedAndTagsViews
190196
}
191197

192198
@Test
193-
public void given_multibranch_when_noBranchesWanted_then_uncategorizedViewPresentButEmpty()
199+
void given_multibranch_when_noBranchesWanted_then_uncategorizedViewPresentButEmpty()
194200
throws Exception {
195201
try (MockSCMController c = MockSCMController.create()) {
196202
c.createRepository("foo");
@@ -229,7 +235,7 @@ public void given_multibranch_when_noBranchesWanted_then_uncategorizedViewPresen
229235
}
230236

231237
@Test
232-
public void given_multibranch_when_wantsEverything_then_hasEverything()
238+
void given_multibranch_when_wantsEverything_then_hasEverything()
233239
throws Exception {
234240
try (MockSCMController c = MockSCMController.create()) {
235241
c.createRepository("foo");

0 commit comments

Comments
 (0)