Ticket #18441: 18441.patch

File 18441.patch, 2.9 KB (added by taylor.smock, 4 years ago)
  • src/org/openstreetmap/josm/data/validation/OsmValidator.java

     
    165165        }
    166166    }
    167167
     168    /**
     169     * Removes a test to the list of available tests. This will not remove core
     170     * tests.
     171     *
     172     * @param testClass The test class
     173     * @return {@code true} if the test was removed (see {@link Collection#remove})
     174     * @since xxx
     175     */
     176    public static boolean removeTest(Class<? extends Test> testClass) {
     177        boolean removed = false;
     178        if (!Arrays.asList(CORE_TEST_CLASSES).contains(testClass)) {
     179            removed = allTests.remove(testClass);
     180            allTestsMap.remove(testClass.getName());
     181        }
     182        return removed;
     183    }
     184
    168185    static {
    169186        for (Class<? extends Test> testClass : CORE_TEST_CLASSES) {
    170187            addTest(testClass);
  • test/unit/org/openstreetmap/josm/data/validation/OsmValidatorTest.java

     
    22package org.openstreetmap.josm.data.validation;
    33
    44import static org.junit.Assert.assertFalse;
     5import static org.junit.Assert.assertNotEquals;
    56import static org.junit.Assert.assertTrue;
    67
    78import org.junit.Before;
    89import org.junit.Rule;
    910import org.junit.Test;
     11import org.openstreetmap.josm.data.validation.tests.Addresses;
    1012import org.openstreetmap.josm.testutils.JOSMTestRules;
    1113
    1214import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    8385        assertTrue(OsmValidator.hasIgnoredError("1351:n_6871910559:w_733713588"));
    8486    }
    8587
     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
    86107}