Changeset 10876 in josm for trunk


Ignore:
Timestamp:
2016-08-22T22:05:45+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13309 - fix unit tests (patch by michael2402) - gsoc-core

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/TagInfoExtract.groovy

    r10872 r10876  
    371371     */
    372372    def init() {
    373         Main.initApplicationPreferences()
    374373        Main.determinePlatformHook()
    375374        Main.pref.enableSaveOnPut(false)
  • trunk/src/org/openstreetmap/josm/Main.java

    r10858 r10876  
    168168     * Global application preferences
    169169     */
    170     public static Preferences pref;
     170    public static final Preferences pref = new Preferences();
    171171
    172172    /**
     
    513513     */
    514514    public static volatile PlatformHook platform;
    515 
    516     /**
    517      * Initializes {@code Main.pref} in normal application context.
    518      * @since 6471
    519      */
    520     public static void initApplicationPreferences() {
    521         Main.pref = new Preferences();
    522     }
    523515
    524516    /**
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r10839 r10876  
    779779    }
    780780
     781    /**
     782     * Resets the preferences to their initial state. This resets all values and file associations.
     783     * The default values and listeners are not removed.
     784     * <p>
     785     * It is meant to be called before {@link #init(boolean)}
     786     * @since 10876
     787     */
     788    public void resetToInitialState() {
     789        resetToDefault();
     790        preferencesDir = null;
     791        cacheDir = null;
     792        userdataDir = null;
     793        saveOnPut = true;
     794        initSuccessful = false;
     795    }
     796
     797    /**
     798     * Reset all values stored in this map to the default values. This clears the preferences.
     799     */
    781800    public final void resetToDefault() {
    782801        settingsMap.clear();
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r10824 r10876  
    326326        }
    327327
    328         initApplicationPreferences();
    329 
    330328        Policy.setPolicy(new Policy() {
    331329            // Permissions for plug-ins loaded when josm is started via webstart
  • trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java

    r10758 r10876  
    2020import org.junit.Assert;
    2121import org.junit.Before;
    22 import org.junit.BeforeClass;
     22import org.junit.Rule;
    2323import org.junit.Test;
    24 import org.openstreetmap.josm.JOSMFixture;
    25 import org.openstreetmap.josm.Main;
    2624import org.openstreetmap.josm.TestUtils;
    2725import org.openstreetmap.josm.data.Version;
    2826import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     27import org.openstreetmap.josm.testutils.JOSMTestRules;
     28
     29import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2930
    3031/**
     
    3334public class HttpClientTest {
    3435
     36    @Rule
     37    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     38    public JOSMTestRules test = new JOSMTestRules().preferences();
     39
    3540    private ProgressMonitor progress;
    36 
    37     @BeforeClass
    38     public static void setUpBeforeClass() {
    39         JOSMFixture.createFunctionalTestFixture().init();
    40     }
    4141
    4242    @Before
     
    173173    @Test
    174174    public void testOpenUrlGzip() throws IOException {
    175         Main.initApplicationPreferences();
    176175        final URL url = new URL("https://www.openstreetmap.org/trace/1613906/data");
    177176        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
     
    186185    @Test
    187186    public void testOpenUrlBzip() throws IOException {
    188         Main.initApplicationPreferences();
    189187        final URL url = new URL("https://www.openstreetmap.org/trace/785544/data");
    190188        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
     
    199197    @Test
    200198    public void testTicket9660() throws IOException {
    201         Main.initApplicationPreferences();
    202199        final URL url = new URL("http://www.openstreetmap.org/trace/1350010/data");
    203200        try (BufferedReader x = HttpClient.create(url).connect()
  • trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java

    r10850 r10876  
    9191        System.setProperty("josm.home", josmHome);
    9292        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    93         Main.initApplicationPreferences();
     93        Main.pref.resetToInitialState();
    9494        Main.pref.enableSaveOnPut(false);
    9595        I18n.init();
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java

    r10758 r10876  
    1717import org.openstreetmap.josm.JOSMFixture;
    1818import org.openstreetmap.josm.Main;
    19 import org.openstreetmap.josm.data.Preferences;
    2019import org.openstreetmap.josm.data.coor.EastNorth;
    2120import org.openstreetmap.josm.data.osm.DataSet;
     
    3231 */
    3332public class SelectActionTest {
    34 
    35     /**
    36      * Override some configuration variables without change in preferences.xml
    37      */
    38     static class PreferencesMock extends Preferences {
    39         @Override
    40         public synchronized int getInteger(String key, int def) {
    41             if ("edit.initial-move-delay".equals(key)) {
    42                 return 0;
    43             } else {
    44                 return super.getInteger(key, def);
    45             }
    46         }
    47     }
    4833
    4934    boolean nodesMerged;
     
    10489        dataSet.addSelected(w);
    10590
    106         Main.pref = new PreferencesMock();
     91        Main.pref.put("edit.initial-move-delay", "0");
    10792        Main.getLayerManager().addLayer(layer);
    10893        try {
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorterTest.java

    r8857 r10876  
    88
    99import org.junit.Assert;
    10 import org.junit.BeforeClass;
     10import org.junit.Before;
     11import org.junit.Rule;
    1112import org.junit.Test;
    12 import org.openstreetmap.josm.Main;
    1313import org.openstreetmap.josm.data.osm.DataSet;
    1414import org.openstreetmap.josm.data.osm.Relation;
    1515import org.openstreetmap.josm.data.osm.RelationMember;
    16 import org.openstreetmap.josm.data.projection.Projections;
    1716import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1817import org.openstreetmap.josm.io.IllegalDataException;
    1918import org.openstreetmap.josm.io.OsmReader;
     19import org.openstreetmap.josm.testutils.JOSMTestRules;
     20
     21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2022
    2123/**
     
    2527
    2628    private final RelationSorter sorter = new RelationSorter();
    27     private static DataSet testDataset;
     29    private DataSet testDataset;
    2830
    29     @BeforeClass
    30     public static void loadData() throws IllegalDataException, IOException {
    31         Main.initApplicationPreferences();
    32         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    33         try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
    34             testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     31    /**
     32     * Use Mercator projection
     33     */
     34    @Rule
     35    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     36    public JOSMTestRules test = new JOSMTestRules().preferences().projection();
     37
     38    /**
     39     * Load the test data set
     40     * @throws IllegalDataException if an error was found while parsing the data
     41     * @throws IOException in case of I/O error
     42     */
     43    @Before
     44    public void loadData() throws IllegalDataException, IOException {
     45        if (testDataset == null) {
     46            try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
     47                testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     48            }
    3549        }
    3650    }
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java

    r8857 r10876  
    99
    1010import org.junit.Assert;
    11 import org.junit.BeforeClass;
     11import org.junit.Before;
     12import org.junit.Rule;
    1213import org.junit.Test;
    13 import org.openstreetmap.josm.Main;
    1414import org.openstreetmap.josm.data.osm.DataSet;
    1515import org.openstreetmap.josm.data.osm.Relation;
    16 import org.openstreetmap.josm.data.projection.Projections;
    1716import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1817import org.openstreetmap.josm.io.IllegalDataException;
    1918import org.openstreetmap.josm.io.OsmReader;
     19import org.openstreetmap.josm.testutils.JOSMTestRules;
     20
     21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2022
    2123/**
     
    2628    private RelationSorter sorter = new RelationSorter();
    2729    private WayConnectionTypeCalculator wayConnectionTypeCalculator = new WayConnectionTypeCalculator();
    28     private static DataSet testDataset;
     30    private DataSet testDataset;
    2931
    30     @BeforeClass
    31     public static void loadData() throws IllegalDataException, IOException {
    32         Main.initApplicationPreferences();
    33         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    34         try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
    35             testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     32    /**
     33     * Use Mercator projection
     34     */
     35    @Rule
     36    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     37    public JOSMTestRules test = new JOSMTestRules().preferences().projection();
     38
     39    /**
     40     * Load the test data set
     41     * @throws IllegalDataException if an error was found while parsing the data
     42     * @throws IOException in case of I/O error
     43     */
     44    @Before
     45    public void loadData() throws IllegalDataException, IOException {
     46        if (testDataset == null) {
     47            try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
     48                testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     49            }
    3650        }
    3751    }
  • trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    r10604 r10876  
    201201        // Add preferences
    202202        if (usePreferences) {
    203             Main.initApplicationPreferences();
     203            Main.pref.resetToInitialState();
    204204            Main.pref.enableSaveOnPut(false);
    205205            // No pref init -> that would only create the preferences file.
     
    247247        MemoryManagerTest.resetState(true);
    248248        Main.getLayerManager().resetState();
    249         Main.pref = null;
     249        Main.pref.resetToInitialState();
    250250        Main.platform = null;
    251251        System.gc();
     
    268268
    269269        // TODO: Remove global listeners and other global state.
    270         Main.pref = null;
     270        Main.pref.resetToInitialState();;
    271271        Main.platform = null;
    272272        // Parts of JOSM uses weak references - destroy them.
Note: See TracChangeset for help on using the changeset viewer.