Ticket #16010: v2-0006-JOSMTestRules-clear-JosmBaseDirectories-memo-ized.patch

File v2-0006-JOSMTestRules-clear-JosmBaseDirectories-memo-ized.patch, 3.0 KB (added by ris, 15 months ago)
  • src/org/openstreetmap/josm/data/preferences/JosmBaseDirectories.java

    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 { 
    154154        }
    155155        return cacheDir;
    156156    }
     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    }
    157168}
  • 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 ba23c441c..24394108f 100644
    a b public class JOSMTestRules implements TestRule { 
    378378            TestUtils.setPrivateStaticField(Version.class, "instance", replacementVersion);
    379379        }
    380380
     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
    381392        Config.setPreferencesInstance(Main.pref);
    382393        Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
    383394        // All tests use the same timezone.
    public class JOSMTestRules implements TestRule { 
    396407            I18n.set(i18n);
    397408        }
    398409
    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 
    409410        // Add preferences
    410411        if (usePreferences) {
    411412            Main.pref.resetToInitialState();