Skip to content

Commit ceafc21

Browse files
committed
Update to JUnit 5
Signed-off-by: Taylor Smock <[email protected]>
1 parent d9746e9 commit ceafc21

21 files changed

+268
-314
lines changed

build.gradle

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ plugins {
77
id "jacoco"
88
id "maven-publish"
99
id "pmd"
10-
id("com.github.spotbugs").version("5.0.8")
10+
id("com.github.spotbugs").version("5.2.1")
1111
id("org.openstreetmap.josm").version("0.8.2")
12-
id("net.ltgt.errorprone").version("2.0.2")
12+
id("net.ltgt.errorprone").version("3.1.0")
1313
}
1414

1515
// Set up Errorprone
@@ -31,11 +31,13 @@ tasks.withType(JavaCompile).configureEach {
3131
java.sourceCompatibility = JavaVersion.VERSION_1_8
3232

3333
def versions = [
34+
awaitility: "4.2.0",
3435
errorprone: "2.10.0",
35-
jacoco : "0.8.8",
36-
junit : "5.8.2",
37-
pmd : "6.46.0",
38-
spotbugs : "4.7.0",
36+
jacoco : "0.8.11",
37+
junit : "5.10.0",
38+
pmd : "6.55.0",
39+
spotbugs : "4.8.0",
40+
wiremock : "2.35.1"
3941
]
4042

4143
repositories {
@@ -48,12 +50,13 @@ dependencies {
4850
errorprone("com.google.errorprone:error_prone_core:${versions.errorprone}")
4951

5052
testImplementation("org.junit.jupiter:junit-jupiter-api:${versions.junit}")
53+
testImplementation("org.junit.jupiter:junit-jupiter-params:${versions.junit}")
5154
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${versions.junit}")
5255
testImplementation("org.junit.vintage:junit-vintage-engine:${versions.junit}")
5356
testImplementation("com.github.spotbugs:spotbugs-annotations:${versions.spotbugs}")
5457
testImplementation("org.openstreetmap.josm:josm-unittest:"){changing=true}
55-
testImplementation('com.github.tomakehurst:wiremock-jre8:2.33.2')
56-
testImplementation('org.awaitility:awaitility:4.2.0')
58+
testImplementation("com.github.tomakehurst:wiremock-jre8:${versions.wiremock}")
59+
testImplementation("org.awaitility:awaitility:${versions.awaitility}")
5760
}
5861

5962
// Add dependencies from ivy.xml
@@ -67,6 +70,7 @@ ivyModule.dependencies.dependency.each {
6770
test {
6871
useJUnitPlatform()
6972
testLogging.exceptionFormat = 'full'
73+
systemProperty("junit.jupiter.extensions.autodetection.enabled", true)
7074
}
7175

7276
sourceSets {

gradle/wrapper/gradle-wrapper.jar

2.04 KB
Binary file not shown.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=e6d864e3b5bc05cc62041842b306383fc1fefcec359e70cebb1d470a6094ca82
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
3+
distributionSha256Sum=3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
5+
networkTimeout=10000
56
zipStoreBase=GRADLE_USER_HOME
67
zipStorePath=wrapper/dists

gradlew

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Darwin, MinGW, and NonStop.
5656
#
5757
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
58+
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5959
# within the Gradle project.
6060
#
6161
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,10 +80,10 @@ do
8080
esac
8181
done
8282

83-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84-
85-
APP_NAME="Gradle"
83+
# This is normally unused
84+
# shellcheck disable=SC2034
8685
APP_BASE_NAME=${0##*/}
86+
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
8787

8888
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
8989
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
@@ -143,12 +143,16 @@ fi
143143
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144144
case $MAX_FD in #(
145145
max*)
146+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147+
# shellcheck disable=SC3045
146148
MAX_FD=$( ulimit -H -n ) ||
147149
warn "Could not query maximum file descriptor limit"
148150
esac
149151
case $MAX_FD in #(
150152
'' | soft) :;; #(
151153
*)
154+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155+
# shellcheck disable=SC3045
152156
ulimit -n "$MAX_FD" ||
153157
warn "Could not set maximum file descriptor limit to $MAX_FD"
154158
esac
@@ -205,6 +209,12 @@ set -- \
205209
org.gradle.wrapper.GradleWrapperMain \
206210
"$@"
207211

212+
# Stop when "xargs" is not available.
213+
if ! command -v xargs >/dev/null 2>&1
214+
then
215+
die "xargs is not available"
216+
fi
217+
208218
# Use "xargs" to parse quoted args.
209219
#
210220
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

gradlew.bat

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@rem limitations under the License.
1515
@rem
1616

17-
@if "%DEBUG%" == "" @echo off
17+
@if "%DEBUG%"=="" @echo off
1818
@rem ##########################################################################
1919
@rem
2020
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
2525
if "%OS%"=="Windows_NT" setlocal
2626

2727
set DIRNAME=%~dp0
28-
if "%DIRNAME%" == "" set DIRNAME=.
28+
if "%DIRNAME%"=="" set DIRNAME=.
29+
@rem This is normally unused
2930
set APP_BASE_NAME=%~n0
3031
set APP_HOME=%DIRNAME%
3132

@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4041

4142
set JAVA_EXE=java.exe
4243
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
44+
if %ERRORLEVEL% equ 0 goto execute
4445

4546
echo.
4647
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7576

7677
:end
7778
@rem End local scope for the variables with windows NT shell
78-
if "%ERRORLEVEL%"=="0" goto mainEnd
79+
if %ERRORLEVEL% equ 0 goto mainEnd
7980

8081
:fail
8182
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
8283
rem the _cmd.exe /c_ return code!
83-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84-
exit /b 1
84+
set EXIT_CODE=%ERRORLEVEL%
85+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
86+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87+
exit /b %EXIT_CODE%
8588

8689
:mainEnd
8790
if "%OS%"=="Windows_NT" endlocal

test/unit/org/wikipedia/WikipediaAppTest.java

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import static org.hamcrest.CoreMatchers.is;
66
import static org.hamcrest.CoreMatchers.nullValue;
77
import static org.hamcrest.MatcherAssert.assertThat;
8-
import static org.junit.Assert.assertEquals;
9-
import static org.junit.Assert.assertTrue;
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertThrows;
10+
import static org.junit.jupiter.api.Assertions.assertTrue;
1011

1112
import java.util.Arrays;
1213
import java.util.Collection;
@@ -17,64 +18,60 @@
1718
import java.util.stream.Collectors;
1819
import java.util.stream.IntStream;
1920
import java.util.stream.Stream;
20-
import org.junit.Rule;
21-
import org.junit.Test;
21+
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.Timeout;
2224
import org.openstreetmap.josm.data.coor.LatLon;
23-
import org.openstreetmap.josm.testutils.JOSMTestRules;
25+
import org.openstreetmap.josm.testutils.annotations.I18n;
2426
import org.wikipedia.data.WikidataEntry;
2527
import org.wikipedia.data.WikipediaEntry;
2628

27-
public class WikipediaAppTest {
28-
29-
/**
30-
* Setup test.
31-
*/
32-
@Rule
33-
public JOSMTestRules rules = new JOSMTestRules().preferences().timeout(20_000).i18n("en");
34-
29+
@Timeout(20)
30+
@I18n
31+
class WikipediaAppTest {
3532
@Test
36-
public void testMediawikiLocale() throws Exception {
33+
void testMediawikiLocale() {
3734
assertThat(WikipediaApp.getMediawikiLocale(Locale.GERMANY), is("de-de"));
3835
assertThat(WikipediaApp.getMediawikiLocale(Locale.GERMAN), is("de"));
3936
assertThat(WikipediaApp.getMediawikiLocale(Locale.UK), is("en-gb"));
4037
assertThat(WikipediaApp.getMediawikiLocale(Locale.CANADA), is("en-ca"));
4138
}
4239

4340
@Test
44-
public void testPartitionList() {
41+
void testPartitionList() {
4542
assertThat(
4643
WikipediaApp.partitionList(Arrays.asList(1, 2, 3, 4, 5), 2),
4744
is(Arrays.asList(
4845
Arrays.asList(1, 2),
4946
Arrays.asList(3, 4),
50-
Arrays.asList(5)
47+
Collections.singletonList(5)
5148
))
5249
);
5350
}
5451

5552
@Test
56-
public void testGetInterwikiArticles1() {
53+
void testGetInterwikiArticles1() {
5754
final Collection<WikipediaEntry> iw = WikipediaApp.forLanguage("de").getInterwikiArticles("Österreich");
5855
assertThat(iw, hasItem(new WikipediaEntry("en", "Austria")));
5956
assertThat(iw, hasItem(new WikipediaEntry("nb", "Østerrike")));
6057
assertThat(iw, hasItem(new WikipediaEntry("ko", "오스트리아")));
6158
}
6259

6360
@Test
64-
public void testGetInterwikiArticles2() {
61+
void testGetInterwikiArticles2() {
6562
final Collection<WikipediaEntry> iw = WikipediaApp.forLanguage("en").getInterwikiArticles("Ampersand");
6663
assertThat(iw, hasItem(new WikipediaEntry("fi", "&")));
6764
}
6865

6966
@Test
70-
public void testGetCoordinates() throws Exception {
67+
void testGetCoordinates() {
7168
assertThat(WikipediaApp.forLanguage("de").getCoordinateForArticle("Marchreisenspitze"), is(new LatLon(47.1725, 11.30833333)));
7269
assertThat(WikipediaApp.forLanguage("en").getCoordinateForArticle("Austria"), is(new LatLon(47.33333333, 13.33333333)));
7370
assertThat(WikipediaApp.forLanguage("en").getCoordinateForArticle("Foobar2000"), nullValue());
7471
}
7572

7673
@Test
77-
public void testFromCoordinates() throws Exception {
74+
void testFromCoordinates() {
7875
final List<WikipediaEntry> entries = WikipediaApp.forLanguage("de")
7976
.getEntriesFromCoordinates(new LatLon(52.5179786, 13.3753321), new LatLon(52.5192215, 13.3768705));
8077
final long c = entries.stream()
@@ -84,7 +81,7 @@ public void testFromCoordinates() throws Exception {
8481
}
8582

8683
@Test
87-
public void testForQuery() {
84+
void testForQuery() {
8885
final List<WikidataEntry> de = WikipediaApp.getWikidataEntriesForQuery("de", "Österreich", Locale.GERMAN);
8986
final List<WikidataEntry> en = WikipediaApp.getWikidataEntriesForQuery("de", "Österreich", Locale.ENGLISH);
9087
assertThat(de.get(0).article, is("Q40"));
@@ -96,7 +93,7 @@ public void testForQuery() {
9693
}
9794

9895
@Test
99-
public void testFromCoordinatesWikidata() throws Exception {
96+
void testFromCoordinatesWikidata() {
10097
final List<WikipediaEntry> entries = WikipediaApp.forLanguage("wikidata")
10198
.getEntriesFromCoordinates(new LatLon(47.20, 11.30), new LatLon(47.22, 11.32));
10299
final long c = entries.stream()
@@ -107,7 +104,7 @@ public void testFromCoordinatesWikidata() throws Exception {
107104
}
108105

109106
@Test
110-
public void testGetWikidataForArticles() {
107+
void testGetWikidataForArticles() {
111108
final Map<String, String> map = WikipediaApp.forLanguage("en")
112109
.getWikidataForArticles(Arrays.asList("London", "Vienna", "Völs, Tyrol", "a-non-existing-article"));
113110
assertThat(map.get("London"), is("Q84"));
@@ -118,7 +115,7 @@ public void testGetWikidataForArticles() {
118115
}
119116

120117
@Test
121-
public void testGetWikidataForArticlesResolveRedirects() throws Exception {
118+
void testGetWikidataForArticlesResolveRedirects() {
122119
final Map<String, String> map = WikipediaApp.forLanguage("en")
123120
.getWikidataForArticles(Arrays.asList("einstein", "USA"));
124121
assertThat(map.get("einstein"), is("Q937"));
@@ -127,7 +124,7 @@ public void testGetWikidataForArticlesResolveRedirects() throws Exception {
127124
}
128125

129126
@Test
130-
public void testTicket13991() {
127+
void testTicket13991() {
131128
final Map<String, String> map = WikipediaApp.forLanguage("en")
132129
.getWikidataForArticles(Stream.iterate("London", x -> x).limit(100).collect(Collectors.toList()));
133130
assertThat(map, is(Collections.singletonMap("London", "Q84")));
@@ -138,7 +135,7 @@ public void testTicket13991() {
138135
}
139136

140137
@Test
141-
public void testGetLabelForWikidata() throws Exception {
138+
void testGetLabelForWikidata() {
142139
assertThat(WikipediaApp.getLabelForWikidata("Q1741", Locale.GERMAN), is("Wien"));
143140
assertThat(WikipediaApp.getLabelForWikidata("Q1741", Locale.ENGLISH), is("Vienna"));
144141
// fallback to any label
@@ -152,13 +149,13 @@ public void testGetLabelForWikidata() throws Exception {
152149
assertThat(twoLabels.get(1).label, is("Wien"));
153150
}
154151

155-
@Test(expected = RuntimeException.class)
156-
public void testGetLabelForWikidataInvalidId() throws Exception {
157-
WikipediaApp.getLabelForWikidata("Qxyz", Locale.ENGLISH);
152+
@Test
153+
void testGetLabelForWikidataInvalidId() {
154+
assertThrows(RuntimeException.class, () -> WikipediaApp.getLabelForWikidata("Qxyz", Locale.ENGLISH));
158155
}
159156

160157
@Test
161-
public void testWIWOSMStatus() throws Exception {
158+
void testWIWOSMStatus() {
162159
final WikipediaEntry entry1 = new WikipediaEntry("en", "Vienna");
163160
final WikipediaEntry entry2 = new WikipediaEntry("en", "London");
164161
final WikipediaEntry entry3 = new WikipediaEntry("en", "a-non-existing-article");
@@ -169,13 +166,13 @@ public void testWIWOSMStatus() throws Exception {
169166
}
170167

171168
@Test
172-
public void testCategoriesForPrefix() throws Exception {
169+
void testCategoriesForPrefix() {
173170
final List<String> categories = WikipediaApp.forLanguage("de").getCategoriesForPrefix("Gemeinde in Öster");
174171
assertTrue(categories.contains("Gemeinde in Österreich"));
175172
}
176173

177174
@Test
178-
public void testEntriesFromClipboard() {
175+
void testEntriesFromClipboard() {
179176
List<WikipediaEntry> entries = WikipediaApp.getEntriesFromClipboard("de", "foo\nde:bar\nen:baz\n");
180177
assertThat(entries.size(), is(3));
181178
assertThat(entries.get(0), is(new WikipediaEntry("de", "foo")));
@@ -184,7 +181,7 @@ public void testEntriesFromClipboard() {
184181
}
185182

186183
@Test
187-
public void testEntriesFromClipboardWikidata() {
184+
void testEntriesFromClipboardWikidata() {
188185
List<WikipediaEntry> entries = WikipediaApp.getEntriesFromClipboard("wikidata", "Q40\nQ151897");
189186
assertThat(entries.size(), is(2));
190187
assertThat(entries.get(0).article, is("Q40"));

test/unit/org/wikipedia/api/ApiUrlTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
// License: GPL. For details, see LICENSE file.
22
package org.wikipedia.api;
33

4-
import static org.junit.Assert.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
56

67
import java.net.MalformedURLException;
78
import java.net.URL;
8-
import org.junit.Test;
99

10-
public class ApiUrlTest {
10+
import org.junit.jupiter.api.Test;
1111

12-
@Test(expected = IllegalArgumentException.class)
13-
public void testMalformedUrl() {
14-
ApiUrl.url("malformedURL");
12+
class ApiUrlTest {
13+
14+
@Test
15+
void testMalformedUrl() {
16+
assertThrows(IllegalArgumentException.class, () -> ApiUrl.url("malformedURL"));
1517
}
1618

1719
@Test
18-
public void testUrl() throws MalformedURLException {
20+
void testUrl() throws MalformedURLException {
1921
assertEquals(new URL("https://example.org"), ApiUrl.url("https://example.org"));
2022
assertEquals(new URL("https://example.org/abc"), ApiUrl.url("https://example.org/abc"));
2123
assertEquals(new URL("https://example.org/abc/def/ghi/jkl/mno"), ApiUrl.url("https://example.org/abc/def/ghi/jkl/mno"));

0 commit comments

Comments
 (0)