diff --git a/build.gradle b/build.gradle index bd92f61e..6eeb66a9 100644 --- a/build.gradle +++ b/build.gradle @@ -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 @@ -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 { @@ -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 @@ -67,6 +70,7 @@ ivyModule.dependencies.dependency.each { test { useJUnitPlatform() testLogging.exceptionFormat = 'full' + systemProperty("junit.jupiter.extensions.autodetection.enabled", true) } sourceSets { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f..afba1092 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e1e0c8dc..b446fa9a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/gradlew b/gradlew index 1b6c7873..65dcd68d 100755 --- a/gradlew +++ b/gradlew @@ -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/. @@ -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"' @@ -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 @@ -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. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f9..6689b85b 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -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 @@ -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% @@ -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. @@ -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 diff --git a/test/unit/org/wikipedia/WikipediaAppTest.java b/test/unit/org/wikipedia/WikipediaAppTest.java index 9239d52a..94cb6df4 100644 --- a/test/unit/org/wikipedia/WikipediaAppTest.java +++ b/test/unit/org/wikipedia/WikipediaAppTest.java @@ -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; @@ -17,23 +18,19 @@ 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")); @@ -41,19 +38,19 @@ public void testMediawikiLocale() throws Exception { } @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 iw = WikipediaApp.forLanguage("de").getInterwikiArticles("Österreich"); assertThat(iw, hasItem(new WikipediaEntry("en", "Austria"))); assertThat(iw, hasItem(new WikipediaEntry("nb", "Østerrike"))); @@ -61,20 +58,20 @@ public void testGetInterwikiArticles1() { } @Test - public void testGetInterwikiArticles2() { + void testGetInterwikiArticles2() { final Collection 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 entries = WikipediaApp.forLanguage("de") .getEntriesFromCoordinates(new LatLon(52.5179786, 13.3753321), new LatLon(52.5192215, 13.3768705)); final long c = entries.stream() @@ -84,7 +81,7 @@ public void testFromCoordinates() throws Exception { } @Test - public void testForQuery() { + void testForQuery() { final List de = WikipediaApp.getWikidataEntriesForQuery("de", "Österreich", Locale.GERMAN); final List en = WikipediaApp.getWikidataEntriesForQuery("de", "Österreich", Locale.ENGLISH); assertThat(de.get(0).article, is("Q40")); @@ -96,7 +93,7 @@ public void testForQuery() { } @Test - public void testFromCoordinatesWikidata() throws Exception { + void testFromCoordinatesWikidata() { final List entries = WikipediaApp.forLanguage("wikidata") .getEntriesFromCoordinates(new LatLon(47.20, 11.30), new LatLon(47.22, 11.32)); final long c = entries.stream() @@ -107,7 +104,7 @@ public void testFromCoordinatesWikidata() throws Exception { } @Test - public void testGetWikidataForArticles() { + void testGetWikidataForArticles() { final Map map = WikipediaApp.forLanguage("en") .getWikidataForArticles(Arrays.asList("London", "Vienna", "Völs, Tyrol", "a-non-existing-article")); assertThat(map.get("London"), is("Q84")); @@ -118,7 +115,7 @@ public void testGetWikidataForArticles() { } @Test - public void testGetWikidataForArticlesResolveRedirects() throws Exception { + void testGetWikidataForArticlesResolveRedirects() { final Map map = WikipediaApp.forLanguage("en") .getWikidataForArticles(Arrays.asList("einstein", "USA")); assertThat(map.get("einstein"), is("Q937")); @@ -127,7 +124,7 @@ public void testGetWikidataForArticlesResolveRedirects() throws Exception { } @Test - public void testTicket13991() { + void testTicket13991() { final Map map = WikipediaApp.forLanguage("en") .getWikidataForArticles(Stream.iterate("London", x -> x).limit(100).collect(Collectors.toList())); assertThat(map, is(Collections.singletonMap("London", "Q84"))); @@ -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 @@ -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"); @@ -169,13 +166,13 @@ public void testWIWOSMStatus() throws Exception { } @Test - public void testCategoriesForPrefix() throws Exception { + void testCategoriesForPrefix() { final List categories = WikipediaApp.forLanguage("de").getCategoriesForPrefix("Gemeinde in Öster"); assertTrue(categories.contains("Gemeinde in Österreich")); } @Test - public void testEntriesFromClipboard() { + void testEntriesFromClipboard() { List entries = WikipediaApp.getEntriesFromClipboard("de", "foo\nde:bar\nen:baz\n"); assertThat(entries.size(), is(3)); assertThat(entries.get(0), is(new WikipediaEntry("de", "foo"))); @@ -184,7 +181,7 @@ public void testEntriesFromClipboard() { } @Test - public void testEntriesFromClipboardWikidata() { + void testEntriesFromClipboardWikidata() { List entries = WikipediaApp.getEntriesFromClipboard("wikidata", "Q40\nQ151897"); assertThat(entries.size(), is(2)); assertThat(entries.get(0).article, is("Q40")); diff --git a/test/unit/org/wikipedia/api/ApiUrlTest.java b/test/unit/org/wikipedia/api/ApiUrlTest.java index 8b6a8384..9b9145d3 100644 --- a/test/unit/org/wikipedia/api/ApiUrlTest.java +++ b/test/unit/org/wikipedia/api/ApiUrlTest.java @@ -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")); diff --git a/test/unit/org/wikipedia/api/wdq/WdqApiQueryTest.java b/test/unit/org/wikipedia/api/wdq/WdqApiQueryTest.java index 7e39a970..b0c7230c 100644 --- a/test/unit/org/wikipedia/api/wdq/WdqApiQueryTest.java +++ b/test/unit/org/wikipedia/api/wdq/WdqApiQueryTest.java @@ -7,12 +7,9 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.verify; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; -import static org.wikipedia.testutils.JunitJupiterCompatUtil.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import com.github.tomakehurst.wiremock.matching.EqualToPattern; import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; @@ -22,16 +19,22 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.openstreetmap.josm.testutils.JOSMTestRules; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.wikipedia.api.ApiQueryClient; import org.wikipedia.api.wdq.json.SparqlResult; import org.wikipedia.testutils.ResourceFileLoader; import org.wikipedia.tools.WikiProperties; -public class WdqApiQueryTest { +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import com.github.tomakehurst.wiremock.matching.EqualToPattern; + +@Timeout(30) +@WireMockTest +class WdqApiQueryTest { private static final String URL_PATH = "/sparql"; @@ -76,19 +79,13 @@ public class WdqApiQueryTest { private static final String BRIDGE_CLASS = "Q12280"; private static final String BUILDING_CLASS = "Q41176"; - @Rule - public JOSMTestRules josmRules = new JOSMTestRules().preferences().timeout(30_000); - - @Rule - public WireMockRule wmRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Before - public void setUp() throws MalformedURLException { - WdqApiQuery.setBaseUrl(new URL("http://localhost:" + wmRule.port() + URL_PATH)); + @BeforeEach + void setUp(WireMockRuntimeInfo wmRuntimeInfo) throws MalformedURLException { + WdqApiQuery.setBaseUrl(new URL(wmRuntimeInfo.getHttpBaseUrl() + URL_PATH)); } @Test - public void testMixed() throws IOException, URISyntaxException { + void testMixed() throws IOException, URISyntaxException { stubWithFileContent("mixed.json"); WikiProperties.WIKIPEDIA_LANGUAGE.put("es"); testFindInstancesOfClassesOrTheirSubclasses(MIXED_LIST, Arrays.asList(BRIDGE_CLASS, BUILDING_CLASS), MIXED_LIST); @@ -96,7 +93,7 @@ public void testMixed() throws IOException, URISyntaxException { } @Test - public void testBridges() throws IOException, URISyntaxException { + void testBridges() throws IOException, URISyntaxException { stubWithFileContent("bridges.json"); WikiProperties.WIKIPEDIA_LANGUAGE.put("de"); testFindInstancesOfClassesOrTheirSubclasses(MIXED_LIST, Collections.singletonList(BRIDGE_CLASS), BRIDGE_LIST); @@ -104,7 +101,7 @@ public void testBridges() throws IOException, URISyntaxException { } @Test - public void testBuildings() throws IOException, URISyntaxException { + void testBuildings() throws IOException, URISyntaxException { stubWithFileContent("buildings.json"); WikiProperties.WIKIPEDIA_LANGUAGE.put("zh"); testFindInstancesOfClassesOrTheirSubclasses(MIXED_LIST, Collections.singletonList(BUILDING_CLASS), BUILDING_LIST); @@ -112,22 +109,17 @@ public void testBuildings() throws IOException, URISyntaxException { } @Test - public void testIllegalArguments() { - assertThrows(IllegalArgumentException.class, () -> { - WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(new ArrayList<>(), Collections.singletonList("Q1")); - }); - assertThrows(IllegalArgumentException.class, () -> { - WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(Collections.singletonList("Q1"), Collections.emptyList()); - }); - assertThrows(NullPointerException.class, () -> { - WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(null, Collections.singletonList("Q1")); - }); - assertThrows(NullPointerException.class, () -> { - WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(Collections.singletonList("Q1"), null); - }); - assertThrows(IllegalArgumentException.class, () -> { - WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(Collections.singletonList("X1"), Collections.singletonList("")); - }); + void testIllegalArguments() { + assertThrows(IllegalArgumentException.class, + () -> WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(new ArrayList<>(), Collections.singletonList("Q1"))); + assertThrows(IllegalArgumentException.class, + () -> WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(Collections.singletonList("Q1"), Collections.emptyList())); + assertThrows(NullPointerException.class, + () -> WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(null, Collections.singletonList("Q1"))); + assertThrows(NullPointerException.class, + () -> WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(Collections.singletonList("Q1"), null)); + assertThrows(IllegalArgumentException.class, + () -> WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(Collections.singletonList("X1"), Collections.singletonList(""))); } private static void stubWithFileContent(final String filename) throws IOException, URISyntaxException { @@ -148,7 +140,8 @@ private static void verifyOneRequestTo(final String urlPattern) { private static void testFindInstancesOfClassesOrTheirSubclasses(final Collection itemList, final Collection classesList, final Collection expectedResultList) throws IOException { final SparqlResult result = ApiQueryClient.query(WdqApiQuery.findInstancesOfClassesOrTheirSubclasses(itemList, classesList)); for (final String expectedEntry : expectedResultList) { - assertEquals("Entry " + expectedEntry + " not found in the result!", 1, result.getRows().stream().filter(row -> ("http://www.wikidata.org/entity/" + expectedEntry).equals(row.get(0).getValue())).count()); + assertEquals(1, result.getRows().stream().filter(row -> ("http://www.wikidata.org/entity/" + expectedEntry).equals(row.get(0).getValue())).count(), + "Entry " + expectedEntry + " not found in the result!"); } assertEquals(expectedResultList.size(), result.size()); } diff --git a/test/unit/org/wikipedia/api/wikidata_action/QueryResultTest.java b/test/unit/org/wikipedia/api/wikidata_action/QueryResultTest.java index f9aad570..7108b604 100644 --- a/test/unit/org/wikipedia/api/wikidata_action/QueryResultTest.java +++ b/test/unit/org/wikipedia/api/wikidata_action/QueryResultTest.java @@ -1,18 +1,20 @@ package org.wikipedia.api.wikidata_action; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; import java.net.URISyntaxException; import java.util.Map; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.wikipedia.api.ApiQueryClient; import org.wikipedia.testutils.ResourceFileLoader; -public class QueryResultTest extends WikidataActionApiTestAbstract { +class QueryResultTest extends WikidataActionApiTestAbstract { @Test - public void test() throws IOException, URISyntaxException { + void test() throws IOException, URISyntaxException { simpleJsonStub(ResourceFileLoader.getResourceBytes(WikidataActionApiQueryTest.class, "response/query/languages.json")); final Map languages = ApiQueryClient.query(WikidataActionApiQuery.queryLanguages()); assertEquals(456, languages.size()); diff --git a/test/unit/org/wikipedia/api/wikidata_action/WbgetentitiesClaimsTest.java b/test/unit/org/wikipedia/api/wikidata_action/WbgetentitiesClaimsTest.java index c444cdd3..78a43d0b 100644 --- a/test/unit/org/wikipedia/api/wikidata_action/WbgetentitiesClaimsTest.java +++ b/test/unit/org/wikipedia/api/wikidata_action/WbgetentitiesClaimsTest.java @@ -1,7 +1,7 @@ package org.wikipedia.api.wikidata_action; -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.assertTrue; import java.io.IOException; import java.net.URISyntaxException; @@ -10,15 +10,16 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.wikipedia.api.ApiQueryClient; import org.wikipedia.api.wikidata_action.json.WbgetclaimsResult; import org.wikipedia.testutils.ResourceFileLoader; -public class WbgetentitiesClaimsTest extends WikidataActionApiTestAbstract { +class WbgetentitiesClaimsTest extends WikidataActionApiTestAbstract { @Test - public void test() throws IOException, URISyntaxException { + void test() throws IOException, URISyntaxException { simpleJsonStub(ResourceFileLoader.getResourceBytes(WikidataActionApiQueryTest.class, "response/wbgetentities/claims_Q2.json")); final Optional> result = ApiQueryClient.query(WikidataActionApiQuery.wbgetentitiesClaims("Q2")); diff --git a/test/unit/org/wikipedia/api/wikidata_action/WikidataActionApiQueryTest.java b/test/unit/org/wikipedia/api/wikidata_action/WikidataActionApiQueryTest.java index 3c6d470e..7a09e488 100644 --- a/test/unit/org/wikipedia/api/wikidata_action/WikidataActionApiQueryTest.java +++ b/test/unit/org/wikipedia/api/wikidata_action/WikidataActionApiQueryTest.java @@ -1,17 +1,24 @@ // License: GPL. For details, see LICENSE file. package org.wikipedia.api.wikidata_action; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.net.URISyntaxException; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Optional; -import org.junit.Test; +import java.util.stream.Stream; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.wikipedia.api.ApiQueryClient; import org.wikipedia.api.wikidata_action.json.WbgetentitiesResult; import org.wikipedia.data.WikipediaSite; @@ -19,44 +26,38 @@ public class WikidataActionApiQueryTest extends WikidataActionApiTestAbstract { - @Test(expected = IllegalArgumentException.class) - public void testWbgetentities_nonQId() { - WikidataActionApiQuery.wbgetentities(Collections.singletonList("X1")); - } - @Test(expected = IllegalArgumentException.class) - - public void testCheckEntityExists_nonQId2() { - WikidataActionApiQuery.wbgetentities(Arrays.asList("Q1", "Q2", "X1")); + static Stream testWbgetentitiesErrorIds() { + return Stream.of(Arguments.of((Object) new String[] {"X1"}), + Arguments.of((Object) new String[] {"Q1", "Q2", "X1"}), + Arguments.of((Object) new String[] {"Q1", null, "Q3"}), + Arguments.of((Object) new String[0])); } - @Test(expected = IllegalArgumentException.class) - public void testWbgetentities_nullId() { - WikidataActionApiQuery.wbgetentities(Arrays.asList("Q1", null, "Q3")); + @ParameterizedTest + @MethodSource + void testWbgetentitiesErrorIds(String[] entities) { + final List list = Arrays.asList(entities); + assertThrows(IllegalArgumentException.class, () -> WikidataActionApiQuery.wbgetentities(list)); } - @Test(expected = IllegalArgumentException.class) - public void testWbgetentities_emptyIdList() { - WikidataActionApiQuery.wbgetentities(Collections.emptyList()); - } - - @Test(expected = IllegalArgumentException.class) - public void testWbgetentitiesLabels_invalidQid() { - WikidataActionApiQuery.wbgetentitiesLabels("X1"); + @Test + void testWbgetentitiesLabelsInvalidQid() { + assertThrows(IllegalArgumentException.class, () -> WikidataActionApiQuery.wbgetentitiesLabels("X1")); } @Test - public void testApiName() { + void testApiName() { assertEquals("Wikidata Action API", WikidataActionApiQuery.wbgetentitiesClaims("Q1").getApiName()); assertEquals("Wikidata Action API", WikidataActionApiQuery.sitematrix().getApiName()); } - @Test(expected = IllegalArgumentException.class) - public void testWbgetclaims_invalidQid() { - WikidataActionApiQuery.wbgetentitiesClaims("123"); + @Test + void testWbgetclaimsInvalidQid() { + assertThrows(IllegalArgumentException.class, () -> WikidataActionApiQuery.wbgetentitiesClaims("123")); } @Test - public void testWbgetentitiesQuery() { + void testWbgetentitiesQuery() { assertEquals( "action=wbgetentities&format=json&formatversion=2&ids=Q1&props=&sites=&utf8=1", WikidataActionApiQuery.wbgetentities(Collections.singletonList("Q1")).getQueryString().toString() @@ -68,7 +69,7 @@ public void testWbgetentitiesQuery() { } @Test - public void testWikidataForArticles1() throws IOException, URISyntaxException { + void testWikidataForArticles1() throws IOException, URISyntaxException { final WikipediaSite site = siteFromStub("de"); simpleJsonStub(ResourceFileLoader.getResourceBytes(WikidataActionApiQueryTest.class, "response/wbgetentities/dewiki_Berlin.json")); @@ -90,7 +91,7 @@ public void testWikidataForArticles1() throws IOException, URISyntaxException { } @Test - public void testWikidataForArticles2() throws IOException, URISyntaxException { + void testWikidataForArticles2() throws IOException, URISyntaxException { final WikipediaSite site = siteFromStub("en"); simpleJsonStub(ResourceFileLoader.getResourceBytes(WikidataActionApiQueryTest.class, "response/wbgetentities/enwiki_2entities2missing.json")); @@ -122,7 +123,7 @@ public void testWikidataForArticles2() throws IOException, URISyntaxException { } @Test - public void testWikidataItemLabelQuery() throws IOException, URISyntaxException { + void testWikidataItemLabelQuery() throws IOException, URISyntaxException { simpleJsonStub(ResourceFileLoader.getResourceBytes(WikidataActionApiQueryTest.class, "response/wbgetentities/labels_Q42.json")); final Optional result = ApiQueryClient.query(WikidataActionApiQuery.wbgetentitiesLabels("Q42")); diff --git a/test/unit/org/wikipedia/api/wikidata_action/WikidataActionApiTestAbstract.java b/test/unit/org/wikipedia/api/wikidata_action/WikidataActionApiTestAbstract.java index 7eeb0610..304f8372 100644 --- a/test/unit/org/wikipedia/api/wikidata_action/WikidataActionApiTestAbstract.java +++ b/test/unit/org/wikipedia/api/wikidata_action/WikidataActionApiTestAbstract.java @@ -8,11 +8,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.verify; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import com.github.tomakehurst.wiremock.client.MappingBuilder; -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import com.github.tomakehurst.wiremock.matching.EqualToPattern; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -20,28 +16,27 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.stream.Collectors; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.openstreetmap.josm.testutils.JOSMTestRules; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.wikipedia.data.WikipediaSite; +import com.github.tomakehurst.wiremock.client.MappingBuilder; +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import com.github.tomakehurst.wiremock.matching.EqualToPattern; + // Name must not end in "Test", so "Abstract" put at the end. +@WireMockTest public abstract class WikidataActionApiTestAbstract { - @Rule - public WireMockRule wmRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public JOSMTestRules josmRule = new JOSMTestRules().preferences(); - private URL oldDefaultUrl = null; - @Before - public void before() throws MalformedURLException { - oldDefaultUrl = setApiUrl(new URL("http://localhost:" + wmRule.port())); + @BeforeEach + public void before(WireMockRuntimeInfo wmRuntimeInfo) throws MalformedURLException { + oldDefaultUrl = setApiUrl(new URL(wmRuntimeInfo.getHttpBaseUrl())); } - @After + @AfterEach public void after() { setApiUrl(oldDefaultUrl); } diff --git a/test/unit/org/wikipedia/api/wikipedia_action/WikipediaActionApiQueryTest.java b/test/unit/org/wikipedia/api/wikipedia_action/WikipediaActionApiQueryTest.java index e779a6b0..472286dd 100644 --- a/test/unit/org/wikipedia/api/wikipedia_action/WikipediaActionApiQueryTest.java +++ b/test/unit/org/wikipedia/api/wikipedia_action/WikipediaActionApiQueryTest.java @@ -8,34 +8,29 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.verify; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -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.assertTrue; -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import com.github.tomakehurst.wiremock.matching.EqualToPattern; import java.io.IOException; import java.net.URISyntaxException; import java.util.Arrays; -import org.junit.Rule; -import org.junit.Test; -import org.openstreetmap.josm.testutils.JOSMTestRules; + +import org.junit.jupiter.api.Test; import org.wikipedia.api.ApiQueryClient; import org.wikipedia.api.wikidata_action.json.SitematrixResult; import org.wikipedia.api.wikipedia_action.json.QueryResult; import org.wikipedia.data.IWikipediaSite; import org.wikipedia.testutils.ResourceFileLoader; -public class WikipediaActionApiQueryTest { - - @Rule - public WireMockRule wmRule = new WireMockRule(wireMockConfig().dynamicPort()); +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import com.github.tomakehurst.wiremock.matching.EqualToPattern; - @Rule - public JOSMTestRules josmRule = new JOSMTestRules().preferences(); +@WireMockTest +class WikipediaActionApiQueryTest { @Test - public void test() throws IOException, URISyntaxException { + void test(WireMockRuntimeInfo wmRuntimeInfo) throws IOException, URISyntaxException { stubFor(post("/w/api.php") .withHeader("Accept", equalTo("application/json")) .willReturn( @@ -47,7 +42,7 @@ public void test() throws IOException, URISyntaxException { ); final QueryResult result = ApiQueryClient.query( - WikipediaActionApiQuery.query(new WikiSiteMock("en").getSite(), Arrays.asList("US", "USA", "Universe", "united states")) + WikipediaActionApiQuery.query(new WikiSiteMock(wmRuntimeInfo, "en").getSite(), Arrays.asList("US", "USA", "Universe", "united states")) ); assertEquals("United States", result.getQuery().resolveRedirect("USA")); @@ -65,16 +60,18 @@ public void test() throws IOException, URISyntaxException { .withRequestBody(new EqualToPattern("action=query&format=json&formatversion=2&redirects=1&titles=US%7CUSA%7CUniverse%7Cunited+states&utf8=1"))); } - private class WikiSiteMock implements IWikipediaSite { + private static class WikiSiteMock implements IWikipediaSite { private final String langCode; + private final String url; - private WikiSiteMock(final String langCode) { + private WikiSiteMock(WireMockRuntimeInfo wmRuntimeInfo, final String langCode) { this.langCode = langCode; + this.url = wmRuntimeInfo.getHttpBaseUrl(); } @Override public SitematrixResult.Sitematrix.Site getSite() { - return new SitematrixResult.Sitematrix.Site("http://localhost:" + wmRule.port(), "dbname", "code", "false", "Wikipedia"); + return new SitematrixResult.Sitematrix.Site(this.url, "dbname", "code", "false", "Wikipedia"); } @Override diff --git a/test/unit/org/wikipedia/data/WikipediaEntryTest.java b/test/unit/org/wikipedia/data/WikipediaEntryTest.java index 42384dd6..58281162 100644 --- a/test/unit/org/wikipedia/data/WikipediaEntryTest.java +++ b/test/unit/org/wikipedia/data/WikipediaEntryTest.java @@ -2,83 +2,57 @@ package org.wikipedia.data; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; -import java.util.Optional; -import org.junit.Rule; -import org.junit.Test; -import org.openstreetmap.josm.testutils.JOSMTestRules; +import java.util.stream.Stream; -public class WikipediaEntryTest { +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; - @Rule - public JOSMTestRules rules = new JOSMTestRules(); - - @Test - public void testParseFromUrl1() { - final Optional actual = WikipediaEntry.fromUrl("https://de.wikipedia.org/wiki/Österreich"); - assertThat(actual.get().article, is("Österreich")); - assertThat(actual.get().lang, is("de")); - } - - @Test - public void testParseFromUrl2() { - final Optional actual = WikipediaEntry.fromUrl("http://de.m.wikipedia.org/wiki/%C3%96sterreich"); - assertThat(actual.get().article, is("Österreich")); - assertThat(actual.get().lang, is("de")); - } - - @Test - public void testParseFromUrl3() { - final Optional actual = WikipediaEntry.fromUrl("http://de.wikipedia.org/wiki/Sternheim_%26_Emanuel"); - assertThat(actual.get().article, is("Sternheim & Emanuel")); - assertThat(actual.get().lang, is("de")); - } - - @Test - public void testParseFromUrl4() { - final Optional actual = WikipediaEntry.fromUrl("//de.wikipedia.org/wiki/Reichstagsgeb%C3%A4ude"); - assertThat(actual.get().article, is("Reichstagsgebäude")); - assertThat(actual.get().lang, is("de")); - } - - @Test - public void testParseFromTag0() { - final WikipediaEntry actual = WikipediaEntry.parseTag("wikipedia", "Österreich"); - assertThat(actual, nullValue()); - } - - @Test - public void testParseFromTag1() { - final WikipediaEntry actual = WikipediaEntry.parseTag("wikipedia", "de:Österreich"); - assertThat(actual.article, is("Österreich")); - assertThat(actual.lang, is("de")); +class WikipediaEntryTest { + static Stream testParseFromUrl() { + return Stream.of(Arguments.of("https://de.wikipedia.org/wiki/Österreich", "Österreich", "de"), + Arguments.of("http://de.m.wikipedia.org/wiki/%C3%96sterreich", "Österreich", "de"), + Arguments.of("http://de.wikipedia.org/wiki/Sternheim_%26_Emanuel", "Sternheim & Emanuel", "de"), + Arguments.of("//de.wikipedia.org/wiki/Reichstagsgeb%C3%A4ude", "Reichstagsgebäude", "de")); } - @Test - public void testParseFromTag2() { - final WikipediaEntry actual = WikipediaEntry.parseTag("wikipedia:de", "Österreich"); - assertThat(actual.article, is("Österreich")); - assertThat(actual.lang, is("de")); + @ParameterizedTest + @MethodSource + void testParseFromUrl(String url, String article, String lang) { + final WikipediaEntry actual = WikipediaEntry.fromUrl(url).orElseThrow(AssertionError::new); + assertEquals(article, actual.article); + assertEquals(lang, actual.lang); } - @Test - public void testParseFromTag3() { - final WikipediaEntry actual = WikipediaEntry.parseTag("wikipedia:de", "de:Österreich"); - assertThat(actual.article, is("Österreich")); - assertThat(actual.lang, is("de")); + static Stream testParseFromTag() { + return Stream.of(Arguments.of("wikipedia", "Österreich", null, null), + Arguments.of("wikipedia", "de:Österreich", "Österreich", "de"), + Arguments.of("wikipedia:de", "Österreich", "Österreich", "de"), + Arguments.of("wikipedia:de", "de:Österreich", "Österreich", "de"), + Arguments.of("wikipedia", "https://de.wikipedia.org/wiki/Österreich", "Österreich", "de")); } - @Test - public void testParseFromTag4() { - final WikipediaEntry actual = WikipediaEntry.parseTag("wikipedia", "https://de.wikipedia.org/wiki/Österreich"); - assertThat(actual.article, is("Österreich")); - assertThat(actual.lang, is("de")); + @ParameterizedTest + @MethodSource + void testParseFromTag(String key, String value, String article, String lang) { + final WikipediaEntry actual = WikipediaEntry.parseTag(key, value); + if (article == null && lang == null) { + assertNull(actual); + } else { + assertNotNull(actual); + assertEquals(article, actual.article); + assertEquals(lang, actual.lang); + } } @Test - public void testGetBrowserUrl() { + void testGetBrowserUrl() { final WikipediaEntry entry = new WikipediaEntry("de", "Sternheim & Emanuel"); assertThat(entry.getBrowserUrl().get(), is("https://de.wikipedia.org/wiki/Sternheim_%26_Emanuel")); } diff --git a/test/unit/org/wikipedia/data/WikipediaSiteTest.java b/test/unit/org/wikipedia/data/WikipediaSiteTest.java index 165e385f..62d46865 100644 --- a/test/unit/org/wikipedia/data/WikipediaSiteTest.java +++ b/test/unit/org/wikipedia/data/WikipediaSiteTest.java @@ -1,19 +1,22 @@ // License: GPL. For details, see LICENSE file. package org.wikipedia.data; -import static org.junit.Assert.assertEquals; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.net.URISyntaxException; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.wikipedia.api.wikidata_action.WikidataActionApiQueryTest; import org.wikipedia.api.wikidata_action.WikidataActionApiTestAbstract; import org.wikipedia.testutils.ResourceFileLoader; -public class WikipediaSiteTest extends WikidataActionApiTestAbstract { +class WikipediaSiteTest extends WikidataActionApiTestAbstract { @Test - public void testSites() throws IOException, URISyntaxException { + void testSites() throws IOException, URISyntaxException { simpleJsonStub(ResourceFileLoader.getResourceBytes(WikidataActionApiQueryTest.class, "response/sitematrix/sitematrix.json")); assertEquals("https://de.wikipedia.org", new WikipediaSite("de").getSite().getUrl()); @@ -23,9 +26,9 @@ public void testSites() throws IOException, URISyntaxException { assertEquals("https://zh-min-nan.wikipedia.org", new WikipediaSite("zh-min-nan").getSite().getUrl()); } - @Test(expected = IllegalArgumentException.class) - public void testUnknownSite() throws IOException, URISyntaxException { + @Test + void testUnknownSite() throws IOException, URISyntaxException { simpleJsonStub(ResourceFileLoader.getResourceBytes(WikidataActionApiQueryTest.class, "response/sitematrix/sitematrix.json")); - new WikipediaSite("xy"); + assertThrows(IllegalArgumentException.class, () -> new WikipediaSite("xy")); } } diff --git a/test/unit/org/wikipedia/gui/WikiPreferencesTest.java b/test/unit/org/wikipedia/gui/WikiPreferencesTest.java index 8796c448..72c1ecbf 100644 --- a/test/unit/org/wikipedia/gui/WikiPreferencesTest.java +++ b/test/unit/org/wikipedia/gui/WikiPreferencesTest.java @@ -1,20 +1,14 @@ // License: GPL. For details, see LICENSE file. package org.wikipedia.gui; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; -import org.openstreetmap.josm.testutils.JOSMTestRules; - -public class WikiPreferencesTest { - - @Rule - public JOSMTestRules test = new JOSMTestRules(); +class WikiPreferencesTest { @Test - public void testAddGui() { + void testAddGui() { final WikiPreferences setting = new WikiPreferences(); final PreferenceTabbedPane tabPane = new PreferenceTabbedPane(); tabPane.buildGui(); diff --git a/test/unit/org/wikipedia/gui/WikidataTagCellRendererTest.java b/test/unit/org/wikipedia/gui/WikidataTagCellRendererTest.java index 627d446a..ac114c65 100644 --- a/test/unit/org/wikipedia/gui/WikidataTagCellRendererTest.java +++ b/test/unit/org/wikipedia/gui/WikidataTagCellRendererTest.java @@ -3,27 +3,22 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.Arrays; import java.util.List; import java.util.Optional; + import javax.swing.JLabel; import javax.swing.JTable; -import org.junit.Rule; -import org.junit.Test; -import org.openstreetmap.josm.testutils.JOSMTestRules; - -public class WikidataTagCellRendererTest { - /** - * Setup test. - */ - @Rule - public JOSMTestRules rules = new JOSMTestRules().preferences().i18n("en"); +import org.junit.jupiter.api.Test; +import org.openstreetmap.josm.testutils.annotations.I18n; +@I18n +class WikidataTagCellRendererTest { @Test - public void testRenderLabel() throws Exception { + void testRenderLabel() throws Exception { final List ids = Arrays.asList("Q84", "Q1741", "Q278250"); final WikidataTagCellRenderer renderer = new WikidataTagCellRenderer(); renderer.renderValues(ids, new JTable(), new JLabel(), Optional.empty()); diff --git a/test/unit/org/wikipedia/io/SophoxDownloadReaderTest.java b/test/unit/org/wikipedia/io/SophoxDownloadReaderTest.java index 20ca2dbc..248fa809 100644 --- a/test/unit/org/wikipedia/io/SophoxDownloadReaderTest.java +++ b/test/unit/org/wikipedia/io/SophoxDownloadReaderTest.java @@ -4,37 +4,27 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; -import org.junit.Rule; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.openstreetmap.josm.data.osm.OsmPrimitiveType; import org.openstreetmap.josm.data.osm.PrimitiveId; import org.openstreetmap.josm.data.osm.SimplePrimitiveId; -import org.openstreetmap.josm.testutils.JOSMTestRules; /** * Unit tests of {@link SophoxDownloadReader} class. */ -public class SophoxDownloadReaderTest { - - /** - * Base test environment is enough - */ - @Rule - @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - public JOSMTestRules test = new JOSMTestRules().preferences(); - +class SophoxDownloadReaderTest { /** * Tests point generation */ @Test - public void testPoint() { + void testPoint() { assertThat(SophoxDownloadReader.point(9.5, 47.16), is("\"Point(9.5 47.16)\"^^geo:wktLiteral")); assertThat(SophoxDownloadReader.boxParams(1.1, 2.2, 3.3, 4.4), @@ -47,7 +37,7 @@ public void testPoint() { * @throws UnsupportedEncodingException if an error occurs */ @Test - public void testIdParsing() throws UnsupportedEncodingException { + void testIdParsing() throws UnsupportedEncodingException { String json = String.join("\n", "{\"results\":{\"bindings\":[", "{\"a\":{\"type\": \"uri\", \"value\": \"https://www.openstreetmap.org/node/12345\"}},", diff --git a/test/unit/org/wikipedia/testutils/JunitJupiterCompatUtil.java b/test/unit/org/wikipedia/testutils/JunitJupiterCompatUtil.java index 22eada2b..19bf3240 100644 --- a/test/unit/org/wikipedia/testutils/JunitJupiterCompatUtil.java +++ b/test/unit/org/wikipedia/testutils/JunitJupiterCompatUtil.java @@ -1,6 +1,6 @@ package org.wikipedia.testutils; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class JunitJupiterCompatUtil { @@ -8,6 +8,7 @@ private JunitJupiterCompatUtil() { // Private constructor to avoid instantiation } + @Deprecated public static void assertThrows(Class expectedType, Runnable runnable) { boolean success = false; Throwable throwable = null; @@ -17,6 +18,6 @@ public static void assertThrows(Class expectedType, Run success = expectedType.isInstance(t); throwable = t; } - assertTrue("Expected " + expectedType.getName() + " but was " + (throwable == null ? "null" : throwable.getClass().getName()), success); + assertTrue(success, "Expected " + expectedType.getName() + " but was " + (throwable == null ? "null" : throwable.getClass().getName())); } } diff --git a/test/unit/org/wikipedia/tools/OsmPrimitiveUtilTest.java b/test/unit/org/wikipedia/tools/OsmPrimitiveUtilTest.java index 76cc21e1..0d64ca14 100644 --- a/test/unit/org/wikipedia/tools/OsmPrimitiveUtilTest.java +++ b/test/unit/org/wikipedia/tools/OsmPrimitiveUtilTest.java @@ -1,29 +1,25 @@ package org.wikipedia.tools; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.Optional; -import org.junit.Rule; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.openstreetmap.josm.data.osm.Node; import org.openstreetmap.josm.data.osm.Relation; import org.openstreetmap.josm.data.osm.Way; -import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.tools.Pair; import org.wikipedia.data.IWikipediaSite; import org.wikipedia.data.WikipediaSite; -public class OsmPrimitiveUtilTest { - - @Rule - public JOSMTestRules rules = new JOSMTestRules(); +class OsmPrimitiveUtilTest { @Test - public void testWikidata() { + void testWikidata() { assertFalse(OsmPrimitiveUtil.getWikidataValue(new Node()).isPresent()); final Node wdNode = new Node(); @@ -33,7 +29,7 @@ public void testWikidata() { } @Test - public void testWikipedia() throws IOException { + void testWikipedia() throws IOException { assertFalse(OsmPrimitiveUtil.getWikipediaValue(new Relation()).isPresent()); final Way wpWay = new Way(); @@ -46,7 +42,7 @@ public void testWikipedia() throws IOException { } @Test - public void testWithNonExistentWikipediaSite() { + void testWithNonExistentWikipediaSite() { final Way wpWay = new Way(); wpWay.put("wikipedia", "xx:Wikipedia"); assertFalse(OsmPrimitiveUtil.getWikipediaValue(wpWay).isPresent()); diff --git a/test/unit/org/wikipedia/validator/AllValidationTestsTest.java b/test/unit/org/wikipedia/validator/AllValidationTestsTest.java index b491c400..d7957d5f 100644 --- a/test/unit/org/wikipedia/validator/AllValidationTestsTest.java +++ b/test/unit/org/wikipedia/validator/AllValidationTestsTest.java @@ -1,25 +1,20 @@ // License: GPL. For details, see LICENSE file. package org.wikipedia.validator; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import org.junit.Rule; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.openstreetmap.josm.data.osm.Way; import org.openstreetmap.josm.data.validation.TestError; -import org.openstreetmap.josm.testutils.JOSMTestRules; - -public class AllValidationTestsTest { - @Rule - public JOSMTestRules rules = new JOSMTestRules() - .preferences(); // The Severity class needs access to the preferences +class AllValidationTestsTest { @Test - public void testValidationTestFields() throws IllegalAccessException { + void testValidationTestFields() throws IllegalAccessException { final Field[] fields = AllValidationTests.class.getDeclaredFields(); for (Field field : fields) { if ((field.getModifiers() & Modifier.PRIVATE) == 0) { @@ -39,9 +34,9 @@ private static void testValidationTestField(final AllValidationTests.ValidationT .message("dummy message") .primitives(new Way()) .build(); - assertTrue("The code of a validation test must be at least 30,000", te.getCode() >= 30_000); - assertTrue("The code of a validation test must be lower than 31,000", te.getCode() < 31_000); - assertNotNull("The severity of a validation test must be non-null", te.getSeverity()); + assertTrue(te.getCode() >= 30_000, "The code of a validation test must be at least 30,000"); + assertTrue(te.getCode() < 31_000, "The code of a validation test must be lower than 31,000"); + assertNotNull(te.getSeverity(), "The severity of a validation test must be non-null"); System.out.println(" \uD83D\uDDF8"); } }