1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.Arrays;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import org.junit.Assert;
|
---|
9 | import org.junit.Test;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Test {@link Tag2Link}
|
---|
13 | */
|
---|
14 | public 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 | }
|
---|