source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.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

  • Property svn:eol-style set to native
File size: 4.9 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 org.junit.Assert;
10import org.junit.jupiter.api.Test;
11import org.junit.jupiter.api.extension.RegisterExtension;
12import org.openstreetmap.josm.data.coor.LatLon;
13import org.openstreetmap.josm.testutils.JOSMTestRules;
14
15import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16
17class RelationTest {
18
19 /**
20 * Setup test.
21 */
22 @RegisterExtension
23 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
24 public JOSMTestRules test = new JOSMTestRules();
25
26 @Test
27 void testCreateNewRelation() {
28 assertThrows(NullPointerException.class, () -> new Relation(null));
29 }
30
31 @Test
32 void testEqualSemanticsToNull() {
33 Relation relation = new Relation();
34 assertFalse(relation.hasEqualTechnicalAttributes(null));
35 }
36
37 @Test
38 void testBbox() {
39 DataSet ds = new DataSet();
40
41 Node n1 = new Node(new LatLon(10, 10));
42 Node n2 = new Node(new LatLon(20, 20));
43 Node n3 = new Node(new LatLon(30, 30));
44 Way w1 = new Way();
45 w1.addNode(n1);
46 w1.addNode(n2);
47 Relation r1 = new Relation();
48 Relation r2 = new Relation();
49 ds.addPrimitive(r1);
50 ds.addPrimitive(r2);
51 ds.addPrimitive(n1);
52 ds.addPrimitive(n2);
53 ds.addPrimitive(n3);
54 ds.addPrimitive(w1);
55 r1.addMember(new RelationMember("", n1));
56 r1.addMember(new RelationMember("", w1));
57 r1.addMember(new RelationMember("", r1));
58 r1.addMember(new RelationMember("", r2));
59 r2.addMember(new RelationMember("", r1));
60 r2.addMember(new RelationMember("", n3));
61
62 BBox bbox = new BBox(w1);
63 bbox.add(n3.getBBox());
64 Assert.assertEquals(bbox, r1.getBBox());
65 Assert.assertEquals(bbox, r2.getBBox());
66
67 n3.setCoor(new LatLon(40, 40));
68 bbox.add(n3.getBBox());
69 Assert.assertEquals(bbox, r1.getBBox());
70 Assert.assertEquals(bbox, r2.getBBox());
71
72 r1.removeMembersFor(r2);
73 Assert.assertEquals(w1.getBBox(), r1.getBBox());
74 Assert.assertEquals(bbox, r2.getBBox());
75
76 w1.addNode(n3);
77 Assert.assertEquals(w1.getBBox(), r1.getBBox());
78 Assert.assertEquals(w1.getBBox(), r2.getBBox());
79
80 // create incomplete node and add it to the relation, this must not change the bbox
81 BBox oldBBox = r2.getBBox();
82 Node n4 = new Node();
83 n4.setIncomplete(true);
84 ds.addPrimitive(n4);
85 r2.addMember(new RelationMember("", n4));
86
87 Assert.assertEquals(oldBBox, r2.getBBox());
88 }
89
90 @Test
91 void testBBoxNotInDataset() {
92 Node n1 = new Node(new LatLon(10, 10));
93 Node n2 = new Node(new LatLon(20, 20));
94 Way w1 = new Way();
95 w1.addNode(n1);
96 w1.addNode(n2);
97 Relation r1 = new Relation();
98 r1.getBBox();
99 r1.addMember(new RelationMember("", w1));
100
101 Assert.assertEquals(new BBox(w1), r1.getBBox());
102
103 DataSet ds = new DataSet();
104 ds.addPrimitive(n1);
105 ds.addPrimitive(n2);
106 ds.addPrimitive(w1);
107 ds.addPrimitive(r1);
108
109 Assert.assertEquals(new BBox(w1), r1.getBBox());
110
111 ds.removePrimitive(r1);
112
113 n1.setCoor(new LatLon(30, 40));
114 Assert.assertEquals(new BBox(w1), r1.getBBox());
115
116 ds.addPrimitive(r1);
117 Assert.assertEquals(new BBox(w1), r1.getBBox());
118 }
119
120 /**
121 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/12467">Bug #12467</a>.
122 * @throws Exception if any error occurs
123 */
124 @Test
125 void testTicket12467() throws Exception {
126 Relation r = new Relation();
127 r.put("type", "boundary");
128 assertTrue(r.isBoundary());
129 assertTrue(r.isMultipolygon());
130 assertEquals(OsmPrimitiveType.RELATION, r.getDisplayType());
131
132 r.put("type", "multipolygon");
133 assertFalse(r.isBoundary());
134 assertTrue(r.isMultipolygon());
135 assertEquals(OsmPrimitiveType.MULTIPOLYGON, r.getDisplayType());
136
137 r.put("type", "something_else");
138 assertFalse(r.isBoundary());
139 assertFalse(r.isMultipolygon());
140 assertEquals(OsmPrimitiveType.RELATION, r.getDisplayType());
141 }
142
143 /**
144 * Test that {@link Relation#cloneFrom} throws IAE for invalid arguments
145 */
146 @Test
147 void testCloneFromIAE() {
148 assertThrows(IllegalArgumentException.class, () -> new Relation().cloneFrom(new Node()));
149 }
150
151 /**
152 * Test that {@link Relation#load} throws IAE for invalid arguments
153 */
154 @Test
155 void testLoadIAE() {
156 assertThrows(IllegalArgumentException.class, () -> new Relation().load(new NodeData()));
157 }
158}
Note: See TracBrowser for help on using the repository browser.