Changeset 15603 in josm for trunk


Ignore:
Timestamp:
2019-12-21T03:15:48+01:00 (5 years ago)
Author:
Don-vip
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r15588 r15603  
    166166    }
    167167
     168    /**
     169     * Removes a test from the list of available tests. This will not remove
     170     * core tests.
     171     *
     172     * @param testClass The test class
     173     * @return {@code true} if the test was removed (see {@link Collection#remove})
     174     * @since 15603
     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) {
  • trunk/test/unit/org/openstreetmap/josm/data/validation/OsmValidatorTest.java

    r15460 r15603  
    33
    44import static org.junit.Assert.assertFalse;
     5import static org.junit.Assert.assertNotEquals;
    56import static org.junit.Assert.assertTrue;
    67
     
    89import org.junit.Rule;
    910import org.junit.Test;
     11import org.openstreetmap.josm.data.validation.tests.Addresses;
    1012import org.openstreetmap.josm.testutils.JOSMTestRules;
    1113
     
    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}
Note: See TracChangeset for help on using the changeset viewer.