Changeset 12070 in josm


Ignore:
Timestamp:
2017-05-06T14:27:02+02:00 (23 months ago)
Author:
michael2402
Message:

Reset the SelectionEventManager listeners for each test.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/event/SelectionEventManager.java

    r12048 r12070  
    147147        }
    148148    };
     149
     150    /**
     151     * Only to be used during unit tests, to reset the state. Do not use it in plugins/other code.
     152     * Called after the layer manager was reset by the test framework.
     153     */
     154    public void resetState() {
     155        inEDTListeners.clear();
     156        normalListeners.clear();
     157        Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
     158    }
    149159}
  • trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java

    r11943 r12070  
    2121import org.openstreetmap.josm.io.CertificateAmendment;
    2222import org.openstreetmap.josm.io.OsmApi;
     23import org.openstreetmap.josm.testutils.JOSMTestRules;
    2324import org.openstreetmap.josm.tools.I18n;
    2425import org.openstreetmap.josm.tools.JosmRuntimeException;
     
    140141
    141142    private void setupGUI() {
    142         Main.getLayerManager().resetState();
     143        JOSMTestRules.cleanLayerEnvironment();
    143144        assertTrue(Main.getLayerManager().getLayers().isEmpty());
    144145        assertNull(Main.getLayerManager().getEditLayer());
  • trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    r11943 r12070  
    1515import org.openstreetmap.josm.JOSMFixture;
    1616import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    1718import org.openstreetmap.josm.data.projection.Projections;
    1819import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
     
    286287    private void cleanUpFromJosmFixture() {
    287288        MemoryManagerTest.resetState(true);
    288         Main.getLayerManager().resetState();
     289        cleanLayerEnvironment();
    289290        Main.pref.resetToInitialState();
    290291        Main.platform = null;
    291292        System.gc();
     293    }
     294
     295    /**
     296     * Cleans the Layer manager and the SelectionEventManager.
     297     * You don't need to call this during tests, the test environment will do it for you.
     298     * @since 12070
     299     */
     300    public static void cleanLayerEnvironment() {
     301        // Get the instance before cleaning - this ensures that it is initialized.
     302        SelectionEventManager eventManager = SelectionEventManager.getInstance();
     303        Main.getLayerManager().resetState();
     304        eventManager.resetState();
    292305    }
    293306
     
    304317        });
    305318        // Remove all layers
    306         Main.getLayerManager().resetState();
     319        cleanLayerEnvironment();
    307320        MemoryManagerTest.resetState(allowMemoryManagerLeaks);
    308321
Note: See TracChangeset for help on using the changeset viewer.