Changeset 8937 in josm


Ignore:
Timestamp:
2015-10-24T00:54:52+02:00 (6 years ago)
Author:
Don-vip
Message:

add unit tests to check validity of all map paint styles and tagging presets

Location:
trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r8512 r8937  
    1111import java.util.Arrays;
    1212import java.util.Collection;
     13import java.util.Collections;
    1314import java.util.HashSet;
    1415import java.util.LinkedList;
     
    266267            }
    267268        }
    268         if (Main.isDebugEnabled()) {
     269        if (Main.isDebugEnabled() || !source.getErrors().isEmpty()) {
    269270            final long elapsedTime = System.currentTimeMillis() - startTime;
    270             Main.debug("Initializing map style " + source.url + " completed in " + Utils.getDurationString(elapsedTime));
     271            String message = "Initializing map style " + source.url + " completed in " + Utils.getDurationString(elapsedTime);
     272            if (!source.getErrors().isEmpty()) {
     273                Main.warn(message + " (" + source.getErrors().size() + " errors)");
     274            } else {
     275                Main.debug(message);
     276            }
    271277        }
    272278    }
     
    433439    }
    434440
    435     public static void addStyle(SourceEntry entry) {
     441    /**
     442     * Add a new map paint style.
     443     * @param entry map paint style
     444     * @return list of errors that occured during loading
     445     */
     446    public static Collection<Throwable> addStyle(SourceEntry entry) {
    436447        StyleSource source = fromSourceEntry(entry);
    437448        if (source != null) {
     
    441452            fireMapPaintSylesUpdated();
    442453            styles.clearCached();
    443             Main.map.mapView.repaint();
    444         }
     454            if (Main.isDisplayingMapView()) {
     455                Main.map.mapView.repaint();
     456            }
     457            return source.getErrors();
     458        }
     459        return Collections.emptyList();
    445460    }
    446461
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r8926 r8937  
    8383    public static final String OPTIONAL_TOOLTIP_TEXT = "Optional tooltip text";
    8484
     85    /** Prefix of preset icon loading failure error message */
     86    public static final String PRESET_ICON_ERROR_MSG_PREFIX = "Could not get presets icon ";
     87
    8588    public TaggingPresetMenu group;
    8689    public String name;
     
    166169     * Called from the XML parser to set the icon.
    167170     * The loading task is performed in the background in order to speedup startup.
     171     * @param iconName icon name
    168172     */
    169173    public void setIcon(final String iconName) {
     
    190194                    });
    191195                } else {
    192                     Main.warn("Could not get presets icon " + iconName);
     196                    Main.warn(PRESET_ICON_ERROR_MSG_PREFIX + iconName);
    193197                }
    194198            }
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/validator/ValidatorTagCheckerRulesPreferenceTest.java

    r8936 r8937  
    66
    77import java.io.IOException;
     8import java.util.ArrayList;
    89import java.util.Collection;
    910
     
    3536     */
    3637    @Test
    37     public void testValidityOfAvailableSources() throws ParseException, IOException {
     38    public void testValidityOfAvailableRules() throws ParseException, IOException {
    3839        Collection<ExtendedSourceEntry> sources = new ValidatorTagCheckerRulesPreference.TagCheckerRulesSourceEditor()
    3940                .loadAndGetAvailableSources();
    4041        assertFalse(sources.isEmpty());
     42        Collection<Throwable> allErrors = new ArrayList<>();
    4143        MapCSSTagChecker tagChecker = new MapCSSTagChecker();
    4244        for (ExtendedSourceEntry source : sources) {
     
    4446            ParseResult result = tagChecker.addMapCSS(source.url);
    4547            assertFalse(result.parseChecks.isEmpty());
    46             assertTrue(result.parseErrors.isEmpty());
    47             System.out.println(" => OK");
     48            System.out.println(result.parseErrors.isEmpty() ? " => OK" : " => KO");
     49            allErrors.addAll(result.parseErrors);
    4850        }
     51        assertTrue(allErrors.isEmpty());
    4952    }
    5053}
Note: See TracChangeset for help on using the changeset viewer.