-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix JOSM #21902: IAE: Listener was not registered before
This is caused by (a) sharing an action between a menu and (b) a mapframe icon. This adds a non-regression test, and additionally modifies the AreaSelectorAction to override `readPreferences`, which is called when the map mode is entered. Furthermore, the MapMode class implements PreferenceChangedListener, which removes the need to notify the action manually about modified preferences. Signed-off-by: Taylor Smock <[email protected]>
- Loading branch information
Showing
5 changed files
with
65 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ bin | |
.svn | ||
build | ||
out | ||
test | ||
lib/jar | ||
lib/javadoc | ||
lib/source | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
test/unit/org/openstreetmap/josm/plugins/areaselector/AreaSelectorPluginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.openstreetmap.josm.plugins.areaselector; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
import java.util.jar.Attributes; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.openstreetmap.josm.data.osm.DataSet; | ||
import org.openstreetmap.josm.gui.MainApplication; | ||
import org.openstreetmap.josm.gui.MapFrame; | ||
import org.openstreetmap.josm.gui.layer.Layer; | ||
import org.openstreetmap.josm.gui.layer.OsmDataLayer; | ||
import org.openstreetmap.josm.plugins.PluginException; | ||
import org.openstreetmap.josm.plugins.PluginInformation; | ||
import org.openstreetmap.josm.testutils.JOSMTestRules; | ||
import org.openstreetmap.josm.testutils.annotations.BasicPreferences; | ||
|
||
/** | ||
* Test class for {@link AreaSelectorPlugin} | ||
* @author Taylor Smock | ||
*/ | ||
@BasicPreferences | ||
class AreaSelectorPluginTest { | ||
@RegisterExtension | ||
static JOSMTestRules josmTestRules = new JOSMTestRules().main().projection(); | ||
|
||
/** | ||
* Non-regression test for JOSM #21902. This occurs when someone removes all layers, adds a new layer, and then | ||
* removes all layers again. | ||
*/ | ||
@Test | ||
void testNonRegression21902() throws PluginException { | ||
assertDoesNotThrow(() -> AreaSelectorPlugin.class.getDeclaredMethod("mapFrameInitialized", MapFrame.class, MapFrame.class), "AreaSelector used to implement mapFrameInitialized"); | ||
final Attributes attributes = new Attributes(); | ||
attributes.put(new Attributes.Name("Plugin-Mainversion"), Integer.toString(10_000)); | ||
AreaSelectorPlugin plugin = new AreaSelectorPlugin(new PluginInformation(attributes, getClass().getSimpleName(), null)); | ||
MainApplication.getMainPanel().addMapFrameListener(plugin); | ||
// We have to go through this twice. So let us do it a few extra times, just in case. | ||
for (int i = 1; i <= 5; i++) { | ||
final Layer testLayer = new OsmDataLayer(new DataSet(), getClass().getSimpleName(), null); | ||
assertDoesNotThrow(() -> MainApplication.getLayerManager().addLayer(testLayer), "Failed on cycle " + i); | ||
assertDoesNotThrow(() -> MainApplication.getLayerManager().removeLayer(testLayer), "Failed on cycle " + i); | ||
} | ||
assertDoesNotThrow(() -> plugin.mapFrameInitialized(null, null)); | ||
} | ||
} |