Changeset 14449 in josm


Ignore:
Timestamp:
2018-11-25T15:00:02+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #17027 - clean output of TaggingPresetPreferenceTestIT

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r14319 r14449  
    2121import java.util.Map;
    2222import java.util.Set;
     23import java.util.concurrent.CompletableFuture;
    2324import java.util.function.Predicate;
    2425
     
    128129    private boolean originalSelectionEmpty;
    129130
     131    /** The completable future task of asynchronous icon loading */
     132    private CompletableFuture<Void> iconFuture;
     133
    130134    /**
    131135     * Create an empty tagging preset. This will not have any items and
     
    215219        File arch = TaggingPresetReader.getZipIcons();
    216220        final Collection<String> s = Config.getPref().getList("taggingpreset.icon.sources", null);
    217         ImageProvider imgProv = new ImageProvider(iconName);
    218         imgProv.setDirs(s);
    219         imgProv.setId("presets");
    220         imgProv.setArchive(arch);
    221         imgProv.setOptional(true);
    222         imgProv.getResourceAsync(result -> {
    223             if (result != null) {
    224                 GuiHelper.runInEDT(() -> result.attachImageIcon(this));
    225             } else {
    226                 Logging.warn(toString() + ": " + PRESET_ICON_ERROR_MSG_PREFIX + iconName);
    227             }
    228         });
     221        this.iconFuture = new ImageProvider(iconName)
     222            .setDirs(s)
     223            .setId("presets")
     224            .setArchive(arch)
     225            .setOptional(true)
     226            .getResourceAsync(result -> {
     227                if (result != null) {
     228                    GuiHelper.runInEDT(() -> result.attachImageIcon(this));
     229                } else {
     230                    Logging.warn(toString() + ": " + PRESET_ICON_ERROR_MSG_PREFIX + iconName);
     231                }
     232            });
    229233    }
    230234
     
    648652        return actionParser.saveAction(new ToolbarPreferences.ActionDefinition(this));
    649653    }
     654
     655    /**
     656     * Returns the completable future task that performs icon loading, if any.
     657     * @return the completable future task that performs icon loading, or null
     658     * @since 14449
     659     */
     660    public CompletableFuture<Void> getIconLoadingTask() {
     661        return iconFuture;
     662    }
    650663}
  • trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java

    r13901 r14449  
    146146                    f.set(c, getValueForClass(f.getType(), value));
    147147                } else {
     148                    String setter;
    148149                    if (fieldName.startsWith(lang)) {
    149150                        int l = lang.length();
    150                         fieldName = "set" + fieldName.substring(l, l + 1).toUpperCase(Locale.ENGLISH) + fieldName.substring(l + 1);
     151                        setter = "set" + fieldName.substring(l, l + 1).toUpperCase(Locale.ENGLISH) + fieldName.substring(l + 1);
    151152                    } else {
    152                         fieldName = "set" + fieldName.substring(0, 1).toUpperCase(Locale.ENGLISH) + fieldName.substring(1);
     153                        setter = "set" + fieldName.substring(0, 1).toUpperCase(Locale.ENGLISH) + fieldName.substring(1);
    153154                    }
    154                     Method m = entry.getMethod(fieldName);
     155                    Method m = entry.getMethod(setter);
    155156                    if (m != null) {
    156157                        m.invoke(c, getValueForClass(m.getParameterTypes()[0], value));
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreferenceTestIT.java

    r14235 r14449  
    88import java.util.Collection;
    99import java.util.HashMap;
    10 import java.util.HashSet;
    1110import java.util.Map;
     11import java.util.Objects;
    1212import java.util.Set;
     13import java.util.TreeSet;
     14import java.util.concurrent.ExecutionException;
     15import java.util.concurrent.TimeUnit;
     16import java.util.concurrent.TimeoutException;
    1317
    1418import org.junit.Rule;
     
    5054        Config.getPref().putInt("socket.timeout.connect", 30);
    5155        Config.getPref().putInt("socket.timeout.read", 60);
    52         Map<Object, Throwable> allErrors = new HashMap<>();
    53         Set<String> allMessages = new HashSet<>();
     56        Map<String, Throwable> allErrors = new HashMap<>();
     57        Map<String, Set<String>> allMessages = new HashMap<>();
    5458        for (ExtendedSourceEntry source : sources) {
    5559            System.out.println(source.url);
     
    8387    }
    8488
    85     private static void testPresets(Set<String> allMessages, ExtendedSourceEntry source) throws SAXException, IOException {
     89    private static void testPresets(Map<String, Set<String>> allMessages, ExtendedSourceEntry source) throws SAXException, IOException {
    8690        Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, true);
    8791        assertFalse(presets.isEmpty());
     92        // wait for asynchronous icon loading
     93        presets.stream().map(TaggingPreset::getIconLoadingTask).filter(Objects::nonNull).forEach(t -> {
     94            try {
     95                t.get(30, TimeUnit.SECONDS);
     96            } catch (InterruptedException | ExecutionException | TimeoutException e) {
     97                Logging.error(e);
     98            }
     99        });
    88100        Collection<String> errorsAndWarnings = Logging.getLastErrorAndWarnings();
    89101        boolean error = false;
     
    93105                // ignore https://github.com/yopaseopor/traffic_signs_preset_JOSM because of far too frequent missing icons errors
    94106                if (!source.url.contains("yopaseopor/traffic_signs")) {
    95                     allMessages.add(message);
     107                    allMessages.computeIfAbsent(source.url, x -> new TreeSet<>()).add(message);
    96108                }
    97109            }
Note: See TracChangeset for help on using the changeset viewer.