Changeset 10443 in josm for trunk/test/unit


Ignore:
Timestamp:
2016-06-20T23:57:32+02:00 (8 years ago)
Author:
Don-vip
Message:

see #12974 - Unit tests hang (patch by michael2402) - gsoc-core

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java

    r10400 r10443  
    22package org.openstreetmap.josm;
    33
     4import static org.junit.Assert.assertNull;
     5import static org.junit.Assert.assertTrue;
    46import static org.junit.Assert.fail;
    57
     
    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;
     
    132133            new MainApplication().initialize();
    133134        }
    134         if (Main.map == null) {
    135             Main.main.createMapFrame(null, null);
    136         } else {
    137             for (Layer l: Main.getLayerManager().getLayers()) {
    138                 Main.getLayerManager().removeLayer(l);
    139             }
    140         }
     135        Main.getLayerManager().resetState();
     136        assertTrue(Main.getLayerManager().getLayers().isEmpty());
     137        assertNull(Main.getLayerManager().getEditLayer());
     138        assertNull(Main.getLayerManager().getActiveLayer());
    141139    }
    142140}
  • trunk/test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java

    r10436 r10443  
    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;
     
    1918import org.openstreetmap.josm.gui.layer.Layer;
    2019import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     20import org.openstreetmap.josm.testutils.JOSMTestRules;
    2121
    2222/**
     
    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    /**
     
    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));
     
    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
     
    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
     
    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}
  • trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    r10441 r10443  
    157157     */
    158158    protected void before() throws InitializationError {
     159        cleanUpFromJosmFixture();
     160
    159161        // Tests are running headless by default.
    160162        System.setProperty("java.awt.headless", "true");
     
    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     */
Note: See TracChangeset for help on using the changeset viewer.