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