Ticket #12974: patch-fix-12974-2.patch

File patch-fix-12974-2.patch, 8.9 KB (added by michael2402, 9 years ago)
  • test/unit/org/openstreetmap/josm/JOSMFixture.java

    diff --git a/test/unit/org/openstreetmap/josm/JOSMFixture.java b/test/unit/org/openstreetmap/josm/JOSMFixture.java
    index f08ca13..51fb2dc 100644
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm;
    33
     4import static org.junit.Assert.assertNull;
     5import static org.junit.Assert.assertTrue;
    46import static org.junit.Assert.fail;
    57
    68import java.io.File;
    import java.util.Locale;  
    1214
    1315import org.openstreetmap.josm.data.projection.Projections;
    1416import org.openstreetmap.josm.gui.MainApplication;
    15 import org.openstreetmap.josm.gui.layer.Layer;
    1617import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
    1718import org.openstreetmap.josm.gui.util.GuiHelper;
    1819import org.openstreetmap.josm.io.CertificateAmendment;
    public class JOSMFixture {  
    132133        if (Main.main == null) {
    133134            new MainApplication().initialize();
    134135        }
    135         if (Main.map == null) {
    136             Main.main.createMapFrame(null, null);
    137         } else {
    138             for (Layer l: Main.getLayerManager().getLayers()) {
    139                 Main.getLayerManager().removeLayer(l);
    140             }
    141         }
     136        Main.getLayerManager().resetState();
     137        assertTrue(Main.getLayerManager().getLayers().isEmpty());
     138        assertNull(Main.getLayerManager().getEditLayer());
     139        assertNull(Main.getLayerManager().getActiveLayer());
    142140    }
    143141}
  • test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java

    diff --git a/test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java b/test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java
    index 3ea8298..6e0a1b2 100644
    a b import static org.junit.Assert.assertNotNull;  
    66import static org.junit.Assert.assertNull;
    77import static org.junit.Assert.assertTrue;
    88
    9 import org.junit.BeforeClass;
     9import org.junit.Rule;
    1010import org.junit.Test;
    11 import org.openstreetmap.josm.JOSMFixture;
    1211import org.openstreetmap.josm.Main;
    1312import org.openstreetmap.josm.data.coor.EastNorth;
    1413import org.openstreetmap.josm.data.osm.DataSet;
    import org.openstreetmap.josm.data.osm.RelationMember;  
    1817import org.openstreetmap.josm.data.osm.Way;
    1918import org.openstreetmap.josm.gui.layer.Layer;
    2019import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     20import org.openstreetmap.josm.testutils.JOSMTestRules;
    2121
    2222/**
    2323 * Unit tests for class {@link SelectByInternalPointAction}.
    public final class SelectByInternalPointActionTest {  
    2727    /**
    2828     * Setup test.
    2929     */
    30     @BeforeClass
    31     public static void setUp() {
    32         JOSMFixture.createUnitTestFixture().init(true);
    33     }
     30    @Rule
     31    public JOSMTestRules rules = new JOSMTestRules().preferences().projection();
    3432
    3533    /**
    3634     * Unit test - no dataset.
    3735     */
    3836    @Test
    3937    public void testNoDataSet() {
    40         while (Main.main.hasEditLayer()) {
    41             Main.getLayerManager().removeLayer(Main.getLayerManager().getEditLayer());
    42         }
    43         assertNull(JosmAction.getCurrentDataSet());
     38        assertNull(Main.getLayerManager().getEditDataSet());
    4439        assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size());
    4540        assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null));
    4641        SelectByInternalPointAction.performSelection(null, false, false);
    public final class SelectByInternalPointActionTest {  
    7772     */
    7873    @Test
    7974    public void testGetSurroundingObjects() {
    80         Layer layer = initDataSet();
    81         try {
    82             assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size());
    83             assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(0, 0)).size());
    84             assertEquals(1, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(1.5, 1.5)).size());
    85             assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(3, 3)).size());
    86         } finally {
    87             // Ensure we clean the place before leaving, even if test fails.
    88             Main.getLayerManager().removeLayer(layer);
    89         }
     75        initDataSet();
     76        assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size());
     77        assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(0, 0)).size());
     78        assertEquals(1, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(1.5, 1.5)).size());
     79        assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(3, 3)).size());
    9080    }
    9181
    9282    /**
    public final class SelectByInternalPointActionTest {  
    9484     */
    9585    @Test
    9686    public void testGetSmallestSurroundingObject() {
    97         Layer layer = initDataSet();
    98         try {
    99             assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null));
    100             assertNotNull(SelectByInternalPointAction.getSmallestSurroundingObject(new EastNorth(1.5, 1.5)));
    101         } finally {
    102             // Ensure we clean the place before leaving, even if test fails.
    103             Main.getLayerManager().removeLayer(layer);
    104         }
     87        initDataSet();
     88        assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null));
     89        assertNotNull(SelectByInternalPointAction.getSmallestSurroundingObject(new EastNorth(1.5, 1.5)));
    10590    }
    10691
    10792    /**
    public final class SelectByInternalPointActionTest {  
    10994     */
    11095    @Test
    11196    public void testPerformSelection() {
    112         Layer layer = initDataSet();
    113         try {
    114             DataSet ds = JosmAction.getCurrentDataSet();
     97        initDataSet();
     98        DataSet ds = Main.getLayerManager().getEditDataSet();
    11599
    116             assertEquals(0, ds.getSelected().size());
    117             SelectByInternalPointAction.performSelection(null, false, false);
    118             assertEquals(0, ds.getSelected().size());
    119             SelectByInternalPointAction.performSelection(new EastNorth(0, 0), false, false);
    120             assertEquals(0, ds.getSelected().size());
    121             SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, false);
    122             assertEquals(1, ds.getSelected().size());
    123             ds.clearSelection();
    124             ds.addSelected(ds.getNodes());
    125             assertEquals(4, ds.getSelected().size());
    126             SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), true, false);
    127             assertEquals(5, ds.getSelected().size());
    128             SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, true);
    129             assertEquals(4, ds.getSelected().size());
    130         } finally {
    131             // Ensure we clean the place before leaving, even if test fails.
    132             Main.getLayerManager().removeLayer(layer);
    133         }
     100        assertEquals(0, ds.getSelected().size());
     101        SelectByInternalPointAction.performSelection(null, false, false);
     102        assertEquals(0, ds.getSelected().size());
     103        SelectByInternalPointAction.performSelection(new EastNorth(0, 0), false, false);
     104        assertEquals(0, ds.getSelected().size());
     105        SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, false);
     106        assertEquals(1, ds.getSelected().size());
     107        ds.clearSelection();
     108        ds.addSelected(ds.getNodes());
     109        assertEquals(4, ds.getSelected().size());
     110        SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), true, false);
     111        assertEquals(5, ds.getSelected().size());
     112        SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, true);
     113        assertEquals(4, ds.getSelected().size());
    134114    }
    135115}
  • 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 39dae30..5a49b02 100644
    a b public class JOSMTestRules implements TestRule {  
    156156     * @throws InitializationError If an error occured while creating the required environment.
    157157     */
    158158    protected void before() throws InitializationError {
     159        cleanUpFromJosmFixture();
     160
    159161        // Tests are running headless by default.
    160162        System.setProperty("java.awt.headless", "true");
    161163
    public class JOSMTestRules implements TestRule {  
    211213    }
    212214
    213215    /**
     216     * Clean up what test not using these test rules may have broken.
     217     */
     218    private void cleanUpFromJosmFixture() {
     219        Main.getLayerManager().resetState();
     220        Main.pref = null;
     221        Main.platform = null;
     222        Main.pref.put("osm-server.url", "invalid-server");
     223        System.gc();
     224    }
     225
     226    /**
    214227     * Clean up after running a test
    215228     */
    216229    protected void after() {