From 459a78c23fc47e694bb5770f66015f226d1cdbf0 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 v2 06/28] 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 | 11 +++++++++++
.../openstreetmap/josm/testutils/JOSMTestRules.java | 21 +++++++++++----------
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/org/openstreetmap/josm/data/preferences/JosmBaseDirectories.java b/src/org/openstreetmap/josm/data/preferences/JosmBaseDirectories.java
index 16b81cfc8..feaac0608 100644
a
|
b
|
public final class JosmBaseDirectories implements IBaseDirectories {
|
154 | 154 | } |
155 | 155 | return cacheDir; |
156 | 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Clears any previously calculated values used for {@link #getPreferencesDirectory(boolean)}, |
| 160 | * {@link #getCacheDirectory(boolean)} or {@link #getUserDataDirectory(boolean)}. Useful for tests. |
| 161 | * @since xxx |
| 162 | */ |
| 163 | public void clearMemos() { |
| 164 | this.preferencesDir = null; |
| 165 | this.cacheDir = null; |
| 166 | this.userdataDir = null; |
| 167 | } |
157 | 168 | } |
diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
index ba23c441c..24394108f 100644
a
|
b
|
public class JOSMTestRules implements TestRule {
|
378 | 378 | TestUtils.setPrivateStaticField(Version.class, "instance", replacementVersion); |
379 | 379 | } |
380 | 380 | |
| 381 | // Add JOSM home |
| 382 | if (josmHome != null) { |
| 383 | try { |
| 384 | File home = josmHome.newFolder(); |
| 385 | System.setProperty("josm.home", home.getAbsolutePath()); |
| 386 | JosmBaseDirectories.getInstance().clearMemos(); |
| 387 | } catch (IOException e) { |
| 388 | throw new InitializationError(e); |
| 389 | } |
| 390 | } |
| 391 | |
381 | 392 | Config.setPreferencesInstance(Main.pref); |
382 | 393 | Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); |
383 | 394 | // All tests use the same timezone. |
… |
… |
public class JOSMTestRules implements TestRule {
|
396 | 407 | I18n.set(i18n); |
397 | 408 | } |
398 | 409 | |
399 | | // Add JOSM home |
400 | | if (josmHome != null) { |
401 | | try { |
402 | | File home = josmHome.newFolder(); |
403 | | System.setProperty("josm.home", home.getAbsolutePath()); |
404 | | } catch (IOException e) { |
405 | | throw new InitializationError(e); |
406 | | } |
407 | | } |
408 | | |
409 | 410 | // Add preferences |
410 | 411 | if (usePreferences) { |
411 | 412 | Main.pref.resetToInitialState(); |