source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java@ 2982

Last change on this file since 2982 was 2982, checked in by jttt, 14 years ago

Calculate bbox for relations, use it in mappaint.

File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import static org.junit.Assert.assertFalse;
5
6import org.junit.Assert;
7import org.junit.Test;
8import org.openstreetmap.josm.data.coor.LatLon;
9
10public class RelationTest {
11
12 @Test(expected=NullPointerException.class)
13 public void createNewRelation() {
14 new Relation(null);
15 }
16
17 @Test
18 public void equalSemenaticsToNull() {
19 Relation relation = new Relation();
20 assertFalse(relation.hasEqualTechnicalAttributes(null));
21 }
22
23 @Test
24 public void testBBox() {
25 DataSet ds = new DataSet();
26
27 Node n1 = new Node(new LatLon(10, 10));
28 Node n2 = new Node(new LatLon(20, 20));
29 Node n3 = new Node(new LatLon(30, 30));
30 Way w1 = new Way();
31 w1.addNode(n1);
32 w1.addNode(n2);
33 Relation r1 = new Relation();
34 Relation r2 = new Relation();
35 ds.addPrimitive(r1);
36 ds.addPrimitive(r2);
37 ds.addPrimitive(n1);
38 ds.addPrimitive(n2);
39 ds.addPrimitive(n3);
40 ds.addPrimitive(w1);
41 r1.addMember(new RelationMember("", n1));
42 r1.addMember(new RelationMember("", w1));
43 r1.addMember(new RelationMember("", r1));
44 r1.addMember(new RelationMember("", r2));
45 r2.addMember(new RelationMember("", r1));
46 r2.addMember(new RelationMember("", n3));
47
48 BBox bbox = new BBox(w1);
49 bbox.add(n3.getBBox());
50 Assert.assertEquals(bbox, r1.getBBox());
51 Assert.assertEquals(bbox, r2.getBBox());
52
53 n3.setCoor(new LatLon(40, 40));
54 bbox.add(n3.getBBox());
55 Assert.assertEquals(bbox, r1.getBBox());
56 Assert.assertEquals(bbox, r2.getBBox());
57
58 r1.removeMembersFor(r2);
59 Assert.assertEquals(w1.getBBox(), r1.getBBox());
60 Assert.assertEquals(bbox, r2.getBBox());
61
62 w1.addNode(n3);
63 Assert.assertEquals(w1.getBBox(), r1.getBBox());
64 Assert.assertEquals(w1.getBBox(), r2.getBBox());
65 }
66
67}
Note: See TracBrowser for help on using the repository browser.