Changeset 10876 in josm for trunk/test/unit


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/test/unit/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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.