source: josm/trunk/test/unit/org/openstreetmap/josm/data/validation/OsmValidatorTest.java@ 15603

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

fix #18441 - Allow plugins to remove a test they added (patch by taylor.smock)

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation;
3
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertNotEquals;
6import static org.junit.Assert.assertTrue;
7
8import org.junit.Before;
9import org.junit.Rule;
10import org.junit.Test;
11import org.openstreetmap.josm.data.validation.tests.Addresses;
12import org.openstreetmap.josm.testutils.JOSMTestRules;
13
14import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15import net.trajano.commons.testing.UtilityClassTestUtil;
16
17/**
18 * Unit tests for class {@link OsmValidator}.
19 */
20public class OsmValidatorTest {
21
22 /**
23 * Setup test.
24 */
25 @Rule
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 @Before
34 public void setUp() throws Exception {
35 OsmValidator.clearIgnoredErrors();
36 }
37
38 /**
39 * Tests that {@code OsmValidator} satisfies utility class criterias.
40 * @throws ReflectiveOperationException if an error occurs
41 */
42 @Test
43 public 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 public 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 public 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 public 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 public 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}
Note: See TracBrowser for help on using the repository browser.