Skip to content

Commit b6eef6c

Browse files
authored
Merge pull request #634 from strangelookingnerd/migrate_to_junit5
2 parents 80a9999 + bffdb1d commit b6eef6c

File tree

49 files changed

+616
-648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+616
-648
lines changed

pom.xml

+6-1
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.6</version>
7+
<version>5.7</version>
88
<relativePath />
99
</parent>
1010

@@ -328,6 +328,11 @@
328328
<artifactId>mockito-core</artifactId>
329329
<scope>test</scope>
330330
</dependency>
331+
<dependency>
332+
<groupId>org.mockito</groupId>
333+
<artifactId>mockito-junit-jupiter</artifactId>
334+
<scope>test</scope>
335+
</dependency>
331336
</dependencies>
332337

333338
<repositories>

src/test/java/com/atlassian/httpclient/apache/httpcomponents/ApacheAsyncHttpClientTest.java

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.atlassian.httpclient.apache.httpcomponents;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
35
import com.atlassian.httpclient.api.Response;
46
import com.atlassian.httpclient.api.factory.HttpClientOptions;
57
import com.atlassian.sal.api.ApplicationProperties;
@@ -28,17 +30,14 @@
2830
import org.eclipse.jetty.server.Server;
2931
import org.eclipse.jetty.server.ServerConnector;
3032
import org.eclipse.jetty.util.Callback;
31-
import org.junit.After;
32-
import org.junit.Assert;
33-
import org.junit.Rule;
34-
import org.junit.Test;
33+
import org.junit.jupiter.api.AfterEach;
34+
import org.junit.jupiter.api.Test;
3535
import org.jvnet.hudson.test.JenkinsRule;
36+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
3637

