Commit 492ddf92 authored by Florian Schäfer's avatar Florian Schäfer

Add unit test for `OsmPrimitiveUtil`

parent 0f7fa139
Pipeline #39505331 failed with stages
in 9 minutes and 34 seconds
......@@ -127,7 +127,7 @@ public class WikipediaAppTest {
}
@Test
public void testTicket13991() throws Exception {
public 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")));
......
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 java.io.IOException;
import java.util.Optional;
import org.junit.Rule;
import org.junit.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;
import org.wikipedia.tools.OsmPrimitiveUtil;
public class OsmPrimitiveUtilTest {
@Rule
public JOSMTestRules rules = new JOSMTestRules();
@Test
public void testWikidata() {
assertFalse(OsmPrimitiveUtil.getWikidataValue(new Node()).isPresent());
final Node wdNode = new Node();
wdNode.put("wikidata", "Q1");
assertEquals("Q1", OsmPrimitiveUtil.getWikidataValue(wdNode).get());
assertFalse(OsmPrimitiveUtil.getWikipediaValue(wdNode).isPresent());
}
@Test
public void testWikipedia() throws IOException {
assertFalse(OsmPrimitiveUtil.getWikipediaValue(new Relation()).isPresent());
final Way wpWay = new Way();
wpWay.put("wikipedia", "en:London");
final Optional<Pair<IWikipediaSite, String>> result = OsmPrimitiveUtil.getWikipediaValue(wpWay);
assertTrue(result.isPresent());
assertEquals(new WikipediaSite("en").getLanguageCode(), result.get().a.getLanguageCode());
assertNotNull( result.get().a.getSite());
assertEquals("London", result.get().b);
}
@Test
public void testWithNonExistentWikipediaSite() {
final Way wpWay = new Way();
wpWay.put("wikipedia", "xx:Wikipedia");
assertFalse(OsmPrimitiveUtil.getWikipediaValue(wpWay).isPresent());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment