1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.properties;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
6 |
|
---|
7 | import javax.swing.Action;
|
---|
8 |
|
---|
9 | import org.junit.jupiter.api.Test;
|
---|
10 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
11 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
12 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
13 |
|
---|
14 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
15 |
|
---|
16 | class TaginfoActionTest {
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Setup test.
|
---|
20 | */
|
---|
21 | @RegisterExtension
|
---|
22 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
23 | public JOSMTestRules test = new JOSMTestRules();
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Unit test of {@link TaginfoAction#getTaginfoUrlForTag} and {@link TaginfoAction#getTaginfoUrlForRelationType}
|
---|
27 | */
|
---|
28 | @Test
|
---|
29 | void testTaginfoUrls() {
|
---|
30 | TaginfoAction action = new TaginfoAction(() -> null, () -> null);
|
---|
31 | assertEquals("https://taginfo.openstreetmap.org/keys/railway", action.getTaginfoUrlForTag(new Tag("railway")));
|
---|
32 | assertEquals("https://taginfo.openstreetmap.org/tags/railway=tram", action.getTaginfoUrlForTag(new Tag("railway", "tram")));
|
---|
33 | assertEquals("https://taginfo.openstreetmap.org/tags/addr%3Acity=Bassum%3ACity",
|
---|
34 | action.getTaginfoUrlForTag(new Tag("addr:city", "Bassum:City")));
|
---|
35 | assertEquals("https://taginfo.openstreetmap.org/relations/route", action.getTaginfoUrlForRelationType("route"));
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Unit test of {@link TaginfoAction#toTagHistoryAction()}
|
---|
40 | */
|
---|
41 | @Test
|
---|
42 | void testCustomInstance() {
|
---|
43 | TaginfoAction action = new TaginfoAction(() -> null, () -> null).withTaginfoUrl("example.com", "https://taginfo.example.com////");
|
---|
44 | assertEquals("example.com", action.getValue(Action.NAME));
|
---|
45 | assertEquals("https://taginfo.example.com/keys/railway", action.getTaginfoUrlForTag(new Tag("railway")));
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Unit test of {@link TaginfoAction#toTagHistoryAction()}
|
---|
50 | */
|
---|
51 | @Test
|
---|
52 | void testTagHistoryUrls() {
|
---|
53 | TaginfoAction action = new TaginfoAction(() -> null, () -> null).toTagHistoryAction();
|
---|
54 | assertEquals("https://taghistory.raifer.tech/#***/railway/", action.getTaginfoUrlForTag(new Tag("railway")));
|
---|
55 | assertEquals("https://taghistory.raifer.tech/#***/railway/tram", action.getTaginfoUrlForTag(new Tag("railway", "tram")));
|
---|
56 | assertEquals("https://taghistory.raifer.tech/#***/addr:city/Bassum:City",
|
---|
57 | action.getTaginfoUrlForTag(new Tag("addr:city", "Bassum:City")));
|
---|
58 | assertNull(action.getTaginfoUrlForRelationType("route"));
|
---|
59 | }
|
---|
60 | }
|
---|