Skip to content

Commit cd9a9d5

Browse files
Migrate tests to JUnit5 (#596)
Co-authored-by: strangelookingnerd <[email protected]>
1 parent 946ff4a commit cd9a9d5

9 files changed

+125
-166
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>5.5</version>
7+
<version>5.7</version>
88
<relativePath />
99
</parent>
1010

@@ -46,7 +46,7 @@
4646
<!-- Pick up common dependencies for the selected LTS line: https://github.com/jenkinsci/bom#usage -->
4747
<groupId>io.jenkins.tools.bom</groupId>
4848
<artifactId>bom-${jenkins.baseline}.x</artifactId>
49-
<version>3559.vb_5b_81183b_d23</version>
49+
<version>4136.vca_c3202a_7fd1</version>
5050
<type>pom</type>
5151
<scope>import</scope>
5252
</dependency>

src/test/java/io/jenkins/plugins/pipelinegraphview/PipelineGraphViewRebuildTest.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
package io.jenkins.plugins.pipelinegraphview;
22

3-
import static org.junit.Assert.assertEquals;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
44

55
import hudson.model.Result;
66
import io.jenkins.plugins.pipelinegraphview.utils.TestUtils;
77
import org.htmlunit.html.HtmlPage;
88
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
9-
import org.junit.Rule;
10-
import org.junit.Test;
9+
import org.junit.jupiter.api.Test;
1110
import org.jvnet.hudson.test.Issue;
1211
import org.jvnet.hudson.test.JenkinsRule;
12+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
1313

14-
public class PipelineGraphViewRebuildTest {
15-
@Rule
16-
public JenkinsRule j = new JenkinsRule();
14+
@WithJenkins
15+
class PipelineGraphViewRebuildTest {
1716

1817
@Issue("GH#330")
1918
@Test
20-
public void rebuildButtonStartsNewBuild() throws Exception {
19+
void rebuildButtonStartsNewBuild(JenkinsRule j) throws Exception {
2120
WorkflowRun run =
2221
TestUtils.createAndRunJob(j, "hello_world", "helloWorldScriptedPipeline.jenkinsfile", Result.SUCCESS);
2322

@@ -30,7 +29,7 @@ public void rebuildButtonStartsNewBuild() throws Exception {
3029

3130
@Issue("GH#330")
3231
@Test
33-
public void rebuildButtonRedirectsForParameterizedJob() throws Exception {
32+
void rebuildButtonRedirectsForParameterizedJob(JenkinsRule j) throws Exception {
3433
WorkflowRun run = TestUtils.createAndRunJob(
3534
j, "echo_parameterized", "gh330_parameterizedBuild.jenkinsfile", Result.SUCCESS);
3635

src/test/java/io/jenkins/plugins/pipelinegraphview/consoleview/PipelineConsoleViewActionTest.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@
1111
import java.util.List;
1212
import net.sf.json.JSONObject;
1313
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
14-
import org.junit.Rule;
15-
import org.junit.Test;
14+
import org.junit.jupiter.api.Test;
1615
import org.jvnet.hudson.test.Issue;
1716
import org.jvnet.hudson.test.JenkinsRule;
17+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
1818

19-
public class PipelineConsoleViewActionTest {
20-
@Rule
21-
public JenkinsRule j = new JenkinsRule();
19+
@WithJenkins
20+
class PipelineConsoleViewActionTest {
2221

2322
private static final String TEXT = "Hello, World!" + System.lineSeparator();
2423

2524
@Issue("GH#224")
2625
@Test
27-
public void getConsoleLogReturnLogText() throws Exception {
26+
void getConsoleLogReturnLogText(JenkinsRule j) throws Exception {
2827
WorkflowRun run = TestUtils.createAndRunJob(
2928
j, "hello_world_scripted", "helloWorldScriptedPipeline.jenkinsfile", Result.SUCCESS);
3029

@@ -43,7 +42,7 @@ public void getConsoleLogReturnLogText() throws Exception {
4342

4443
@Issue("GH#224")
4544
@Test
46-
public void getConsoleLogReturnsErrorText() throws Exception {
45+
void getConsoleLogReturnsErrorText(JenkinsRule j) throws Exception {
4746
WorkflowRun run =
4847
TestUtils.createAndRunJob(j, "hello_world_scripted", "simpleError.jenkinsfile", Result.FAILURE);
4948

@@ -61,7 +60,7 @@ public void getConsoleLogReturnsErrorText() throws Exception {
6160

6261
@Issue("GH#224")
6362
@Test
64-
public void getConsoleLogReturnLogTextWithOffset() throws Exception {
63+
void getConsoleLogReturnLogTextWithOffset(JenkinsRule j) throws Exception {
6564
WorkflowRun run = TestUtils.createAndRunJob(
6665
j, "hello_world_scripted", "helloWorldScriptedPipeline.jenkinsfile", Result.SUCCESS);
6766

@@ -80,7 +79,7 @@ public void getConsoleLogReturnLogTextWithOffset() throws Exception {
8079

8180
@Issue("GH#224")
8281
@Test
83-
public void getConsoleLogReturnLogTextWithNegativeOffset() throws Exception {
82+
void getConsoleLogReturnLogTextWithNegativeOffset(JenkinsRule j) throws Exception {
8483
WorkflowRun run = TestUtils.createAndRunJob(
8584
j, "hello_world_scripted", "helloWorldScriptedPipeline.jenkinsfile", Result.SUCCESS);
8685

@@ -101,7 +100,7 @@ public void getConsoleLogReturnLogTextWithNegativeOffset() throws Exception {
101100

102101
@Issue("GH#224")
103102
@Test
104-
public void getConsoleLogReturnLogTextWithLargeNegativeOffset() throws Exception {
103+
void getConsoleLogReturnLogTextWithLargeNegativeOffset(JenkinsRule j) throws Exception {
105104
WorkflowRun run = TestUtils.createAndRunJob(
106105
j, "hello_world_scripted", "helloWorldScriptedPipeline.jenkinsfile", Result.SUCCESS);
107106

@@ -120,7 +119,7 @@ public void getConsoleLogReturnLogTextWithLargeNegativeOffset() throws Exception
120119

121120
@Issue("GH#224")
122121
@Test
123-
public void getConsoleLogReturnLogTextWithLargeOffset() throws Exception {
122+
void getConsoleLogReturnLogTextWithLargeOffset(JenkinsRule j) throws Exception {
124123
WorkflowRun run = TestUtils.createAndRunJob(
125124
j, "hello_world_scripted", "helloWorldScriptedPipeline.jenkinsfile", Result.SUCCESS);
126125

@@ -137,7 +136,7 @@ public void getConsoleLogReturnLogTextWithLargeOffset() throws Exception {
137136

138137
@Issue("GH#224")
139138
@Test
140-
public void getConsoleLogOfStepWithOutputAndException() throws Exception {
139+
void getConsoleLogOfStepWithOutputAndException(JenkinsRule j) throws Exception {
141140
WorkflowRun run =
142141
TestUtils.createAndRunJob(j, "exec_returns_error", "execStepReturnsError.jenkinsfile", Result.FAILURE);
143142
PipelineNodeGraphAdapter builder = new PipelineNodeGraphAdapter(run);

src/test/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineGraphApiLegacyTest.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@
66
import hudson.model.Result;
77
import java.util.List;
88
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
9-
import org.junit.Rule;
10-
import org.junit.Test;
9+
import org.junit.jupiter.api.Test;
1110
import org.jvnet.hudson.test.Issue;
1211
import org.jvnet.hudson.test.JenkinsRule;
12+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
1313

14-
public class PipelineGraphApiLegacyTest {
15-
16-
@Rule
17-
public JenkinsRule j = new JenkinsRule();
14+
@WithJenkins
15+
class PipelineGraphApiLegacyTest {
1816

1917
@Test
20-
public void createLegacyTree_unstableSmokes() throws Exception {
18+
void createLegacyTree_unstableSmokes(JenkinsRule j) throws Exception {
2119
WorkflowRun run = TestUtils.createAndRunJob(j, "unstableSmokes", "unstableSmokes.jenkinsfile", Result.FAILURE);
2220
PipelineGraphApi api = new PipelineGraphApi(run);
2321
PipelineGraph graph = api.createLegacyTree();
@@ -56,7 +54,7 @@ public void createLegacyTree_unstableSmokes() throws Exception {
5654
}
5755

5856
@Test
59-
public void createLegacyTree_complexSmokes() throws Exception {
57+
void createLegacyTree_complexSmokes(JenkinsRule j) throws Exception {
6058
WorkflowRun run = TestUtils.createAndRunJob(j, "complexSmokes", "complexSmokes.jenkinsfile", Result.SUCCESS);
6159
PipelineGraphApi api = new PipelineGraphApi(run);
6260
PipelineGraph graph = api.createLegacyTree();
@@ -82,7 +80,7 @@ public void createLegacyTree_complexSmokes() throws Exception {
8280
}
8381

8482
@Test
85-
public void createLegacyTree_scriptedParallel() throws Exception {
83+
void createLegacyTree_scriptedParallel(JenkinsRule j) throws Exception {
8684
WorkflowRun run =
8785
TestUtils.createAndRunJob(j, "scriptedParallel", "scriptedParallel.jenkinsfile", Result.SUCCESS);
8886
PipelineGraphApi api = new PipelineGraphApi(run);
@@ -102,7 +100,7 @@ public void createLegacyTree_scriptedParallel() throws Exception {
102100

103101
@Issue("GH#85")
104102
@Test
105-
public void createLegacyTree_syntheticStages() throws Exception {
103+
void createLegacyTree_syntheticStages(JenkinsRule j) throws Exception {
106104
WorkflowRun run =
107105
TestUtils.createAndRunJob(j, "syntheticStages", "syntheticStages.jenkinsfile", Result.SUCCESS);
108106
PipelineGraphApi api = new PipelineGraphApi(run);
@@ -131,7 +129,7 @@ public void createLegacyTree_syntheticStages() throws Exception {
131129

132130
@Issue("GH#87")
133131
@Test
134-
public void createLegacyTree_skippedParallel() throws Exception {
132+
void createLegacyTree_skippedParallel(JenkinsRule j) throws Exception {
135133
WorkflowRun run =
136134
TestUtils.createAndRunJob(j, "skippedParallel", "skippedParallel.jenkinsfile", Result.SUCCESS);
137135
PipelineGraphApi api = new PipelineGraphApi(run);

0 commit comments

Comments
 (0)