Ticket #16010: v1-0004-JOSMTestRules-clear-JosmBaseDirectories-memo-ized.patch

File v1-0004-JOSMTestRules-clear-JosmBaseDirectories-memo-ized.patch, 3.0 KB (added by ris, 3 years ago)
  • src/org/openstreetmap/josm/data/preferences/JosmBaseDirectories.java

    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 { 
    132132        }
    133133        return cacheDir;
    134134    }
     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    }
    135145}
  • 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 6c6bdbaa2..ff3c9420d 100644
    a b public class JOSMTestRules implements TestRule { 
    367367            TestUtils.setPrivateStaticField(Version.class, "instance", replacementVersion);
    368368        }
    369369
     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
    370381        Config.setPreferencesInstance(Main.pref);
    371382        Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
    372383        // All tests use the same timezone.
    public class JOSMTestRules implements TestRule { 
    385396            I18n.set(i18n);
    386397        }
    387398
    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 
    398399        // Add preferences
    399400        if (usePreferences) {
    400401            Main.pref.resetToInitialState();