Index: /trunk/scripts/TagInfoExtract.groovy
===================================================================
--- /trunk/scripts/TagInfoExtract.groovy	(revision 10875)
+++ /trunk/scripts/TagInfoExtract.groovy	(revision 10876)
@@ -371,5 +371,4 @@
      */
     def init() {
-        Main.initApplicationPreferences()
         Main.determinePlatformHook()
         Main.pref.enableSaveOnPut(false)
Index: /trunk/src/org/openstreetmap/josm/Main.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/Main.java	(revision 10875)
+++ /trunk/src/org/openstreetmap/josm/Main.java	(revision 10876)
@@ -168,5 +168,5 @@
      * Global application preferences
      */
-    public static Preferences pref;
+    public static final Preferences pref = new Preferences();
 
     /**
@@ -513,12 +513,4 @@
      */
     public static volatile PlatformHook platform;
-
-    /**
-     * Initializes {@code Main.pref} in normal application context.
-     * @since 6471
-     */
-    public static void initApplicationPreferences() {
-        Main.pref = new Preferences();
-    }
 
     /**
Index: /trunk/src/org/openstreetmap/josm/data/Preferences.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/Preferences.java	(revision 10875)
+++ /trunk/src/org/openstreetmap/josm/data/Preferences.java	(revision 10876)
@@ -779,4 +779,23 @@
     }
 
+    /**
+     * Resets the preferences to their initial state. This resets all values and file associations.
+     * The default values and listeners are not removed.
+     * <p>
+     * It is meant to be called before {@link #init(boolean)}
+     * @since 10876
+     */
+    public void resetToInitialState() {
+        resetToDefault();
+        preferencesDir = null;
+        cacheDir = null;
+        userdataDir = null;
+        saveOnPut = true;
+        initSuccessful = false;
+    }
+
+    /**
+     * Reset all values stored in this map to the default values. This clears the preferences.
+     */
     public final void resetToDefault() {
         settingsMap.clear();
Index: /trunk/src/org/openstreetmap/josm/gui/MainApplication.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 10875)
+++ /trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 10876)
@@ -326,6 +326,4 @@
         }
 
