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

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

fix #19620 - Tag2Link: allow to customize sources

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