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

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

fixes for unit tests

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