source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/QuadBucketsTest.java@ 6471

Last change on this file since 6471 was 6471, checked in by Don-vip, 10 years ago

Sonar - remove warnings related to the static preferences initialization in instance methods

  • Property svn:mime-type set to text/plain
File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.io.FileInputStream;
5import java.util.ArrayList;
6import java.util.Collection;
7import java.util.Iterator;
8import java.util.List;
9
10import org.fest.reflect.core.Reflection;
11import org.fest.reflect.reference.TypeRef;
12import org.junit.Assert;
13import org.junit.BeforeClass;
14import org.junit.Test;
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.data.Preferences;
17import org.openstreetmap.josm.data.coor.LatLon;
18import org.openstreetmap.josm.data.projection.Projections;
19import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
20import org.openstreetmap.josm.io.OsmReader;
21
22public class QuadBucketsTest {
23
24 @BeforeClass
25 public static void init() {
26 Main.initApplicationPreferences();
27 }
28
29 private void removeAllTest(DataSet ds) {
30 List<Node> allNodes = new ArrayList<Node>(ds.getNodes());
31 List<Way> allWays = new ArrayList<Way>(ds.getWays());
32 List<Relation> allRelations = new ArrayList<Relation>(ds.getRelations());
33
34 QuadBuckets<Node> nodes = Reflection.field("nodes").ofType(new TypeRef<QuadBuckets<Node>>() {}).in(ds).get();
35 QuadBuckets<Way> ways = Reflection.field("ways").ofType(new TypeRef<QuadBuckets<Way>>() {}).in(ds).get();
36 Collection<Relation> relations = Reflection.field("relations").ofType(new TypeRef<Collection<Relation>>() {}).in(ds).get();
37
38 int expectedCount = allNodes.size();
39 for (OsmPrimitive o: allNodes) {
40 ds.removePrimitive(o);
41 checkIterator(nodes, --expectedCount);
42 }
43 expectedCount = allWays.size();
44 for (OsmPrimitive o: allWays) {
45 ds.removePrimitive(o);
46 checkIterator(ways, --expectedCount);
47 }
48 for (OsmPrimitive o: allRelations) {
49 ds.removePrimitive(o);
50 }
51 Assert.assertTrue(nodes.isEmpty());
52 Assert.assertTrue(ways.isEmpty());
53 Assert.assertTrue(relations.isEmpty());
54 }
55
56 private void checkIterator(Collection<? extends OsmPrimitive> col, int expectedCount) {
57 int count = 0;
58 Iterator<? extends OsmPrimitive> it = col.iterator();
59 while (it.hasNext()) {
60 count++;
61 it.next();
62 }
63 Assert.assertEquals(expectedCount, count);
64 }
65
66 @Test
67 public void testRemove() throws Exception {
68 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
69 DataSet ds = OsmReader.parseDataSet(new FileInputStream("data_nodist/restriction.osm"), NullProgressMonitor.INSTANCE);
70 removeAllTest(ds);
71 }
72
73 @Test
74 public void testMove() throws Exception {
75 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
76 DataSet ds = OsmReader.parseDataSet(new FileInputStream("data_nodist/restriction.osm"), NullProgressMonitor.INSTANCE);
77
78 for (Node n: ds.getNodes()) {
79 n.setCoor(new LatLon(10, 10));
80 }
81
82 removeAllTest(ds);
83 }
84
85}
Note: See TracBrowser for help on using the repository browser.