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

Last change on this file since 9130 was 8510, checked in by Don-vip, 9 years ago

checkstyle: enable relevant whitespace checks and fix them

  • Property svn:eol-style set to native
File size: 3.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.BeforeClass;
8import org.junit.Test;
9import org.openstreetmap.josm.JOSMFixture;
10import org.openstreetmap.josm.data.coor.LatLon;
11
12public class RelationTest {
13
14 /**
15 * Setup test.
16 */
17 @BeforeClass
18 public static void setUp() {
19 JOSMFixture.createUnitTestFixture().init();
20 }
21
22 @Test(expected = NullPointerException.class)
23 public void createNewRelation() {
24 new Relation(null);
25 }
26
27 @Test
28 public void equalSemenaticsToNull() {
29 Relation relation = new Relation();
30 assertFalse(relation.hasEqualTechnicalAttributes(null));
31 }
32
33 @Test
34 public void testBBox() {
35 DataSet ds = new DataSet();
36
37 Node n1 = new Node(new LatLon(10, 10));
38 Node n2 = new Node(new LatLon(20, 20));
39 Node n3 = new Node(new LatLon(30, 30));
40 Way w1 = new Way();
41 w1.addNode(n1);
42 w1.addNode(n2);
43 Relation r1 = new Relation();
44 Relation r2 = new Relation();
45 ds.addPrimitive(r1);
46 ds.addPrimitive(r2);
47 ds.addPrimitive(n1);
48 ds.addPrimitive(n2);
49 ds.addPrimitive(n3);
50 ds.addPrimitive(w1);
51 r1.addMember(new RelationMember("", n1));
52 r1.addMember(new RelationMember("", w1));
53 r1.addMember(new RelationMember("", r1));
54 r1.addMember(new RelationMember("", r2));
55 r2.addMember(new RelationMember("", r1));
56 r2.addMember(new RelationMember("", n3));
57
58 BBox bbox = new BBox(w1);
59 bbox.add(n3.getBBox());
60 Assert.assertEquals(bbox, r1.getBBox());
61 Assert.assertEquals(bbox, r2.getBBox());
62
63 n3.setCoor(new LatLon(40, 40));
64 bbox.add(n3.getBBox());
65 Assert.assertEquals(bbox, r1.getBBox());
66 Assert.assertEquals(bbox, r2.getBBox());
67
68 r1.removeMembersFor(r2);
69 Assert.assertEquals(w1.getBBox(), r1.getBBox());
70 Assert.assertEquals(bbox, r2.getBBox());
71
72 w1.addNode(n3);
73 Assert.assertEquals(w1.getBBox(), r1.getBBox());
74 Assert.assertEquals(w1.getBBox(), r2.getBBox());
75 }
76
77 @Test
78 public void testBBoxNotInDataset() {
79 Node n1 = new Node(new LatLon(10, 10));
80 Node n2 = new Node(new LatLon(20, 20));
81 Way w1 = new Way();
82 w1.addNode(n1);
83 w1.addNode(n2);
84 Relation r1 = new Relation();
85 r1.getBBox();
86 r1.addMember(new RelationMember("", w1));
87
88 Assert.assertEquals(new BBox(w1), r1.getBBox());
89
90 DataSet ds = new DataSet();
91 ds.addPrimitive(n1);
92 ds.addPrimitive(n2);
93 ds.addPrimitive(w1);
94 ds.addPrimitive(r1);
95
96 Assert.assertEquals(new BBox(w1), r1.getBBox());
97
98 ds.removePrimitive(r1);
99
100 n1.setCoor(new LatLon(30, 40));
101 Assert.assertEquals(new BBox(w1), r1.getBBox());
102
103 ds.addPrimitive(r1);
104 Assert.assertEquals(new BBox(w1), r1.getBBox());
105 }
106}
Note: See TracBrowser for help on using the repository browser.