1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import org.junit.Rule;
|
---|
5 | import org.junit.Test;
|
---|
6 | import org.junit.Assert;
|
---|
7 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
8 |
|
---|
9 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
10 | import java.util.List;
|
---|
11 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Unit tests for class {@link DataSet}.
|
---|
15 | */
|
---|
16 | public class DataSetTest {
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Setup test.
|
---|
20 | */
|
---|
21 | @Rule
|
---|
22 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
23 | public JOSMTestRules test = new JOSMTestRules();
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Unit test of method {@link DataSet#searchRelations}.
|
---|
27 | */
|
---|
28 | @Test
|
---|
29 | public void testSearchRelations() {
|
---|
30 | final DataSet ds = new DataSet();
|
---|
31 | // null bbox => empty list
|
---|
32 | Assert.assertTrue(
|
---|
33 | "Empty data set should produce an empty list.",
|
---|
34 | ds.searchRelations(null).isEmpty()
|
---|
35 | );
|
---|
36 |
|
---|
37 | // empty data set, any bbox => empty list
|
---|
38 | BBox bbox = new BBox(LatLon.NORTH_POLE, LatLon.SOUTH_POLE);
|
---|
39 | Assert.assertTrue(
|
---|
40 | "Empty data set should produce an empty list.",
|
---|
41 | ds.searchRelations(bbox).isEmpty()
|
---|
42 | );
|
---|
43 |
|
---|
44 | // data set with elements in the given bbox => these elements
|
---|
45 | Node node = new Node(LatLon.ZERO);
|
---|
46 | Relation r = new Relation(1);
|
---|
47 | RelationMember rm = new RelationMember("role", node);
|
---|
48 | r.addMember(rm);
|
---|
49 | ds.addPrimitive(node);
|
---|
50 | ds.addPrimitive(r);
|
---|
51 | bbox = new BBox(new LatLon(-1.0, -1.0), new LatLon(1.0, 1.0));
|
---|
52 | List<Relation> result = ds.searchRelations(bbox);
|
---|
53 | Assert.assertEquals("We should have found only one item.", 1, result.size());
|
---|
54 | Assert.assertTrue("The item found is relation r.", result.contains(r));
|
---|
55 |
|
---|
56 | }
|
---|
57 | }
|
---|