1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 |
|
---|
6 | import org.junit.Assert;
|
---|
7 | import org.junit.BeforeClass;
|
---|
8 | import org.junit.Test;
|
---|
9 | import org.openstreetmap.josm.Main;
|
---|
10 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
11 | import org.openstreetmap.josm.data.projection.Mercator;
|
---|
12 |
|
---|
13 | public class RelationTest {
|
---|
14 |
|
---|
15 | @BeforeClass
|
---|
16 | public static void setUp() {
|
---|
17 | Main.proj = new Mercator();
|
---|
18 | }
|
---|
19 |
|
---|
20 | @Test(expected=NullPointerException.class)
|
---|
21 | public void createNewRelation() {
|
---|
22 | new Relation(null);
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Test
|
---|
26 | public void equalSemenaticsToNull() {
|
---|
27 | Relation relation = new Relation();
|
---|
28 | assertFalse(relation.hasEqualTechnicalAttributes(null));
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Test
|
---|
32 | public void testBBox() {
|
---|
33 | DataSet ds = new DataSet();
|
---|
34 |
|
---|
35 | Node n1 = new Node(new LatLon(10, 10));
|
---|
36 | Node n2 = new Node(new LatLon(20, 20));
|
---|
37 | Node n3 = new Node(new LatLon(30, 30));
|
---|
38 | Way w1 = new Way();
|
---|
39 | w1.addNode(n1);
|
---|
40 | w1.addNode(n2);
|
---|
41 | Relation r1 = new Relation();
|
---|
42 | Relation r2 = new Relation();
|
---|
43 | ds.addPrimitive(r1);
|
---|
44 | ds.addPrimitive(r2);
|
---|
45 | ds.addPrimitive(n1);
|
---|
46 | ds.addPrimitive(n2);
|
---|
47 | ds.addPrimitive(n3);
|
---|
48 | ds.addPrimitive(w1);
|
---|
49 | r1.addMember(new RelationMember("", n1));
|
---|
50 | r1.addMember(new RelationMember("", w1));
|
---|
51 | r1.addMember(new RelationMember("", r1));
|
---|
52 | r1.addMember(new RelationMember("", r2));
|
---|
53 | r2.addMember(new RelationMember("", r1));
|
---|
54 | r2.addMember(new RelationMember("", n3));
|
---|
55 |
|
---|
56 | BBox bbox = new BBox(w1);
|
---|
57 | bbox.add(n3.getBBox());
|
---|
58 | Assert.assertEquals(bbox, r1.getBBox());
|
---|
59 | Assert.assertEquals(bbox, r2.getBBox());
|
---|
60 |
|
---|
61 | n3.setCoor(new LatLon(40, 40));
|
---|
62 | bbox.add(n3.getBBox());
|
---|
63 | Assert.assertEquals(bbox, r1.getBBox());
|
---|
64 | Assert.assertEquals(bbox, r2.getBBox());
|
---|
65 |
|
---|
66 | r1.removeMembersFor(r2);
|
---|
67 | Assert.assertEquals(w1.getBBox(), r1.getBBox());
|
---|
68 | Assert.assertEquals(bbox, r2.getBBox());
|
---|
69 |
|
---|
70 | w1.addNode(n3);
|
---|
71 | Assert.assertEquals(w1.getBBox(), r1.getBBox());
|
---|
72 | Assert.assertEquals(w1.getBBox(), r2.getBBox());
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Test
|
---|
76 | public void testBBoxNotInDataset() {
|
---|
77 | Node n1 = new Node(new LatLon(10, 10));
|
---|
78 | Node n2 = new Node(new LatLon(20, 20));
|
---|
79 | Way w1 = new Way();
|
---|
80 | w1.addNode(n1);
|
---|
81 | w1.addNode(n2);
|
---|
82 | Relation r1 = new Relation();
|
---|
83 | r1.getBBox();
|
---|
84 | r1.addMember(new RelationMember("", w1));
|
---|
85 |
|
---|
86 | Assert.assertEquals(new BBox(w1), r1.getBBox());
|
---|
87 |
|
---|
88 | DataSet ds = new DataSet();
|
---|
89 | ds.addPrimitive(n1);
|
---|
90 | ds.addPrimitive(n2);
|
---|
91 | ds.addPrimitive(w1);
|
---|
92 | ds.addPrimitive(r1);
|
---|
93 |
|
---|
94 | Assert.assertEquals(new BBox(w1), r1.getBBox());
|
---|
95 |
|
---|
96 | ds.removePrimitive(r1);
|
---|
97 |
|
---|
98 | n1.setCoor(new LatLon(30, 40));
|
---|
99 | Assert.assertEquals(new BBox(w1), r1.getBBox());
|
---|
100 |
|
---|
101 | ds.addPrimitive(r1);
|
---|
102 | Assert.assertEquals(new BBox(w1), r1.getBBox());
|
---|
103 | }
|
---|
104 |
|
---|
105 | }
|
---|