38+
@WithJenkins
3739
public class ApacheAsyncHttpClientTest {
3840

39-
@Rule
40-
public JenkinsRule j = new JenkinsRule();
41-
4241
private final ConnectionFactory connectionFactory = new HttpConnectionFactory();
4342

4443
private Server server;
@@ -55,15 +54,15 @@ public void prepare(Handler handler) throws Exception {
5554
server.start();
5655
}
5756

58-
@After
59-
public void dispose() throws Exception {
57+
@AfterEach
58+
void dispose() throws Exception {
6059
if (server != null) {
6160
server.stop();
6261
}
6362
}
6463

6564
@Test
66-
public void simple_get() throws Exception {
65+
void simple_get(JenkinsRule r) throws Exception {
6766
TestHandler testHandler = new TestHandler();
6867
prepare(testHandler);
6968

@@ -74,12 +73,12 @@ public void simple_get() throws Exception {
7473
.newRequest("http://localhost:" + connector.getLocalPort() + "/foo")
7574
.get()
7675
.get(10, TimeUnit.SECONDS);
77-
Assert.assertEquals(200, response.getStatusCode());
78-
Assert.assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
76+
assertEquals(200, response.getStatusCode());
77+
assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
7978
}
8079

8180
@Test
82-
public void simple_post() throws Exception {
81+
void simple_post(JenkinsRule r) throws Exception {
8382
TestHandler testHandler = new TestHandler();
8483
prepare(testHandler);
8584

@@ -92,13 +91,13 @@ public void simple_post() throws Exception {
9291
.setContentType("text")
9392
.post()
9493
.get(10, TimeUnit.SECONDS);
95-
Assert.assertEquals(200, response.getStatusCode());
96-
Assert.assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
97-
Assert.assertEquals("FOO", testHandler.postReceived);
94+
assertEquals(200, response.getStatusCode());
95+
assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
96+
assertEquals("FOO", testHandler.postReceived);
9897
}
9998

10099
@Test
101-
public void simple_get_with_non_proxy_host() throws Exception {
100+
void simple_get_with_non_proxy_host(JenkinsRule r) throws Exception {
102101
ProxyTestHandler testHandler = new ProxyTestHandler();
103102
prepare(testHandler);
104103

@@ -109,12 +108,12 @@ public void simple_get_with_non_proxy_host() throws Exception {
109108
null, buildApplicationProperties(), new NoOpThreadLocalContextManager(), new HttpClientOptions());
110109

111110
Response response = httpClient.newRequest("http://www.apache.org").get().get(30, TimeUnit.SECONDS);
112-
Assert.assertEquals(200, response.getStatusCode());
113-
// Assert.assertEquals( CONTENT_RESPONSE, IOUtils.toString( response.getEntityStream() ) );
111+
assertEquals(200, response.getStatusCode());
112+
// assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
114113
}
115114

116115
@Test
117-
public void simple_get_with_proxy() throws Exception {
116+
void simple_get_with_proxy(JenkinsRule r) throws Exception {
118117
ProxyTestHandler testHandler = new ProxyTestHandler();
119118
prepare(testHandler);
120119

@@ -124,12 +123,12 @@ public void simple_get_with_proxy() throws Exception {
124123
null, buildApplicationProperties(), new NoOpThreadLocalContextManager(), new HttpClientOptions());
125124

126125
Response response = httpClient.newRequest("http://jenkins.io").get().get(30, TimeUnit.SECONDS);
127-
Assert.assertEquals(200, response.getStatusCode());
128-
Assert.assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
126+
assertEquals(200, response.getStatusCode());
127+
assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
129128
}
130129

131130
@Test
132-
public void simple_post_with_proxy() throws Exception {
131+
void simple_post_with_proxy(JenkinsRule r) throws Exception {
133132
ProxyTestHandler testHandler = new ProxyTestHandler();
134133
prepare(testHandler);
135134

@@ -145,9 +144,9 @@ public void simple_post_with_proxy() throws Exception {
145144
.post()
146145
.get(30, TimeUnit.SECONDS);
147146
// we are sure to hit the proxy first :-)
148-
Assert.assertEquals(200, response.getStatusCode());
149-
Assert.assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
150-
Assert.assertEquals("FOO", testHandler.postReceived);
147+
assertEquals(200, response.getStatusCode());
148+
assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
149+
assertEquals("FOO", testHandler.postReceived);
151150
}
152151

153152
public static class ProxyTestHandler extends Handler.Abstract {

src/test/java/com/atlassian/httpclient/apache/httpcomponents/CompletableFuturePromiseHttpPromiseAsyncClientTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
import org.apache.http.concurrent.FutureCallback;
1616
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
1717
import org.apache.http.protocol.HttpContext;
18-
import org.junit.Test;
19-
import org.junit.runner.RunWith;
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.extension.ExtendWith;
2020
import org.mockito.InjectMocks;
2121
import org.mockito.Mock;
22-
import org.mockito.junit.MockitoJUnitRunner;
22+
import org.mockito.junit.jupiter.MockitoExtension;
2323
import org.mockito.stubbing.Answer;
2424

25-
@RunWith(MockitoJUnitRunner.class)
26-
public class CompletableFuturePromiseHttpPromiseAsyncClientTest {
25+
@ExtendWith(MockitoExtension.class)
26+
class CompletableFuturePromiseHttpPromiseAsyncClientTest {
2727

2828
@Mock
2929
private CloseableHttpAsyncClient client;
@@ -47,7 +47,7 @@ public class CompletableFuturePromiseHttpPromiseAsyncClientTest {
4747
private CompletableFuturePromiseHttpPromiseAsyncClient<Object> asyncClient;
4848

4949
@Test
50-
public void ensureCloseHttpclientOnCompletion() throws IOException {
50+
void ensureCloseHttpclientOnCompletion() throws IOException {
5151
when(client.execute(eq(request), eq(context), any())).then((Answer<Future<HttpResponse>>) invocation -> {
5252
invocation.getArgument(2, FutureCallback.class).completed(response);
5353
return mock(Future.class);
@@ -59,7 +59,7 @@ public void ensureCloseHttpclientOnCompletion() throws IOException {
5959
}
6060

6161
@Test
62-
public void ensureCloseHttpclientOnFailure() throws IOException {
62+
void ensureCloseHttpclientOnFailure() throws IOException {
6363
when(client.execute(eq(request), eq(context), any())).then((Answer<Future<HttpResponse>>) invocation -> {
6464
invocation.getArgument(2, FutureCallback.class).failed(null);
6565
return mock(Future.class);
@@ -71,7 +71,7 @@ public void ensureCloseHttpclientOnFailure() throws IOException {
7171
}
7272

7373
@Test
74-
public void ensureCloseHttpclientOnCancellation() throws IOException {
74+
void ensureCloseHttpclientOnCancellation() throws IOException {
7575
when(client.execute(eq(request), eq(context), any())).then((Answer<Future<HttpResponse>>) invocation -> {
7676
invocation.getArgument(2, FutureCallback.class).cancelled();
7777
return mock(Future.class);

src/test/java/hudson/plugins/jira/ChangingWorkflowTest.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@
2525
import java.util.Arrays;
2626
import java.util.Collections;
2727
import java.util.concurrent.TimeoutException;
28-
import org.junit.Before;
29-
import org.junit.Test;
30-
import org.junit.runner.RunWith;
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.Test;
30+
import org.junit.jupiter.api.extension.ExtendWith;
3131
import org.mockito.Mock;
32-
import org.mockito.junit.MockitoJUnitRunner;
32+
import org.mockito.junit.jupiter.MockitoExtension;
3333

3434
/**
3535
* User: lanwen
3636
* Date: 10.09.13
3737
* Time: 0:57
3838
*/
39-
@RunWith(MockitoJUnitRunner.class)
39+
@ExtendWith(MockitoExtension.class)
4040
public class ChangingWorkflowTest {
4141

4242
public static final String NON_EMPTY_COMMENT = "Non empty comment";
@@ -57,25 +57,25 @@ public class ChangingWorkflowTest {
5757

5858
private JiraSession spySession;
5959

60-
@Before
61-
public void setupSpy() {
60+
@BeforeEach
61+
void setupSpy() {
6262
spySession = spy(new JiraSession(site, restService));
6363
}
6464

6565
@Test
66-
public void onGetActionItInvokesServiceMethod() {
66+
void onGetActionItInvokesServiceMethod() {
6767
spySession.getActionIdForIssue(ISSUE_JQL, NON_EMPTY_WORKFLOW_LOWERCASE);
6868
verify(restService, times(1)).getAvailableActions(eq(ISSUE_JQL));
6969
}
7070

7171
@Test
72-
public void getActionIdReturnsNullWhenServiceReturnsNull() {
72+
void getActionIdReturnsNullWhenServiceReturnsNull() {
7373
doReturn(null).when(restService).getAvailableActions(ISSUE_JQL);
7474
assertThat(spySession.getActionIdForIssue(ISSUE_JQL, NON_EMPTY_WORKFLOW_LOWERCASE), nullValue());
7575
}
7676

7777
@Test
78-
public void getActionIdIteratesOverAllActionsEvenOneOfNamesIsNull() {
78+
void getActionIdIteratesOverAllActionsEvenOneOfNamesIsNull() {
7979
Transition action1 = mock(Transition.class);
8080
Transition action2 = mock(Transition.class);
8181

@@ -90,7 +90,7 @@ public void getActionIdIteratesOverAllActionsEvenOneOfNamesIsNull() {
9090
}
9191

9292
@Test
93-
public void getActionIdReturnsNullWhenNullWorkflowUsed() {
93+
void getActionIdReturnsNullWhenNullWorkflowUsed() {
9494
String workflowAction = null;
9595
Transition action1 = mock(Transition.class);
9696
when(action1.getName()).thenReturn("name");
@@ -100,7 +100,7 @@ public void getActionIdReturnsNullWhenNullWorkflowUsed() {
100100
}
101101

102102
@Test
103-
public void getActionIdReturnsIdWhenFoundIgnorecaseWorkflow() {
103+
void getActionIdReturnsIdWhenFoundIgnorecaseWorkflow() {
104104
String id = randomNumeric(5);
105105
Transition action1 = mock(Transition.class);
106106
when(action1.getName()).thenReturn(NON_EMPTY_WORKFLOW_LOWERCASE.toUpperCase());
@@ -112,7 +112,7 @@ public void getActionIdReturnsIdWhenFoundIgnorecaseWorkflow() {
112112
}
113113

114114
@Test
115-
public void addCommentsOnNonEmptyWorkflowAndNonEmptyComment() throws Exception {
115+
void addCommentsOnNonEmptyWorkflowAndNonEmptyComment() throws Exception {
116116
when(site.getSession(any(), anyBoolean())).thenCallRealMethod();
117117
when(site.getSession(any())).thenCallRealMethod();
118118
when(site.createSession(any(), anyBoolean())).thenReturn(mockSession);
@@ -130,7 +130,7 @@ public void addCommentsOnNonEmptyWorkflowAndNonEmptyComment() throws Exception {
130130
}
131131

132132
@Test
133-
public void addCommentsOnNullWorkflowAndNonEmptyComment() throws Exception {
133+
void addCommentsOnNullWorkflowAndNonEmptyComment() throws Exception {
134134
when(site.getSession(any())).thenCallRealMethod();
135135
when(site.getSession(any(), anyBoolean())).thenCallRealMethod();
136136
when(site.createSession(any(), anyBoolean())).thenReturn(mockSession);
@@ -146,7 +146,7 @@ public void addCommentsOnNullWorkflowAndNonEmptyComment() throws Exception {
146146
}
147147

148148
@Test
149-
public void dontAddCommentsOnNullWorkflowAndNullComment() throws TimeoutException {
149+
void dontAddCommentsOnNullWorkflowAndNullComment() throws TimeoutException {
150150
site.progressMatchingIssues(ISSUE_JQL, null, null, mock(PrintStream.class));
151151
verify(mockSession, never()).addComment(anyString(), anyString(), isNull(), isNull());
152152
}

src/test/java/hudson/plugins/jira/CliParameterTest.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@
1010
import hudson.plugins.jira.listissuesparameter.JiraIssueParameterDefinition;
1111
import hudson.plugins.jira.versionparameter.JiraVersionParameterDefinition;
1212
import java.io.IOException;
13-
import org.junit.Before;
14-
import org.junit.Rule;
15-
import org.junit.Test;
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
1615
import org.jvnet.hudson.test.JenkinsRule;
16+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
1717

18-
public class CliParameterTest {
18+
@WithJenkins
19+
class CliParameterTest {
1920

20-
@Rule
21-
public JenkinsRule jenkins = new JenkinsRule();
21+
private JenkinsRule jenkins;
2222

2323
FreeStyleProject project;
2424

25-
@Before
26-
public void setup() throws IOException {
25+
@BeforeEach
26+
void setup(JenkinsRule jenkins) throws IOException {
27+
this.jenkins = jenkins;
2728
project = jenkins.createFreeStyleProject();
2829
}
2930

3031
@Test
31-
public void jiraIssueParameterViaCli() throws Exception {
32+
void jiraIssueParameterViaCli() throws Exception {
3233
project.addProperty(new ParametersDefinitionProperty(
3334
new JiraIssueParameterDefinition("jiraissue", "description", "filter")));
3435

@@ -38,7 +39,7 @@ public void jiraIssueParameterViaCli() throws Exception {
3839
}
3940

4041
@Test
41-
public void jiraVersionParameterViaCli() throws Exception {
42+
void jiraVersionParameterViaCli() throws Exception {
4243
project.addProperty(new ParametersDefinitionProperty(
4344
new JiraVersionParameterDefinition("jiraversion", "description", "PROJ", "RELEASE", "true", "false")));
4445

src/test/java/hudson/plugins/jira/ConfigAsCodeTest.java

+10-13
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,40 @@
33
import static org.hamcrest.MatcherAssert.assertThat;
44
import static org.hamcrest.Matchers.hasSize;
55
import static org.hamcrest.Matchers.is;
6-
import static org.junit.Assert.assertNotNull;
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertNotNull;
78

89
import io.jenkins.plugins.casc.ConfigurationContext;
910
import io.jenkins.plugins.casc.Configurator;
1011
import io.jenkins.plugins.casc.ConfiguratorRegistry;
1112
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
1213
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
14+
import io.jenkins.plugins.casc.misc.junit.jupiter.WithJenkinsConfiguredWithCode;
1315
import io.jenkins.plugins.casc.model.CNode;
1416
import io.jenkins.plugins.casc.model.Mapping;
1517
import java.util.List;
1618
import java.util.Objects;
17-
import org.junit.Assert;
18-
import org.junit.Rule;
19-
import org.junit.Test;
20-
import org.jvnet.hudson.test.JenkinsRule;
19+
import org.junit.jupiter.api.Test;
2120

22-
public class ConfigAsCodeTest {
23-
24-
@Rule
25-
public JenkinsRule r = new JenkinsConfiguredWithCodeRule();
21+
@WithJenkinsConfiguredWithCode
22+
class ConfigAsCodeTest {
2623

2724
@Test
2825
@ConfiguredWithCode("multiple-sites.yml")
29-
public void shouldSupportConfigurationAsCode() throws Exception {
26+
void shouldSupportConfigurationAsCode(JenkinsConfiguredWithCodeRule r) throws Exception {
3027
List<JiraSite> sites = JiraGlobalConfiguration.get().getSites();
3128
assertThat(sites, hasSize(2));
32-
Assert.assertEquals(
29+
assertEquals(
3330
"https://issues.jenkins-ci.org/",
3431
Objects.requireNonNull(sites.get(0).getUrl()).toExternalForm());
35-
Assert.assertEquals(
32+
assertEquals(
3633
"https://jira.com/",
3734
Objects.requireNonNull(sites.get(1).getUrl()).toExternalForm());
3835
}
3936

4037
@Test
4138
@ConfiguredWithCode("single-site.yml")
42-
public void shouldExportConfigurationAsCode() throws Exception {
39+
void shouldExportConfigurationAsCode(JenkinsConfiguredWithCodeRule r) throws Exception {
4340
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
4441
ConfigurationContext context = new ConfigurationContext(registry);
4542
final Configurator c = context.lookupOrFail(JiraGlobalConfiguration.class);

0 commit comments

Comments
 (0)