1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
7 |
|
---|
8 | import org.junit.jupiter.api.BeforeEach;
|
---|
9 | import org.junit.jupiter.api.Test;
|
---|
10 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
11 | import org.openstreetmap.josm.data.validation.tests.Addresses;
|
---|
12 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
13 |
|
---|
14 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
15 | import net.trajano.commons.testing.UtilityClassTestUtil;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Unit tests for class {@link OsmValidator}.
|
---|
19 | */
|
---|
20 | class OsmValidatorTest {
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Setup test.
|
---|
24 | */
|
---|
25 | @RegisterExtension
|
---|
26 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
27 | public JOSMTestRules test = new JOSMTestRules().projection();
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Setup test.
|
---|
31 | * @throws Exception if an error occurs
|
---|
32 | */
|
---|
33 | @BeforeEach
|
---|
34 | public void setUp() throws Exception {
|
---|
35 | OsmValidator.clearIgnoredErrors();
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Tests that {@code OsmValidator} satisfies utility class criteria.
|
---|
40 | * @throws ReflectiveOperationException if an error occurs
|
---|
41 | */
|
---|
42 | @Test
|
---|
43 | void testUtilityClass() throws ReflectiveOperationException {
|
---|
44 | UtilityClassTestUtil.assertUtilityClassWellDefined(OsmValidator.class);
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Test that {@link OsmValidator#cleanupIgnoredErrors()} really removes entry with element IDs when group is ignored
|
---|
49 | */
|
---|
50 | @Test
|
---|
51 | void testCleanupIgnoredErrors1() {
|
---|
52 | OsmValidator.addIgnoredError("1351:n_2449148994:w_236955234", "Way end node near other way");
|
---|
53 | OsmValidator.addIgnoredError("1351:n_6871910559:w_733713588", "Way end node near other way");
|
---|
54 | OsmValidator.addIgnoredError("1351");
|
---|
55 | OsmValidator.cleanupIgnoredErrors();
|
---|
56 | assertTrue(OsmValidator.hasIgnoredError("1351"));
|
---|
57 | assertFalse(OsmValidator.hasIgnoredError("1351:n_6871910559:w_733713588"));
|
---|
58 | assertFalse(OsmValidator.hasIgnoredError("1351:n_2449148994:w_236955234"));
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/17837">Bug #17837</a>.
|
---|
63 | * {@link OsmValidator#cleanupIgnoredErrors()} must not remove entry 1201 when 120 is before it.
|
---|
64 | */
|
---|
65 | @Test
|
---|
66 | void testCleanupIgnoredErrorsTicket17837() {
|
---|
67 | OsmValidator.addIgnoredError("120");
|
---|
68 | OsmValidator.addIgnoredError("3000");
|
---|
69 | OsmValidator.addIgnoredError("1201"); // starts with 120, but has different code
|
---|
70 | OsmValidator.cleanupIgnoredErrors();
|
---|
71 | assertTrue(OsmValidator.hasIgnoredError("1201"));
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18223">Bug #18223</a>.
|
---|
76 | * {@link OsmValidator#cleanupIgnoredErrors()} must not combine primitives.
|
---|
77 | */
|
---|
78 | @Test
|
---|
79 | void testCleanupIgnoredErrorsTicket18223() {
|
---|
80 | OsmValidator.addIgnoredError("1351:n_2449148994:w_236955234", "Way end node near other way");
|
---|
81 | OsmValidator.addIgnoredError("1351:n_6871910559:w_733713588", "Way end node near other way");
|
---|
82 | OsmValidator.cleanupIgnoredErrors();
|
---|
83 | assertFalse(OsmValidator.hasIgnoredError("1351"));
|
---|
84 | assertTrue(OsmValidator.hasIgnoredError("1351:n_2449148994:w_236955234"));
|
---|
85 | assertTrue(OsmValidator.hasIgnoredError("1351:n_6871910559:w_733713588"));
|
---|
86 | }
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Test that tests are really removed, and that core tests cannot be removed
|
---|
90 | */
|
---|
91 | @Test
|
---|
92 | void testRemoveTests() {
|
---|
93 | org.openstreetmap.josm.data.validation.Test test = new org.openstreetmap.josm.data.validation.Test("test") {
|
---|
94 | };
|
---|
95 | assertNotEquals(org.openstreetmap.josm.data.validation.Test.class, test.getClass());
|
---|
96 | OsmValidator.addTest(test.getClass());
|
---|
97 | assertTrue(OsmValidator.getAllAvailableTestClasses().contains(test.getClass()));
|
---|
98 | assertTrue(OsmValidator.removeTest(test.getClass()));
|
---|
99 | assertFalse(OsmValidator.removeTest(test.getClass()));
|
---|
100 | assertFalse(OsmValidator.getAllAvailableTestClasses().contains(test.getClass()));
|
---|
101 |
|
---|
102 | assertTrue(OsmValidator.getAllAvailableTestClasses().contains(Addresses.class));
|
---|
103 | assertFalse(OsmValidator.removeTest(Addresses.class));
|
---|
104 | assertTrue(OsmValidator.getAllAvailableTestClasses().contains(Addresses.class));
|
---|
105 | }
|
---|
106 |
|
---|
107 | }
|
---|