Ticket #16010: v2-0021-JOSMTestRules-preferences-handling-clear-defaults.patch

File v2-0021-JOSMTestRules-preferences-handling-clear-defaults.patch, 3.0 KB (added by ris, 6 years ago)
  • src/org/openstreetmap/josm/data/Preferences.java

    From 2a3a6fe6e45fff64f12d999661eb2ad375f109d2 Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Mon, 7 May 2018 10:44:24 +0100
    Subject: [PATCH v2 21/28] JOSMTestRules preferences handling: clear
     defaultsMap between tests to provide better isolation
    
    also add log message when skipping the setting of a value due to defaults -
    this hint could save a lot of debugging time if noticed.
    ---
     src/org/openstreetmap/josm/data/Preferences.java              | 4 +++-
     test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java | 6 ++++++
     2 files changed, 9 insertions(+), 1 deletion(-)
    
    diff --git a/src/org/openstreetmap/josm/data/Preferences.java b/src/org/openstreetmap/josm/data/Preferences.java
    index 72189f66c..af88902c4 100644
    a b public class Preferences extends AbstractPreferences {  
    621621                settingOld = settingsMap.get(key);
    622622                if (setting.equals(settingOld))
    623623                    return false;
    624                 if (settingOld == null && setting.equals(defaultsMap.get(key)))
     624                if (settingOld == null && setting.equals(defaultsMap.get(key))) {
     625                    Logging.debug(tr("Not setting ''{0}'' to value ''{1}'': it appears to be the default", key, setting));
    625626                    return false;
     627                }
    626628                settingCopy = setting.copy();
    627629                settingsMap.put(key, settingCopy);
    628630            }
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
    index 048e87c6f..b24fc3939 100644
    a b import java.io.IOException;  
    1010import java.security.GeneralSecurityException;
    1111import java.text.MessageFormat;
    1212import java.util.Arrays;
     13import java.util.Map;
    1314import java.util.TimeZone;
    1415import java.util.logging.Handler;
    1516
    import org.openstreetmap.josm.io.OsmApiInitializationException;  
    4041import org.openstreetmap.josm.io.OsmConnection;
    4142import org.openstreetmap.josm.io.OsmTransferCanceledException;
    4243import org.openstreetmap.josm.spi.preferences.Config;
     44import org.openstreetmap.josm.spi.preferences.Setting;
    4345import org.openstreetmap.josm.tools.I18n;
    4446import org.openstreetmap.josm.tools.JosmRuntimeException;
    4547import org.openstreetmap.josm.tools.Logging;
    public class JOSMTestRules implements TestRule {  
    439441
    440442        // Add preferences
    441443        if (usePreferences) {
     444            @SuppressWarnings("unchecked")
     445            final Map<String, Setting<?>> defaultsMap = (Map<String, Setting<?>>) TestUtils.getPrivateField(Main.pref, "defaultsMap");
     446            defaultsMap.clear();
     447
    442448            Main.pref.resetToInitialState();
    443449            Main.pref.enableSaveOnPut(false);
    444450            // No pref init -> that would only create the preferences file.