1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm.history;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
6 |
|
---|
7 | import java.util.Date;
|
---|
8 | import java.util.HashMap;
|
---|
9 | import java.util.Map;
|
---|
10 |
|
---|
11 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
12 | import org.junit.jupiter.api.Test;
|
---|
13 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
14 | import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
17 | import org.openstreetmap.josm.data.osm.User;
|
---|
18 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
19 |
|
---|
20 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Unit tests for class {@link HistoryNode}.
|
---|
24 | */
|
---|
25 | class HistoryNodeTest {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Setup test.
|
---|
29 | */
|
---|
30 | @RegisterExtension
|
---|
31 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
32 | public JOSMTestRules test = new JOSMTestRules();
|
---|
33 |
|
---|
34 | private static HistoryNode create(Date d) {
|
---|
35 | return new HistoryNode(
|
---|
36 | 1L, // id
|
---|
37 | 2L, // version
|
---|
38 | true, // visible
|
---|
39 | User.createOsmUser(3, "testuser"),
|
---|
40 | 4L, // changesetId
|
---|
41 | d, // timestamp
|
---|
42 | LatLon.ZERO
|
---|
43 | );
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Unit test for {@link HistoryNode#HistoryNode}.
|
---|
48 | */
|
---|
49 | @Test
|
---|
50 | void testHistoryNode() {
|
---|
51 | Date d = new Date();
|
---|
52 | HistoryNode node = create(d);
|
---|
53 |
|
---|
54 | assertEquals(1, node.getId());
|
---|
55 | assertEquals(2, node.getVersion());
|
---|
56 | assertTrue(node.isVisible());
|
---|
57 | assertEquals("testuser", node.getUser().getName());
|
---|
58 | assertEquals(3, node.getUser().getId());
|
---|
59 | assertEquals(4, node.getChangesetId());
|
---|
60 | assertEquals(d, node.getTimestamp());
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Unit test for {@link HistoryNode#getType}.
|
---|
65 | */
|
---|
66 | @Test
|
---|
67 | void testGetType() {
|
---|
68 | assertEquals(OsmPrimitiveType.NODE, create(new Date()).getType());
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Unit test for {@link HistoryNode#getCoords}.
|
---|
73 | */
|
---|
74 | @Test
|
---|
75 | void testGetCoords() {
|
---|
76 | Node n = new Node(new LatLon(45, 0));
|
---|
77 | n.setOsmId(1, 2);
|
---|
78 | n.setUser(User.createOsmUser(3, "testuser"));
|
---|
79 | n.setChangesetId(4);
|
---|
80 | assertEquals(n.getCoor(), new HistoryNode(n).getCoords());
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Unit test for {@link HistoryNode#getDisplayName}.
|
---|
85 | */
|
---|
86 | @Test
|
---|
87 | void testGetDisplayName() {
|
---|
88 | HistoryNode node = create(new Date());
|
---|
89 | HistoryNameFormatter hnf = DefaultNameFormatter.getInstance();
|
---|
90 | assertEquals("1 (0.0, 0.0)", node.getDisplayName(hnf));
|
---|
91 | LatLon ll = node.getCoords();
|
---|
92 | node.setCoords(null);
|
---|
93 | assertEquals("1", node.getDisplayName(hnf));
|
---|
94 | node.setCoords(ll);
|
---|
95 | Map<String, String> map = new HashMap<>();
|
---|
96 | map.put("name", "NodeName");
|
---|
97 | node.setTags(map);
|
---|
98 | assertEquals("NodeName (0.0, 0.0)", node.getDisplayName(hnf));
|
---|
99 | node.setCoords(null);
|
---|
100 | assertEquals("NodeName", node.getDisplayName(hnf));
|
---|
101 | }
|
---|
102 | }
|
---|