source: josm/trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MultipolygonTestTest.java@ 10991

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

fix #13570 - Coastline validator doesn't report some problems and is slow (patch by Gerd Petermann, modified)

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertTrue;
7
8import java.util.ArrayList;
9import java.util.List;
10import java.util.stream.Collectors;
11
12import org.junit.Rule;
13import org.junit.Test;
14import org.openstreetmap.josm.data.coor.LatLon;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.data.osm.OsmUtils;
17import org.openstreetmap.josm.data.osm.Relation;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.gui.mappaint.ElemStyles;
20import org.openstreetmap.josm.testutils.JOSMTestRules;
21
22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
23
24/**
25 * JUnit Test of Multipolygon validation test.
26 */
27public class MultipolygonTestTest {
28
29 private static final MultipolygonTest MULTIPOLYGON_TEST = new MultipolygonTest();
30 private static final RelationChecker RELATION_TEST = new RelationChecker();
31
32 /**
33 * Setup test.
34 */
35 @Rule
36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
37 public JOSMTestRules test = new JOSMTestRules().commands();
38
39 private static Way createUnclosedWay(String tags) {
40 List<Node> nodes = new ArrayList<>();
41 nodes.add(new Node(new LatLon(0, 1)));
42 nodes.add(new Node(new LatLon(0, 2)));
43
44 Way w = (Way) OsmUtils.createPrimitive("way "+tags);
45 w.setNodes(nodes);
46 return w;
47 }
48
49 /**
50 * Non-regression test for bug #10469.
51 */
52 @Test
53 public void testTicket10469() {
54 MULTIPOLYGON_TEST.initialize();
55 MULTIPOLYGON_TEST.startTest(null);
56
57 // Erroneous tag
58 Way w = createUnclosedWay("amenity=parking");
59 MULTIPOLYGON_TEST.visit(w);
60 assertTrue(ElemStyles.hasAreaElemStyle(w, false));
61 assertEquals(1, MULTIPOLYGON_TEST.getErrors().size());
62
63 // Erroneous tag, but managed by another test
64 w = createUnclosedWay("building=yes");
65 MULTIPOLYGON_TEST.visit(w);
66 assertTrue(ElemStyles.hasAreaElemStyle(w, false));
67 assertEquals(1, MULTIPOLYGON_TEST.getErrors().size());
68
69 // Correct tag, without area style since #10601 (r7603)
70 w = createUnclosedWay("aeroway=taxiway");
71 MULTIPOLYGON_TEST.visit(w);
72 assertFalse(ElemStyles.hasAreaElemStyle(w, false));
73 assertEquals(1, MULTIPOLYGON_TEST.getErrors().size());
74
75 MULTIPOLYGON_TEST.endTest();
76 }
77
78 /**
79 * Test all error cases manually created in multipolygon.osm.
80 * @throws Exception in case of error
81 */
82 @Test
83 public void testMultipolygonFile() throws Exception {
84 ValidatorTestUtils.testSampleFile("data_nodist/multipolygon.osm",
85 ds -> ds.getRelations().stream().filter(Relation::isMultipolygon).collect(Collectors.toList()),
86 name -> name.startsWith("06") || name.startsWith("07"), MULTIPOLYGON_TEST, RELATION_TEST);
87 }
88}
Note: See TracBrowser for help on using the repository browser.