-        initApplicationPreferences();
-
         Policy.setPolicy(new Policy() {
             // Permissions for plug-ins loaded when josm is started via webstart
Index: /trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java
===================================================================
--- /trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java	(revision 10875)
+++ /trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java	(revision 10876)
@@ -20,11 +20,12 @@
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.BeforeClass;
+import org.junit.Rule;
 import org.junit.Test;
-import org.openstreetmap.josm.JOSMFixture;
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.TestUtils;
 import org.openstreetmap.josm.data.Version;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
+import org.openstreetmap.josm.testutils.JOSMTestRules;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
 /**
@@ -33,10 +34,9 @@
 public class HttpClientTest {
 
+    @Rule
+    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
+    public JOSMTestRules test = new JOSMTestRules().preferences();
+
     private ProgressMonitor progress;
-
-    @BeforeClass
-    public static void setUpBeforeClass() {
-        JOSMFixture.createFunctionalTestFixture().init();
-    }
 
     @Before
@@ -173,5 +173,4 @@
     @Test
     public void testOpenUrlGzip() throws IOException {
-        Main.initApplicationPreferences();
         final URL url = new URL("https://www.openstreetmap.org/trace/1613906/data");
         try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
@@ -186,5 +185,4 @@
     @Test
     public void testOpenUrlBzip() throws IOException {
-        Main.initApplicationPreferences();
         final URL url = new URL("https://www.openstreetmap.org/trace/785544/data");
         try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
@@ -199,5 +197,4 @@
     @Test
     public void testTicket9660() throws IOException {
-        Main.initApplicationPreferences();
         final URL url = new URL("http://www.openstreetmap.org/trace/1350010/data");
         try (BufferedReader x = HttpClient.create(url).connect()
Index: /trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java	(revision 10875)
+++ /trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java	(revision 10876)
@@ -91,5 +91,5 @@
         System.setProperty("josm.home", josmHome);
         TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
-        Main.initApplicationPreferences();
+        Main.pref.resetToInitialState();
         Main.pref.enableSaveOnPut(false);
         I18n.init();
Index: /trunk/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java	(revision 10875)
+++ /trunk/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java	(revision 10876)
@@ -17,5 +17,4 @@
 import org.openstreetmap.josm.JOSMFixture;
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.Preferences;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.osm.DataSet;
@@ -32,18 +31,4 @@
  */
 public class SelectActionTest {
-
-    /**
-     * Override some configuration variables without change in preferences.xml
-     */
-    static class PreferencesMock extends Preferences {
-        @Override
-        public synchronized int getInteger(String key, int def) {
-            if ("edit.initial-move-delay".equals(key)) {
-                return 0;
-            } else {
-                return super.getInteger(key, def);
-            }
-        }
-    }
 
     boolean nodesMerged;
@@ -104,5 +89,5 @@
         dataSet.addSelected(w);
 
-        Main.pref = new PreferencesMock();
+        Main.pref.put("edit.initial-move-delay", "0");
         Main.getLayerManager().addLayer(layer);
         try {
Index: /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorterTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorterTest.java	(revision 10875)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorterTest.java	(revision 10876)
@@ -8,14 +8,16 @@
 
 import org.junit.Assert;
-import org.junit.BeforeClass;
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.RelationMember;
-import org.openstreetmap.josm.data.projection.Projections;
 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
 import org.openstreetmap.josm.io.IllegalDataException;
 import org.openstreetmap.josm.io.OsmReader;
+import org.openstreetmap.josm.testutils.JOSMTestRules;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
 /**
@@ -25,12 +27,24 @@
 
     private final RelationSorter sorter = new RelationSorter();
-    private static DataSet testDataset;
+    private DataSet testDataset;
 
-    @BeforeClass
-    public static void loadData() throws IllegalDataException, IOException {
-        Main.initApplicationPreferences();
-        Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
-        try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
-            testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
+    /**
+     * Use Mercator projection
+     */
+    @Rule
+    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
+    public JOSMTestRules test = new JOSMTestRules().preferences().projection();
+
+    /**
+     * Load the test data set
+     * @throws IllegalDataException if an error was found while parsing the data
+     * @throws IOException in case of I/O error
+     */
+    @Before
+    public void loadData() throws IllegalDataException, IOException {
+        if (testDataset == null) {
+            try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
+                testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
+            }
         }
     }
Index: /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java	(revision 10875)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java	(revision 10876)
@@ -9,13 +9,15 @@
 
 import org.junit.Assert;
-import org.junit.BeforeClass;
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Relation;
-import org.openstreetmap.josm.data.projection.Projections;
 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
 import org.openstreetmap.josm.io.IllegalDataException;
 import org.openstreetmap.josm.io.OsmReader;
+import org.openstreetmap.josm.testutils.JOSMTestRules;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
 /**
@@ -26,12 +28,24 @@
     private RelationSorter sorter = new RelationSorter();
     private WayConnectionTypeCalculator wayConnectionTypeCalculator = new WayConnectionTypeCalculator();
-    private static DataSet testDataset;
+    private DataSet testDataset;
 
-    @BeforeClass
-    public static void loadData() throws IllegalDataException, IOException {
-        Main.initApplicationPreferences();
-        Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
-        try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
-            testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
+    /**
+     * Use Mercator projection
+     */
+    @Rule
+    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
+    public JOSMTestRules test = new JOSMTestRules().preferences().projection();
+
+    /**
+     * Load the test data set
+     * @throws IllegalDataException if an error was found while parsing the data
+     * @throws IOException in case of I/O error
+     */
+    @Before
+    public void loadData() throws IllegalDataException, IOException {
+        if (testDataset == null) {
+            try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
+                testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
+            }
         }
     }
Index: /trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java	(revision 10875)
+++ /trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java	(revision 10876)
@@ -201,5 +201,5 @@
         // Add preferences
         if (usePreferences) {
-            Main.initApplicationPreferences();
+            Main.pref.resetToInitialState();
             Main.pref.enableSaveOnPut(false);
             // No pref init -> that would only create the preferences file.
@@ -247,5 +247,5 @@
         MemoryManagerTest.resetState(true);
         Main.getLayerManager().resetState();
-        Main.pref = null;
+        Main.pref.resetToInitialState();
         Main.platform = null;
         System.gc();
@@ -268,5 +268,5 @@
 
         // TODO: Remove global listeners and other global state.
-        Main.pref = null;
+        Main.pref.resetToInitialState();;
         Main.platform = null;
         // Parts of JOSM uses weak references - destroy them.
