source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/NodeTest.java@ 17275

Last change on this file since 17275 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

File size: 4.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertFalse;
6import static org.junit.jupiter.api.Assertions.assertNotNull;
7import static org.junit.jupiter.api.Assertions.assertNull;
8import static org.junit.jupiter.api.Assertions.assertTrue;
9import static org.junit.jupiter.api.Assertions.assertThrows;
10
11import org.junit.jupiter.api.Test;
12import org.junit.jupiter.api.extension.RegisterExtension;
13import org.openstreetmap.josm.data.Bounds;
14import org.openstreetmap.josm.data.DataSource;
15import org.openstreetmap.josm.data.coor.EastNorth;
16import org.openstreetmap.josm.data.coor.LatLon;
17import org.openstreetmap.josm.testutils.JOSMTestRules;
18
19import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
20
21/**
22 * Unit tests of the {@code Node} class.
23 */
24class NodeTest {
25
26 /**
27 * Setup test.
28 */
29 @RegisterExtension
30 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
31 public JOSMTestRules test = new JOSMTestRules().projection();
32
33 /**
34 * Non-regression test for ticket #12060.
35 */
36 @Test
37 void testTicket12060() {
38 DataSet ds = new DataSet();
39 ds.addDataSource(new DataSource(new Bounds(LatLon.ZERO), null));
40 Node n = new Node(1, 1);
41 n.setCoor(LatLon.ZERO);
42 ds.addPrimitive(n);
43 n.setCoor(null);
44 assertFalse(n.isNewOrUndeleted());
45 assertNotNull(ds.getDataSourceArea());
46 assertNull(n.getCoor());
47 assertFalse(n.isOutsideDownloadArea());
48 }
49
50 /**
51 * Test BBox calculation with Node
52 */
53 @Test
54 void testBBox() {
55 DataSet ds = new DataSet();
56 Node n1 = new Node(1);
57 Node n2 = new Node(2);
58 Node n3 = new Node(3);
59 Node n4 = new Node(4);
60 n1.setIncomplete(true);
61 n2.setCoor(new LatLon(10, 10));
62 n3.setCoor(new LatLon(20, 20));
63 n4.setCoor(new LatLon(90, 180));
64 ds.addPrimitive(n1);
65 ds.addPrimitive(n2);
66 ds.addPrimitive(n3);
67 ds.addPrimitive(n4);
68
69 assertFalse(n1.getBBox().isValid());
70 assertTrue(n2.getBBox().isValid());
71 assertTrue(n3.getBBox().isValid());
72 assertTrue(n4.getBBox().isValid());
73 BBox box1 = n1.getBBox();
74 box1.add(n2.getCoor());
75 assertTrue(box1.isValid());
76 BBox box2 = n2.getBBox();
77 box2.add(n1.getCoor());
78 assertTrue(box2.isValid());
79 assertEquals(box1, box2);
80 box1.add(n3.getCoor());
81 assertTrue(box1.isValid());
82 assertEquals(box1.getCenter(), new LatLon(15, 15));
83 }
84
85 /**
86 * Test that {@link Node#cloneFrom} throws IAE for invalid arguments
87 */
88 @Test
89 void testCloneFromIAE() {
90 assertThrows(IllegalArgumentException.class, () -> new Node().cloneFrom(new Way()));
91 }
92
93 /**
94 * Test that {@link Node#mergeFrom} throws IAE for invalid arguments
95 */
96 @Test
97 void testMergeFromIAE() {
98 assertThrows(IllegalArgumentException.class, () -> new Node().mergeFrom(new Way()));
99 }
100
101 /**
102 * Test that {@link Node#load} throws IAE for invalid arguments
103 */
104 @Test
105 void testLoadIAE() {
106 assertThrows(IllegalArgumentException.class, () -> new Node().load(new WayData()));
107 }
108
109 /**
110 * Test that {@link Node#isOutSideWorld} works as expected.
111 */
112 @Test
113 void testOutsideWorld() {
114 Node n = new Node(1, 1);
115 n.setCoor(LatLon.ZERO);
116 assertFalse(n.isOutSideWorld());
117 n.setCoor(null);
118 assertFalse(n.isOutSideWorld());
119 n.setCoor(LatLon.NORTH_POLE);
120 assertTrue(n.isOutSideWorld());
121 n.setCoor(new LatLon(0, 180.0));
122 assertFalse(n.isOutSideWorld());
123 // simulate a small move east
124 n.setEastNorth(new EastNorth(n.getEastNorth().getX() + 0.1, n.getEastNorth().getY()));
125 assertTrue(n.isOutSideWorld());
126 n.setCoor(new LatLon(0, -180.0));
127 assertFalse(n.isOutSideWorld());
128 // simulate a small move west
129 n.setEastNorth(new EastNorth(n.getEastNorth().getX() - 0.1, n.getEastNorth().getY()));
130 assertTrue(n.isOutSideWorld());
131 }
132
133 /**
134 * Test that {@link Node#hasDirectionKeys} is not set.
135 */
136 @Test
137 void testDirectional() {
138 assertFalse(OsmUtils.createPrimitive("node oneway=yes").hasDirectionKeys());
139 }
140}
Note: See TracBrowser for help on using the repository browser.