source: josm/trunk/test/unit/org/openstreetmap/josm/data/validation/tests/DuplicateRelationTest.java@ 18037

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

fix #21064 - Add JUnit 5 extension for preferences (patch by taylor.smock)

  • 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.jupiter.api.Assertions.assertEquals;
5
6import org.openstreetmap.josm.TestUtils;
7import org.openstreetmap.josm.data.coor.LatLon;
8import org.openstreetmap.josm.data.osm.DataSet;
9import org.openstreetmap.josm.data.osm.Node;
10import org.openstreetmap.josm.data.osm.RelationMember;
11import org.openstreetmap.josm.data.validation.TestError;
12import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
13import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
14
15import org.junit.jupiter.api.Test;
16
17/**
18 * JUnit Test of "Duplicate relation" validation test.
19 */
20@BasicPreferences
21class DuplicateRelationTest {
22 static class ExpectedResult {
23 final int code;
24 final boolean fixable;
25 ExpectedResult(int code, boolean fixable) {
26 this.code = code;
27 this.fixable = fixable;
28 }
29 }
30
31 private void doTest(String tags1, String tags2, ExpectedResult... expectations) {
32 performTest(buildDataSet(tags1, tags2), expectations);
33 }
34
35 private void performTest(DataSet ds, ExpectedResult... expectations) {
36 final DuplicateRelation TEST = new DuplicateRelation();
37 TEST.startTest(NullProgressMonitor.INSTANCE);
38 TEST.visit(ds.allPrimitives());
39 TEST.endTest();
40
41 assertEquals(expectations.length, TEST.getErrors().size());
42 int i = 0;
43 for (TestError error : TEST.getErrors()) {
44 ExpectedResult expected = expectations[i++];
45 assertEquals(expected.code, error.getCode());
46 assertEquals(expected.fixable, error.isFixable());
47 }
48 }
49
50 private static DataSet buildDataSet(String tags1, String tags2) {
51 DataSet ds = new DataSet();
52
53 Node a = new Node(new LatLon(10.0, 5.0));
54 ds.addPrimitive(a);
55 ds.addPrimitive(TestUtils.newRelation(tags1, new RelationMember(null, a)));
56 ds.addPrimitive(TestUtils.newRelation(tags2, new RelationMember(null, a)));
57 return ds;
58 }
59
60 /**
61 * Test of "Duplicate relation" validation test - no tags.
62 */
63 @Test
64 void testDuplicateRelationNoTags() {
65 doTest("", "",
66 new ExpectedResult(DuplicateRelation.DUPLICATE_RELATION, true),
67 new ExpectedResult(DuplicateRelation.SAME_RELATION, false));
68 }
69
70 /**
71 * Test of "Duplicate relation" validation test - same tags.
72 */
73 @Test
74 void testDuplicateRelationSameTags() {
75 doTest("type=boundary", "type=boundary",
76 new ExpectedResult(DuplicateRelation.DUPLICATE_RELATION, true),
77 new ExpectedResult(DuplicateRelation.SAME_RELATION, false));
78 }
79
80 /**
81 * Test of "Duplicate relation" validation test - different tags.
82 */
83 @Test
84 void testDuplicateRelationDifferentTags() {
85 doTest("type=boundary", "type=multipolygon",
86 new ExpectedResult(DuplicateRelation.SAME_RELATION, false));
87 }
88}
Note: See TracBrowser for help on using the repository browser.