Skip to content

Commit

Permalink
Update to JUnit 5
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Oct 25, 2023
1 parent d9746e9 commit ceafc21
Show file tree
Hide file tree
Showing 21 changed files with 268 additions and 314 deletions.
20 changes: 12 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ plugins {
id "jacoco"
id "maven-publish"
id "pmd"
id("com.github.spotbugs").version("5.0.8")
id("com.github.spotbugs").version("5.2.1")
id("org.openstreetmap.josm").version("0.8.2")
id("net.ltgt.errorprone").version("2.0.2")
id("net.ltgt.errorprone").version("3.1.0")
}

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

def versions = [
awaitility: "4.2.0",
errorprone: "2.10.0",
jacoco : "0.8.8",
junit : "5.8.2",
pmd : "6.46.0",
spotbugs : "4.7.0",
jacoco : "0.8.11",
junit : "5.10.0",
pmd : "6.55.0",
spotbugs : "4.8.0",
wiremock : "2.35.1"
]

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

testImplementation("org.junit.jupiter:junit-jupiter-api:${versions.junit}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${versions.junit}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${versions.junit}")
testImplementation("org.junit.vintage:junit-vintage-engine:${versions.junit}")
testImplementation("com.github.spotbugs:spotbugs-annotations:${versions.spotbugs}")
testImplementation("org.openstreetmap.josm:josm-unittest:"){changing=true}
testImplementation('com.github.tomakehurst:wiremock-jre8:2.33.2')
testImplementation('org.awaitility:awaitility:4.2.0')
testImplementation("com.github.tomakehurst:wiremock-jre8:${versions.wiremock}")
testImplementation("org.awaitility:awaitility:${versions.awaitility}")
}

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

