source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/WayTest.java@ 17442

Last change on this file since 17442 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.1 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.assertTrue;
7import static org.junit.jupiter.api.Assertions.assertThrows;
8
9import java.util.Arrays;
10import java.util.HashSet;
11
12import org.junit.jupiter.api.BeforeAll;
13import org.junit.jupiter.api.Test;
14import org.openstreetmap.josm.JOSMFixture;
15import org.openstreetmap.josm.data.coor.LatLon;
16
17/**
18 * Unit tests of the {@code Way} class.
19 * @since 11270
20 */
21class WayTest {
22
23 /**
24 * Setup test.
25 */
26 @BeforeAll
27 public static void setUpBeforeClass() {
28 JOSMFixture.createUnitTestFixture().init();
29 }
30
31 /**
32 * Test BBox calculation with Way
33 */
34 @Test
35 void testBBox() {
36 DataSet ds = new DataSet();
37 Node n1 = new Node(1);
38 Node n2 = new Node(2);
39 Node n3 = new Node(3);
40 Node n4 = new Node(4);
41 n1.setIncomplete(true);
42 n2.setCoor(new LatLon(10, 10));
43 n3.setCoor(new LatLon(20, 20));
44 n4.setCoor(new LatLon(90, 180));
45 ds.addPrimitive(n1);
46 ds.addPrimitive(n2);
47 ds.addPrimitive(n3);
48 ds.addPrimitive(n4);
49 Way way = new Way(1);
50 assertFalse(way.getBBox().isValid());
51 way.setNodes(Arrays.asList(n1));
52 assertFalse(way.getBBox().isValid());
53 way.setNodes(Arrays.asList(n2));
54 assertTrue(way.getBBox().isValid());
55 way.setNodes(Arrays.asList(n1, n2));
56 assertTrue(way.getBBox().isValid());
57 assertEquals(way.getBBox(), new BBox(10, 10));
58 }
59
60 /**
61 * Test remove node
62 */
63 @Test
64 void testRemoveNode() {
65 DataSet ds = new DataSet();
66 Node n1 = new Node(1);
67 Node n2 = new Node(2);
68 Node n3 = new Node(3);
69 Node n4 = new Node(4);
70 n1.setCoor(new LatLon(10, 10));
71 n2.setCoor(new LatLon(11, 11));
72 n3.setCoor(new LatLon(12, 12));
73 n4.setCoor(new LatLon(13, 13));
74 ds.addPrimitive(n1);
75 ds.addPrimitive(n2);
76 ds.addPrimitive(n3);
77 ds.addPrimitive(n4);
78 Way way = new Way(1);
79 ds.addPrimitive(way);
80 // duplicated way node
81 way.setNodes(Arrays.asList(n1, n2, n2, n3, n4, n1));
82 way.setIncomplete(false);
83 way.removeNode(n4);
84 assertEquals(Arrays.asList(n1, n2, n3, n1), way.getNodes());
85 way.removeNode(n3);
86 assertEquals(Arrays.asList(n1, n2), way.getNodes());
87 way.setNodes(Arrays.asList(n1, n2, n3, n4, n1));
88 way.removeNode(n1);
89 assertEquals(Arrays.asList(n2, n3, n4, n2), way.getNodes());
90 }
91
92 /**
93 * Test remove node
94 */
95 @Test
96 void testRemoveNodes() {
97 DataSet ds = new DataSet();
98 Node n1 = new Node(1);
99 Node n2 = new Node(2);
100 Node n3 = new Node(3);
101 Node n4 = new Node(4);
102 n1.setCoor(new LatLon(10, 10));
103 n2.setCoor(new LatLon(11, 11));
104 n3.setCoor(new LatLon(12, 12));
105 n4.setCoor(new LatLon(13, 13));
106 ds.addPrimitive(n1);
107 ds.addPrimitive(n2);
108 ds.addPrimitive(n3);
109 ds.addPrimitive(n4);
110 Way way = new Way(1);
111 ds.addPrimitive(way);
112 // duplicated way node
113 way.setNodes(Arrays.asList(n1, n2, n2, n3, n4, n1));
114 way.setIncomplete(false);
115 way.removeNodes(new HashSet<>(Arrays.asList(n3, n4)));
116 assertEquals(Arrays.asList(n1, n2, n1), way.getNodes());
117 way.setNodes(Arrays.asList(n1, n2, n3, n4, n1));
118 way.removeNodes(new HashSet<>(Arrays.asList(n1)));
119 assertEquals(Arrays.asList(n2, n3, n4, n2), way.getNodes());
120 }
121
122 /**
123 * Test that {@link Way#cloneFrom} throws IAE for invalid arguments
124 */
125 @Test
126 void testCloneFromIAE() {
127 assertThrows(IllegalArgumentException.class, () -> new Way().cloneFrom(new Node()));
128 }
129
130 /**
131 * Test that {@link Way#load} throws IAE for invalid arguments
132 */
133 @Test
134 void testLoadIAE() {
135 assertThrows(IllegalArgumentException.class, () -> new Way().load(new NodeData()));
136 }
137}
Note: See TracBrowser for help on using the repository browser.