| 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.Test; |
|---|
| 8 | import org.openstreetmap.josm.data.coor.LatLon; |
|---|
| 9 | |
|---|
| 10 | public 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 | @Test |
|---|
| 68 | public void testBBoxNotInDataset() { |
|---|
| 69 | Node n1 = new Node(new LatLon(10, 10)); |
|---|
| 70 | Node n2 = new Node(new LatLon(20, 20)); |
|---|
| 71 | Way w1 = new Way(); |
|---|
| 72 | w1.addNode(n1); |
|---|
| 73 | w1.addNode(n2); |
|---|
| 74 | Relation r1 = new Relation(); |
|---|
| 75 | r1.getBBox(); |
|---|
| 76 | r1.addMember(new RelationMember("", w1)); |
|---|
| 77 | |
|---|
| 78 | Assert.assertEquals(new BBox(w1), r1.getBBox()); |
|---|
| 79 | |
|---|
| 80 | DataSet ds = new DataSet(); |
|---|
| 81 | ds.addPrimitive(n1); |
|---|
| 82 | ds.addPrimitive(n2); |
|---|
| 83 | ds.addPrimitive(w1); |
|---|
| 84 | ds.addPrimitive(r1); |
|---|
| 85 | |
|---|
| 86 | Assert.assertEquals(new BBox(w1), r1.getBBox()); |
|---|
| 87 | |
|---|
| 88 | ds.removePrimitive(r1); |
|---|
| 89 | |
|---|
| 90 | n1.setCoor(new LatLon(30, 40)); |
|---|
| 91 | Assert.assertEquals(new BBox(w1), r1.getBBox()); |
|---|
| 92 | |
|---|
| 93 | ds.addPrimitive(r1); |
|---|
| 94 | Assert.assertEquals(new BBox(w1), r1.getBBox()); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | } |
|---|