sourceSets {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=e6d864e3b5bc05cc62041842b306383fc1fefcec359e70cebb1d470a6094ca82
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
distributionSha256Sum=3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 14 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

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

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -205,6 +209,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

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

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

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

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
63 changes: 30 additions & 33 deletions test/unit/org/wikipedia/WikipediaAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -17,64 +18,60 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.junit.Rule;
import org.junit.Test;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.I18n;
import org.wikipedia.data.WikidataEntry;
import org.wikipedia.data.WikipediaEntry;

public class WikipediaAppTest {

/**
* Setup test.
*/
@Rule
public JOSMTestRules rules = new JOSMTestRules().preferences().timeout(20_000).i18n("en");

@Timeout(20)
@I18n
class WikipediaAppTest {
@Test
public void testMediawikiLocale() throws Exception {
void testMediawikiLocale() {
assertThat(WikipediaApp.getMediawikiLocale(Locale.GERMANY), is("de-de"));
assertThat(WikipediaApp.getMediawikiLocale(Locale.GERMAN), is("de"));
assertThat(WikipediaApp.getMediawikiLocale(Locale.UK), is("en-gb"));
assertThat(WikipediaApp.getMediawikiLocale(Locale.CANADA), is("en-ca"));
}

@Test
public void testPartitionList() {
void testPartitionList() {
assertThat(
WikipediaApp.partitionList(Arrays.asList(1, 2, 3, 4, 5), 2),
is(Arrays.asList(
Arrays.asList(1, 2),
Arrays.asList(3, 4),
Arrays.asList(5)
Collections.singletonList(5)
))
);
}

@Test
public void testGetInterwikiArticles1() {
void testGetInterwikiArticles1() {
final Collection<WikipediaEntry> iw = WikipediaApp.forLanguage("de").getInterwikiArticles("Österreich");
assertThat(iw, hasItem(new WikipediaEntry("en", "Austria")));
assertThat(iw, hasItem(new WikipediaEntry("nb", "Østerrike")));
assertThat(iw, hasItem(new WikipediaEntry("ko", "오스트리아")));
}

@Test
public void testGetInterwikiArticles2() {
void testGetInterwikiArticles2() {
final Collection<WikipediaEntry> iw = WikipediaApp.forLanguage("en").getInterwikiArticles("Ampersand");
assertThat(iw, hasItem(new WikipediaEntry("fi", "&")));
}

@Test
public void testGetCoordinates() throws Exception {
void testGetCoordinates() {
assertThat(WikipediaApp.forLanguage("de").getCoordinateForArticle("Marchreisenspitze"), is(new LatLon(47.1725, 11.30833333)));
assertThat(WikipediaApp.forLanguage("en").getCoordinateForArticle("Austria"), is(new LatLon(47.33333333, 13.33333333)));
assertThat(WikipediaApp.forLanguage("en").getCoordinateForArticle("Foobar2000"), nullValue());
}

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

@Test
public void testForQuery() {
void testForQuery() {
final List<WikidataEntry> de = WikipediaApp.getWikidataEntriesForQuery("de", "Österreich", Locale.GERMAN);
final List<WikidataEntry> en = WikipediaApp.getWikidataEntriesForQuery("de", "Österreich", Locale.ENGLISH);
assertThat(de.get(0).article, is("Q40"));
Expand All @@ -96,7 +93,7 @@ public void testForQuery() {
}

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

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

@Test
public void testGetWikidataForArticlesResolveRedirects() throws Exception {
void testGetWikidataForArticlesResolveRedirects() {
final Map<String, String> map = WikipediaApp.forLanguage("en")
.getWikidataForArticles(Arrays.asList("einstein", "USA"));
assertThat(map.get("einstein"), is("Q937"));
Expand All @@ -127,7 +124,7 @@ public void testGetWikidataForArticlesResolveRedirects() throws Exception {
}

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

@Test
public void testGetLabelForWikidata() throws Exception {
void testGetLabelForWikidata() {
assertThat(WikipediaApp.getLabelForWikidata("Q1741", Locale.GERMAN), is("Wien"));
assertThat(WikipediaApp.getLabelForWikidata("Q1741", Locale.ENGLISH), is("Vienna"));
// fallback to any label
Expand All @@ -152,13 +149,13 @@ public void testGetLabelForWikidata() throws Exception {
assertThat(twoLabels.get(1).label, is("Wien"));
}

@Test(expected = RuntimeException.class)
public void testGetLabelForWikidataInvalidId() throws Exception {
WikipediaApp.getLabelForWikidata("Qxyz", Locale.ENGLISH);
@Test
void testGetLabelForWikidataInvalidId() {
assertThrows(RuntimeException.class, () -> WikipediaApp.getLabelForWikidata("Qxyz", Locale.ENGLISH));
}

@Test
public void testWIWOSMStatus() throws Exception {
void testWIWOSMStatus() {
final WikipediaEntry entry1 = new WikipediaEntry("en", "Vienna");
final WikipediaEntry entry2 = new WikipediaEntry("en", "London");
final WikipediaEntry entry3 = new WikipediaEntry("en", "a-non-existing-article");
Expand All @@ -169,13 +166,13 @@ public void testWIWOSMStatus() throws Exception {
}

@Test
public void testCategoriesForPrefix() throws Exception {
void testCategoriesForPrefix() {
final List<String> categories = WikipediaApp.forLanguage("de").getCategoriesForPrefix("Gemeinde in Öster");
assertTrue(categories.contains("Gemeinde in Österreich"));
}

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

@Test
public void testEntriesFromClipboardWikidata() {
void testEntriesFromClipboardWikidata() {
List<WikipediaEntry> entries = WikipediaApp.getEntriesFromClipboard("wikidata", "Q40\nQ151897");
assertThat(entries.size(), is(2));
assertThat(entries.get(0).article, is("Q40"));
Expand Down
16 changes: 9 additions & 7 deletions test/unit/org/wikipedia/api/ApiUrlTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
// License: GPL. For details, see LICENSE file.
package org.wikipedia.api;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.net.MalformedURLException;
import java.net.URL;
import org.junit.Test;

public class ApiUrlTest {
import org.junit.jupiter.api.Test;

@Test(expected = IllegalArgumentException.class)
public void testMalformedUrl() {
ApiUrl.url("malformedURL");
class ApiUrlTest {

@Test
void testMalformedUrl() {
assertThrows(IllegalArgumentException.class, () -> ApiUrl.url("malformedURL"));
}

@Test
public void testUrl() throws MalformedURLException {
void testUrl() throws MalformedURLException {
assertEquals(new URL("https://example.org"), ApiUrl.url("https://example.org"));
assertEquals(new URL("https://example.org/abc"), ApiUrl.url("https://example.org/abc"));
assertEquals(new URL("https://example.org/abc/def/ghi/jkl/mno"), ApiUrl.url("https://example.org/abc/def/ghi/jkl/mno"));
Expand Down
Loading

0 comments on commit ceafc21

Please sign in to comment.