From 85aab3b728d7a47ad0e0261f7049497b888dca3b Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Wed, 21 Feb 2018 21:51:24 +0000
Subject: [PATCH v1 4/5] JOSMTestRules: clear JosmBaseDirectories memo-ized
 values to ensure new josm home setting takes effect

This requires adding a new public method to JosmBaseDirectories but
otherwise our new home directory setting has no effect and contents between
tests are liable to collide.
---
 .../josm/data/preferences/JosmBaseDirectories.java  | 10 ++++++++++
 .../openstreetmap/josm/testutils/JOSMTestRules.java | 21 +++++++++++----------
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/org/openstreetmap/josm/data/preferences/JosmBaseDirectories.java b/src/org/openstreetmap/josm/data/preferences/JosmBaseDirectories.java
index 7e2009b7a..64581e551 100644
--- a/src/org/openstreetmap/josm/data/preferences/JosmBaseDirectories.java
+++ b/src/org/openstreetmap/josm/data/preferences/JosmBaseDirectories.java
@@ -132,4 +132,14 @@ public final class JosmBaseDirectories implements IBaseDirectories {
         }
         return cacheDir;
     }
+
+    /**
+     * Clears any previously calculated values used for {@link #getPreferencesDirectory()},
+     * {@link #getCacheDirectory()} or {@link #getUserDataDirectory()}. Useful for tests.
+     */
+    public void clearMemos() {
+        this.preferencesDir = null;
+        this.cacheDir = null;
+        this.userdataDir = null;
+    }
 }
diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
index 6c6bdbaa2..ff3c9420d 100644
--- a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
+++ b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
@@ -367,6 +367,17 @@ public class JOSMTestRules implements TestRule {
             TestUtils.setPrivateStaticField(Version.class, "instance", replacementVersion);
         }
 
+        // Add JOSM home
+        if (josmHome != null) {
+            try {
+                File home = josmHome.newFolder();
+                System.setProperty("josm.home", home.getAbsolutePath());
+                JosmBaseDirectories.getInstance().clearMemos();
+            } catch (IOException e) {
+                throw new InitializationError(e);
+            }
+        }
+
         Config.setPreferencesInstance(Main.pref);
         Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
         // All tests use the same timezone.
@@ -385,16 +396,6 @@ public class JOSMTestRules implements TestRule {
             I18n.set(i18n);
         }
 
-        // Add JOSM home
-        if (josmHome != null) {
-            try {
-                File home = josmHome.newFolder();
-                System.setProperty("josm.home", home.getAbsolutePath());
-            } catch (IOException e) {
-                throw new InitializationError(e);
-            }
-        }
-
         // Add preferences
         if (usePreferences) {
             Main.pref.resetToInitialState();
-- 
2.11.0

