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 {
|
621 | 621 | settingOld = settingsMap.get(key); |
622 | 622 | if (setting.equals(settingOld)) |
623 | 623 | 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)); |
625 | 626 | return false; |
| 627 | } |
626 | 628 | settingCopy = setting.copy(); |
627 | 629 | settingsMap.put(key, settingCopy); |
628 | 630 | } |
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;
|
10 | 10 | import java.security.GeneralSecurityException; |
11 | 11 | import java.text.MessageFormat; |
12 | 12 | import java.util.Arrays; |
| 13 | import java.util.Map; |
13 | 14 | import java.util.TimeZone; |
14 | 15 | import java.util.logging.Handler; |
15 | 16 | |
… |
… |
import org.openstreetmap.josm.io.OsmApiInitializationException;
|
40 | 41 | import org.openstreetmap.josm.io.OsmConnection; |
41 | 42 | import org.openstreetmap.josm.io.OsmTransferCanceledException; |
42 | 43 | import org.openstreetmap.josm.spi.preferences.Config; |
| 44 | import org.openstreetmap.josm.spi.preferences.Setting; |
43 | 45 | import org.openstreetmap.josm.tools.I18n; |
44 | 46 | import org.openstreetmap.josm.tools.JosmRuntimeException; |
45 | 47 | import org.openstreetmap.josm.tools.Logging; |
… |
… |
public class JOSMTestRules implements TestRule {
|
439 | 441 | |
440 | 442 | // Add preferences |
441 | 443 | if (usePreferences) { |
| 444 | @SuppressWarnings("unchecked") |
| 445 | final Map<String, Setting<?>> defaultsMap = (Map<String, Setting<?>>) TestUtils.getPrivateField(Main.pref, "defaultsMap"); |
| 446 | defaultsMap.clear(); |
| 447 | |
442 | 448 | Main.pref.resetToInitialState(); |
443 | 449 | Main.pref.enableSaveOnPut(false); |
444 | 450 | // No pref init -> that would only create the preferences file. |