1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertTrue;
|
---|
7 |
|
---|
8 | import java.util.ArrayList;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.junit.Before;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.JOSMFixture;
|
---|
14 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmUtils;
|
---|
17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
18 | import org.openstreetmap.josm.gui.mappaint.ElemStyles;
|
---|
19 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * JUnit Test of Multipolygon validation test.
|
---|
23 | */
|
---|
24 | public class MultipolygonTestTest {
|
---|
25 |
|
---|
26 | private static final MultipolygonTest MULTIPOLYGON_TEST = new MultipolygonTest();
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Setup test.
|
---|
30 | * @throws Exception if test cannot be initialized
|
---|
31 | */
|
---|
32 | @Before
|
---|
33 | public void setUp() throws Exception {
|
---|
34 | JOSMFixture.createUnitTestFixture().init();
|
---|
35 | MapPaintStyles.readFromPreferences();
|
---|
36 | MULTIPOLYGON_TEST.initialize();
|
---|
37 | }
|
---|
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.startTest(null);
|
---|
55 |
|
---|
56 | List<Node> nodes = new ArrayList<>();
|
---|
57 | nodes.add(new Node(new LatLon(0, 1)));
|
---|
58 | nodes.add(new Node(new LatLon(0, 2)));
|
---|
59 |
|
---|
60 | // Erroneous tag
|
---|
61 | Way w = createUnclosedWay("amenity=parking");
|
---|
62 | MULTIPOLYGON_TEST.visit(w);
|
---|
63 | assertTrue(ElemStyles.hasAreaElemStyle(w, false));
|
---|
64 | assertEquals(1, MULTIPOLYGON_TEST.getErrors().size());
|
---|
65 |
|
---|
66 | // Erroneous tag, but managed by another test
|
---|
67 | w = createUnclosedWay("building=yes");
|
---|
68 | MULTIPOLYGON_TEST.visit(w);
|
---|
69 | assertTrue(ElemStyles.hasAreaElemStyle(w, false));
|
---|
70 | assertEquals(1, MULTIPOLYGON_TEST.getErrors().size());
|
---|
71 |
|
---|
72 | // Correct tag, without area style since #10601 (r7603)
|
---|
73 | w = createUnclosedWay("aeroway=taxiway");
|
---|
74 | MULTIPOLYGON_TEST.visit(w);
|
---|
75 | assertFalse(ElemStyles.hasAreaElemStyle(w, false));
|
---|
76 | assertEquals(1, MULTIPOLYGON_TEST.getErrors().size());
|
---|
77 |
|
---|
78 | MULTIPOLYGON_TEST.endTest();
|
---|
79 | }
|
---|
80 | }
|
---|