source: josm/trunk/test/unit/org/openstreetmap/josm/tools/Tag2LinkTest.java@ 16774

Last change on this file since 16774 was 16774, checked in by simon04, 4 years ago

fix #19293 - Tag2link/wikipedia: replace space with underscore

File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import java.util.ArrayList;
5import java.util.Arrays;
6import java.util.List;
7
8import org.junit.Assert;
9import org.junit.Test;
10
11/**
12 * Test {@link Tag2Link}
13 */
14public class Tag2LinkTest {
15
16 List<String> links = new ArrayList<>();
17
18 void addLink(String name, String url) {
19 links.add(name + " // " + url);
20 }
21
22 void checkLinks(String... expected) {
23 Assert.assertEquals(Arrays.asList(expected), links);
24 }
25
26 /**
27 * Unit test of function {@link Tag2Link#initialize()}.
28 */
29 @Test
30 public void testInitialize() {
31 Tag2Link.initialize();
32 Assert.assertTrue("obtains at least 40 rules", Tag2Link.wikidataRules.size() > 40);
33 }
34
35 /**
36 * Unit test of function {@link Tag2Link#getLinksForTag}.
37 */
38 @Test
39 public void testWebsite() {
40 Tag2Link.getLinksForTag("website", "http://www.openstreetmap.org/", this::addLink);
41 checkLinks("Open www.openstreetmap.org // http://www.openstreetmap.org/");
42 links.clear();
43 Tag2Link.getLinksForTag("website", "https://www.openstreetmap.org/", this::addLink);
44 checkLinks("Open www.openstreetmap.org // https://www.openstreetmap.org/");
45 links.clear();
46 Tag2Link.getLinksForTag("website", "www.openstreetmap.org", this::addLink);
47 checkLinks("Open www.openstreetmap.org // http://www.openstreetmap.org");
48 }
49
50 /**
51 * Unit test of function {@link Tag2Link#getLinksForTag}.
52 */
53 @Test
54 public void testWikipedia() {
55 Tag2Link.getLinksForTag("wikipedia", "de:Wohnhausgruppe Herderstraße", this::addLink);
56 checkLinks("View Wikipedia article // https://de.wikipedia.org/wiki/Wohnhausgruppe_Herderstraße");
57 links.clear();
58 Tag2Link.getLinksForTag("wikipedia", "de:Stadtbahn Köln#Innenstadttunnel", this::addLink);
59 checkLinks("View Wikipedia article // https://de.wikipedia.org/wiki/Stadtbahn_Köln#Innenstadttunnel");
60 }
61
62 /**
63 * Unit test of function {@link Tag2Link#getLinksForTag}.
64 */
65 @Test
66 public void testImageCommonsImage() {
67 Tag2Link.getLinksForTag("image", "File:Witten Brücke Gasstraße.jpg", this::addLink);
68 checkLinks("View image on Wikimedia Commons // https://commons.wikimedia.org/wiki/File:Witten Brücke Gasstraße.jpg");
69 }
70
71 /**
72 * Unit test of function {@link Tag2Link#getLinksForTag}.
73 */
74 @Test
75 public void testImageCommonsCategory() {
76 Tag2Link.getLinksForTag("image", "category:JOSM", this::addLink);
77 checkLinks("View category on Wikimedia Commons // https://commons.wikimedia.org/wiki/category:JOSM");
78 }
79
80 /**
81 * Unit test of function {@link Tag2Link#getLinksForTag}.
82 */
83 @Test
84 public void testBrandWikidata() {
85 Tag2Link.getLinksForTag("brand:wikidata", "Q259340", this::addLink);
86 checkLinks("View Wikidata item // https://www.wikidata.org/wiki/Q259340");
87 }
88
89 /**
90 * Unit test of function {@link Tag2Link#getLinksForTag}.
91 */
92 @Test
93 public void testArchipelagoWikidata() {
94 Tag2Link.getLinksForTag("archipelago:wikidata", "Q756987;Q756988", this::addLink);
95 checkLinks("View Wikidata item // https://www.wikidata.org/wiki/Q756987",
96 "View Wikidata item // https://www.wikidata.org/wiki/Q756988");
97 }
98
99}
Note: See TracBrowser for help on using the repository browser.