Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit 6a7d9d0

Browse files
committed
Migrate junit4 -> junit5
1 parent c93f1d7 commit 6a7d9d0

11 files changed

+76
-77
lines changed

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@
6868
<version>${go.version}</version>
6969
<scope>provided</scope>
7070
</dependency>
71-
<dependency>
72-
<groupId>junit</groupId>
73-
<artifactId>junit</artifactId>
74-
<version>4.13.2</version>
75-
<scope>test</scope>
76-
</dependency>
7771
<dependency>
7872
<groupId>org.eclipse.jetty</groupId>
7973
<artifactId>jetty-server</artifactId>
@@ -86,6 +80,12 @@
8680
<version>9.4.53.v20231009</version>
8781
<scope>test</scope>
8882
</dependency>
83+
<dependency>
84+
<groupId>org.junit.jupiter</groupId>
85+
<artifactId>junit-jupiter</artifactId>
86+
<version>5.10.1</version>
87+
<scope>test</scope>
88+
</dependency>
8989
</dependencies>
9090

9191
<build>

src/test/java/com/ionos/go/plugin/notifier/CommonTestBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.ionos.go.plugin.notifier.util.Helper;
55
import com.thoughtworks.go.plugin.api.logging.Logger;
66
import lombok.Getter;
7-
import org.junit.Before;
7+
import org.junit.jupiter.api.BeforeEach;
88

99
import java.io.IOException;
1010
import java.util.Collections;
@@ -29,7 +29,7 @@ protected CommonTestBase() {
2929
logger = Logger.getLoggerFor(getClass());
3030
}
3131

32-
@Before
32+
@BeforeEach
3333
public void setupObjects() throws IOException {
3434
this.gson = new Gson();
3535
this.serverInfo = gson.fromJson(Helper.readResource("/serverInfo.json"), Map.class);

src/test/java/com/ionos/go/plugin/notifier/GoNotifierPluginBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.thoughtworks.go.plugin.api.response.GoApiResponse;
77
import lombok.Getter;
88
import org.apache.hc.core5.http.HttpStatus;
9-
import org.junit.Before;
9+
import org.junit.jupiter.api.BeforeEach;
1010

1111
import java.io.IOException;
1212
import java.util.Collections;
@@ -23,7 +23,7 @@ protected GoNotifierPluginBase() {
2323
logger = Logger.getLoggerFor(getClass());
2424
}
2525

26-
@Before
26+
@BeforeEach
2727
public void setupPlugin() {
2828
this.goNotifierPlugin = new GoNotifierPlugin();
2929
this.goNotifierPlugin.initializeGoApplicationAccessor(new GoApplicationAccessor() {

src/test/java/com/ionos/go/plugin/notifier/GoNotifierPluginStageStatusTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,51 @@
44
import com.ionos.go.plugin.notifier.util.Helper;
55
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
66
import org.apache.hc.core5.http.HttpStatus;
7-
import org.junit.AfterClass;
8-
import org.junit.Before;
9-
import org.junit.BeforeClass;
10-
import org.junit.Test;
7+
import org.junit.jupiter.api.AfterAll;
8+
import org.junit.jupiter.api.BeforeAll;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
1111

1212
import java.io.IOException;
1313
import java.util.Arrays;
1414
import java.util.Collections;
1515

16-
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertNotNull;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1818

1919

2020
public class GoNotifierPluginStageStatusTest extends GoNotifierPluginBase {
2121

2222
private static EmbeddedHttpServer embeddedHttpServer;
2323
private static int embeddedHttpPort;
2424

25-
@BeforeClass
25+
@BeforeAll
2626
public static void setUpLocalWebServer() {
2727
embeddedHttpServer = new EmbeddedHttpServer().withServlet(GoogleMockServlet.class, "/gchat");
2828
embeddedHttpServer.start();
2929
embeddedHttpPort = embeddedHttpServer.getRunningPort();
3030
}
3131

32-
@Before
32+
@BeforeEach
3333
public void setupConfig() {
3434
getPluginSettings().put(Constants.PARAM_WEBHOOK_URL, "http://localhost:" + embeddedHttpPort + "/gchat");
3535
getPluginSettings().put(Constants.PARAM_CONDITION, "true");
3636
getPluginSettings().put(Constants.PARAM_TEMPLATE, "${stageStatus.pipeline.group}");
3737
}
3838

39-
@Before
39+
@BeforeEach
4040
public void initServlet() {
4141
GoogleMockServlet.reset();
4242
GoogleMockServlet.setStatusToReturn(HttpStatus.SC_OK);
4343
}
4444

45-
@AfterClass
45+
@AfterAll
4646
public static void stopLocalWebServer() {
4747
embeddedHttpServer.stop();
4848
}
4949

5050
@Test
51-
public void testHandleStageStatusNoSendingConditionFalse() throws IOException {
51+
void testHandleStageStatusNoSendingConditionFalse() throws IOException {
5252
String stageStatusJson = Helper.readResource("/stageStatus.json");
5353
getPluginSettings().put(Constants.PARAM_CONDITION, "false");
5454

@@ -66,7 +66,7 @@ public void testHandleStageStatusNoSendingConditionFalse() throws IOException {
6666
}
6767

6868
@Test
69-
public void testHandleStageStatusGoodWeather() throws IOException {
69+
void testHandleStageStatusGoodWeather() throws IOException {
7070
String stageStatusJson = Helper.readResource("/stageStatus.json");
7171

7272
GoPluginApiResponse response = getGoNotifierPlugin().handle(
@@ -85,7 +85,7 @@ public void testHandleStageStatusGoodWeather() throws IOException {
8585
}
8686

8787
@Test
88-
public void testHandleStageStatusWithRemoteBadRequest() throws IOException {
88+
void testHandleStageStatusWithRemoteBadRequest() throws IOException {
8989
GoogleMockServlet.setStatusToReturn(HttpStatus.SC_BAD_REQUEST);
9090
String stageStatusJson = Helper.readResource("/stageStatus.json");
9191

src/test/java/com/ionos/go/plugin/notifier/GoNotifierPluginTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
44
import org.apache.hc.core5.http.HttpStatus;
5-
import org.junit.Test;
5+
import org.junit.jupiter.api.Test;
66

77
import java.util.Collections;
88
import java.util.Map;
99

10-
import static org.junit.Assert.assertEquals;
11-
import static org.junit.Assert.assertFalse;
12-
import static org.junit.Assert.assertNotNull;
13-
import static org.junit.Assert.assertTrue;
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertFalse;
12+
import static org.junit.jupiter.api.Assertions.assertNotNull;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
1414

1515

1616
public class GoNotifierPluginTest extends GoNotifierPluginBase {
1717

1818
@Test
19-
public void testPluginIdentifier() {
19+
void testPluginIdentifier() {
2020
assertEquals("notification", getGoNotifierPlugin().pluginIdentifier().getExtension());
2121
assertTrue(getGoNotifierPlugin().pluginIdentifier().getSupportedExtensionVersions().contains("4.0"));
2222
}
2323

2424
@Test
25-
public void testHandleNotificationsInterestedIn() {
25+
void testHandleNotificationsInterestedIn() {
2626
// request get conf
2727
GoPluginApiResponse response = getGoNotifierPlugin().handle(GoCdObjects.request(Constants.PLUGIN_NOTIFICATIONS_INTERESTED_IN, null));
2828
assertNotNull(response);
@@ -32,26 +32,26 @@ public void testHandleNotificationsInterestedIn() {
3232
}
3333

3434
@Test
35-
public void testHandleGetView() {
35+
void testHandleGetView() {
3636
GoPluginApiResponse response = getGoNotifierPlugin().handle(GoCdObjects.request(Constants.PLUGIN_GET_VIEW, null));
3737
assertNotNull(response);
3838
assertEquals(HttpStatus.SC_OK, response.responseCode());
3939
assertEquals(Collections.emptyMap(), response.responseHeaders());
40-
assertFalse("needs to be non empty", response.responseBody().isEmpty());
41-
assertFalse("needs to contain input html element", response.responseBody().contains("<input"));
40+
assertFalse(response.responseBody().isEmpty(), "needs to be non empty");
41+
assertFalse(response.responseBody().contains("<input"), "needs to contain input html element");
4242
}
4343

4444
@Test
45-
public void testHandleGetConfiguration() {
45+
void testHandleGetConfiguration() {
4646
GoPluginApiResponse response = getGoNotifierPlugin().handle(
4747
GoCdObjects.request(Constants.PLUGIN_GET_CONFIGURATION, null));
4848
assertNotNull(response);
4949
assertEquals(HttpStatus.SC_OK, response.responseCode());
5050
assertEquals(Collections.emptyMap(), response.responseHeaders());
5151
Map<String, Object> map = getGson().fromJson(response.responseBody(), Map.class);
52-
assertTrue("contains a config key", map.containsKey(Constants.PARAM_CONDITION));
53-
assertTrue("contains a config key", map.containsKey(Constants.PARAM_TEMPLATE));
54-
assertTrue("contains a config key", map.containsKey(Constants.PARAM_PROXY_URL));
55-
assertTrue("contains a config key", map.containsKey(Constants.PARAM_WEBHOOK_URL));
52+
assertTrue(map.containsKey(Constants.PARAM_CONDITION), "contains a config key");
53+
assertTrue(map.containsKey(Constants.PARAM_TEMPLATE), "contains a config key");
54+
assertTrue(map.containsKey(Constants.PARAM_PROXY_URL), "contains a config key");
55+
assertTrue(map.containsKey(Constants.PARAM_WEBHOOK_URL), "contains a config key");
5656
}
5757
}

src/test/java/com/ionos/go/plugin/notifier/GoNotifierPluginValidateConfigurationTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44
import com.ionos.go.plugin.notifier.message.outgoing.ValidateConfigurationResponse;
55
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
66
import org.apache.hc.core5.http.HttpStatus;
7-
import org.junit.Before;
8-
import org.junit.Test;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
99

1010
import java.util.Collections;
1111
import java.util.HashMap;
1212
import java.util.Map;
1313

14-
import static org.junit.Assert.assertEquals;
15-
import static org.junit.Assert.assertNotNull;
16-
import static org.junit.Assert.assertTrue;
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.junit.jupiter.api.Assertions.assertNotNull;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
1717

1818
public class GoNotifierPluginValidateConfigurationTest extends GoNotifierPluginBase {
1919

2020
private ValidateConfigurationRequest request;
2121

22-
@Before
22+
@BeforeEach
2323
public void setupTest() {
2424
request = new ValidateConfigurationRequest();
2525
}
2626

2727
@Test
28-
public void testHandleValidateConfigurationWithBadRequest() {
28+
void testHandleValidateConfigurationWithBadRequest() {
2929
GoPluginApiResponse response = getGoNotifierPlugin().handle(
3030
GoCdObjects.request(Constants.PLUGIN_VALIDATE_CONFIGURATION, getGson().toJson(request)));
3131
assertNotNull(response);
@@ -34,7 +34,7 @@ public void testHandleValidateConfigurationWithBadRequest() {
3434
}
3535

3636
@Test
37-
public void testHandleValidateConfigurationWithGoodRequestMultipleErrors() {
37+
void testHandleValidateConfigurationWithGoodRequestMultipleErrors() {
3838
request.setPluginSettings(new HashMap<>());
3939
GoPluginApiResponse response = getGoNotifierPlugin().handle(
4040
GoCdObjects.request(Constants.PLUGIN_VALIDATE_CONFIGURATION, getGson().toJson(request)));
@@ -47,7 +47,7 @@ public void testHandleValidateConfigurationWithGoodRequestMultipleErrors() {
4747
}
4848

4949
@Test
50-
public void testHandleValidateConfigurationWithGoodRequestNoErrors() {
50+
void testHandleValidateConfigurationWithGoodRequestNoErrors() {
5151
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
5252
request.setPluginSettings(pluginSettings);
5353
GoPluginApiResponse response = getGoNotifierPlugin().handle(
@@ -60,7 +60,7 @@ public void testHandleValidateConfigurationWithGoodRequestNoErrors() {
6060
}
6161

6262
@Test
63-
public void testHandleValidateConfigurationWithMalformedCondition() {
63+
void testHandleValidateConfigurationWithMalformedCondition() {
6464
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
6565
pluginSettings.put(Constants.PARAM_CONDITION, Collections.singletonMap(Constants.FIELD_VALUE, "${ error"));
6666
request.setPluginSettings(pluginSettings);
@@ -75,7 +75,7 @@ public void testHandleValidateConfigurationWithMalformedCondition() {
7575
}
7676

7777
@Test
78-
public void testHandleValidateConfigurationWithMalformedTemplate() {
78+
void testHandleValidateConfigurationWithMalformedTemplate() {
7979
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
8080
pluginSettings.put(Constants.PARAM_TEMPLATE, Collections.singletonMap(Constants.FIELD_VALUE, "${ error"));
8181
request.setPluginSettings(pluginSettings);
@@ -90,7 +90,7 @@ public void testHandleValidateConfigurationWithMalformedTemplate() {
9090
}
9191

9292
@Test
93-
public void testHandleValidateConfigurationWithTemplateAccessingUndefinedProperty() {
93+
void testHandleValidateConfigurationWithTemplateAccessingUndefinedProperty() {
9494
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
9595
pluginSettings.put(Constants.PARAM_TEMPLATE, Collections.singletonMap(Constants.FIELD_VALUE, "${ doesntexist.foobar }"));
9696
request.setPluginSettings(pluginSettings);
@@ -105,7 +105,7 @@ public void testHandleValidateConfigurationWithTemplateAccessingUndefinedPropert
105105
}
106106

107107
@Test
108-
public void testHandleValidateConfigurationWithConditionAccessingUndefinedProperty() {
108+
void testHandleValidateConfigurationWithConditionAccessingUndefinedProperty() {
109109
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
110110
pluginSettings.put(Constants.PARAM_CONDITION, Collections.singletonMap(Constants.FIELD_VALUE, "${ doesntexist.foobar }"));
111111
request.setPluginSettings(pluginSettings);
@@ -120,7 +120,7 @@ public void testHandleValidateConfigurationWithConditionAccessingUndefinedProper
120120
}
121121

122122
@Test
123-
public void testHandleValidateConfigurationWithConditionNotTrueOrFalse() {
123+
void testHandleValidateConfigurationWithConditionNotTrueOrFalse() {
124124
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
125125
pluginSettings.put(Constants.PARAM_CONDITION, Collections.singletonMap(Constants.FIELD_VALUE, "tralse"));
126126
request.setPluginSettings(pluginSettings);
@@ -132,11 +132,11 @@ public void testHandleValidateConfigurationWithConditionNotTrueOrFalse() {
132132
ValidateConfigurationResponse[] validateConfigurationResponses = getGson().fromJson(response.responseBody(), ValidateConfigurationResponse[].class);
133133
assertEquals(1, validateConfigurationResponses.length);
134134
assertEquals(Constants.PARAM_CONDITION, validateConfigurationResponses[0].getKey());
135-
assertTrue("Should contain 'true or false'", validateConfigurationResponses[0].getMessage().contains("true or false"));
135+
assertTrue(validateConfigurationResponses[0].getMessage().contains("true or false"), "Should contain 'true or false'");
136136
}
137137

138138
@Test
139-
public void testHandleValidateConfigurationWithMalformedProxyUrl() {
139+
void testHandleValidateConfigurationWithMalformedProxyUrl() {
140140
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
141141
pluginSettings.put(Constants.PARAM_PROXY_URL, Collections.singletonMap(Constants.FIELD_VALUE, "hppt://foo.bar"));
142142
request.setPluginSettings(pluginSettings);
@@ -152,7 +152,7 @@ public void testHandleValidateConfigurationWithMalformedProxyUrl() {
152152
}
153153

154154
@Test
155-
public void testHandleValidateConfigurationWithMalformedWebhookUrl() {
155+
void testHandleValidateConfigurationWithMalformedWebhookUrl() {
156156
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
157157
pluginSettings.put(Constants.PARAM_WEBHOOK_URL, Collections.singletonMap(Constants.FIELD_VALUE, "hppt://foo.bar"));
158158
request.setPluginSettings(pluginSettings);

src/test/java/com/ionos/go/plugin/notifier/StageStatusHandlerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
import com.thoughtworks.go.plugin.api.request.GoPluginApiRequest;
55
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
66
import org.apache.hc.core5.http.HttpStatus;
7-
import org.junit.Test;
7+
import org.junit.jupiter.api.Test;
88

99
import java.io.IOException;
1010

11-
import static org.junit.Assert.assertEquals;
12-
import static org.junit.Assert.assertNotNull;
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1313

1414

1515
public class StageStatusHandlerTest extends CommonTestBase {
1616

1717
@Test
18-
public void testInit() {
18+
void testInit() {
1919
StageStatusHandler handler = new StageStatusHandler(getServerInfo(), getPluginSettings());
2020
}
2121

2222
@Test
23-
public void testHandle() throws IOException {
23+
void testHandle() throws IOException {
2424
String stageStatusJson = Helper.readResource("/stageStatus.json");
2525
GoPluginApiRequest request = GoCdObjects.request(Constants.PLUGIN_STAGE_STATUS, stageStatusJson);
2626
StageStatusHandler handler = new StageStatusHandler(getServerInfo(), getPluginSettings());

src/test/java/com/ionos/go/plugin/notifier/ValidateConfigurationHandlerTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
import com.thoughtworks.go.plugin.api.request.GoPluginApiRequest;
55
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
66
import org.apache.hc.core5.http.HttpStatus;
7-
import org.junit.Test;
7+
import org.junit.jupiter.api.Test;
88

99
import java.io.IOException;
1010
import java.util.Collections;
1111
import java.util.HashMap;
1212
import java.util.Map;
1313

14-
import static org.junit.Assert.assertEquals;
15-
import static org.junit.Assert.assertNotNull;
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
1615

1716

1817
public class ValidateConfigurationHandlerTest extends CommonTestBase {
1918

2019
@Test
21-
public void toFlatSettingsWithTwoEntries() {
20+
void toFlatSettingsWithTwoEntries() {
2221
Map<String, Map<String, String>> input = new HashMap<>();
2322
input.put("foo", Collections.singletonMap(Constants.FIELD_VALUE, "bar"));
2423
input.put("my", Collections.singletonMap(Constants.FIELD_VALUE, "value"));
@@ -31,7 +30,7 @@ public void toFlatSettingsWithTwoEntries() {
3130
}
3231

3332
@Test
34-
public void toFlatSettingsWithOneNonValue() {
33+
void toFlatSettingsWithOneNonValue() {
3534
Map<String, Map<String, String>> input = new HashMap<>();
3635
input.put("foo", Collections.singletonMap(Constants.FIELD_VALUE, "bar"));
3736
input.put("my", Collections.singletonMap("baz", "value"));

0 commit comments

Comments
 (0)