Ignore:
Timestamp:
2016-05-29T10:37:31+02:00 (8 years ago)
Author:
bastiK
Message:

fixed #12885 - new method to add validator test from plugin (based on patch by by darya)

File:
1 edited

Legend:

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

    r10271 r10297  
    1717import java.util.Arrays;
    1818import java.util.Collection;
     19import java.util.Collections;
    1920import java.util.HashMap;
    2021import java.util.Map;
     
    8788
    8889    /**
    89      * All available tests
    90      * TODO: is there any way to find out automatically all available tests?
     90     * All registered tests
     91     */
     92    private static final Collection<Class<? extends Test>> allTests = new ArrayList<>();
     93    private static final Map<String, Test> allTestsMap = new HashMap<>();
     94
     95    /**
     96     * All available tests in core
    9197     */
    9298    @SuppressWarnings("unchecked")
    93     private static final Class<Test>[] allAvailableTests = new Class[] {
     99    private static final Class<Test>[] CORE_TEST_CLASSES = new Class[] {
    94100        /* FIXME - unique error numbers for tests aren't properly unique - ignoring will not work as expected */
    95101        DuplicateNode.class, // ID    1 ..   99
     
    133139    };
    134140
    135     private static Map<String, Test> allTestsMap;
     141    public static void addTest(Class<? extends Test> testClass) {
     142        allTests.add(testClass);
     143        try {
     144            allTestsMap.put(testClass.getName(), testClass.getConstructor().newInstance());
     145        } catch (ReflectiveOperationException e) {
     146            Main.error(e);
     147        }
     148    }
     149
    136150    static {
    137         allTestsMap = new HashMap<>();
    138         for (Class<Test> testClass : allAvailableTests) {
    139             try {
    140                 allTestsMap.put(testClass.getName(), testClass.getConstructor().newInstance());
    141             } catch (ReflectiveOperationException e) {
    142                 Main.error(e);
    143             }
     151        for (Class<? extends Test> testClass : CORE_TEST_CLASSES) {
     152            addTest(testClass);
    144153        }
    145154    }
     
    274283     * Gets the list of all available test classes
    275284     *
    276      * @return An array of the test classes
    277      */
    278     public static Class<Test>[] getAllAvailableTests() {
    279         return Utils.copyArray(allAvailableTests);
     285     * @return A collection of the test classes
     286     */
     287    public static Collection<Class<? extends Test>> getAllAvailableTestClasses() {
     288        return Collections.unmodifiableCollection(allTests);
    280289    }
    281290
Note: See TracChangeset for help on using the changeset viewer.