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
|
b
|
public final class JosmBaseDirectories implements IBaseDirectories {
|
132 | 132 | } |
133 | 133 | return cacheDir; |
134 | 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Clears any previously calculated values used for {@link #getPreferencesDirectory()}, |
| 138 | * {@link #getCacheDirectory()} or {@link #getUserDataDirectory()}. Useful for tests. |
| 139 | */ |
| 140 | public void clearMemos() { |
| 141 | this.preferencesDir = null; |
| 142 | this.cacheDir = null; |
| 143 | this.userdataDir = null; |
| 144 | } |
135 | 145 | } |
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
|
b
|
public class JOSMTestRules implements TestRule {
|
367 | 367 | TestUtils.setPrivateStaticField(Version.class, "instance", replacementVersion); |
368 | 368 | } |
369 | 369 | |
| 370 | // Add JOSM home |
| 371 | if (josmHome != null) { |
| 372 | try { |
| 373 | File home = josmHome.newFolder(); |
| 374 | System.setProperty("josm.home", home.getAbsolutePath()); |
| 375 | JosmBaseDirectories.getInstance().clearMemos(); |
| 376 | } catch (IOException e) { |
| 377 | throw new InitializationError(e); |
| 378 | } |
| 379 | } |
| 380 | |
370 | 381 | Config.setPreferencesInstance(Main.pref); |
371 | 382 | Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); |
372 | 383 | // All tests use the same timezone. |
… |
… |
public class JOSMTestRules implements TestRule {
|
385 | 396 | I18n.set(i18n); |
386 | 397 | } |
387 | 398 | |
388 | | // Add JOSM home |
389 | | if (josmHome != null) { |
390 | | try { |
391 | | File home = josmHome.newFolder(); |
392 | | System.setProperty("josm.home", home.getAbsolutePath()); |
393 | | } catch (IOException e) { |
394 | | throw new InitializationError(e); |
395 | | } |
396 | | } |
397 | | |
398 | 399 | // Add preferences |
399 | 400 | if (usePreferences) { |
400 | 401 | Main.pref.resetToInitialState(); |