source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetTest.java@ 11115

Last change on this file since 11115 was 11115, checked in by simon04, 8 years ago

fix #13785 - Use streams, add unit tests (patch by alno, modified)

File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import org.junit.Rule;
5import org.junit.Test;
6import org.junit.Assert;
7import org.openstreetmap.josm.testutils.JOSMTestRules;
8
9import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
10import java.util.List;
11import org.openstreetmap.josm.data.coor.LatLon;
12
13/**
14 * Unit tests for class {@link DataSet}.
15 */
16public 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}
Note: See TracBrowser for help on using the repository browser.