Changeset 19227 in josm for trunk/test/unit


Ignore:
Timestamp:
2024-09-19T15:38:39+02:00 (3 months ago)
Author:
taylor.smock
Message:

Fix #20908: IllegalStateException: JOSM expected to find primitive in dataset after undoing a Parallel mode action

The test acts (roughly) like a user would, and performs click and drags via a new
utility class (MapModeUtils) which has various methods for performing mouse
actions on the map view.

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/ParallelWayActionTest.java

    r18870 r19227  
    55import static org.junit.jupiter.api.Assertions.assertTrue;
    66
     7import org.junit.jupiter.api.BeforeEach;
    78import org.junit.jupiter.api.Test;
    89import org.openstreetmap.josm.TestUtils;
    910import org.openstreetmap.josm.actions.mapmode.ParallelWayAction.Mode;
    1011import org.openstreetmap.josm.actions.mapmode.ParallelWayAction.Modifier;
     12import org.openstreetmap.josm.data.UndoRedoHandler;
     13import org.openstreetmap.josm.data.coor.LatLon;
    1114import org.openstreetmap.josm.data.osm.DataSet;
    1215import org.openstreetmap.josm.gui.MainApplication;
    1316import org.openstreetmap.josm.gui.MapFrame;
    1417import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     18import org.openstreetmap.josm.testutils.MapModeUtils;
    1519import org.openstreetmap.josm.testutils.annotations.Main;
    1620import org.openstreetmap.josm.testutils.annotations.Projection;
     21import org.openstreetmap.josm.tools.Logging;
    1722
    1823/**
     
    2227@Projection
    2328class ParallelWayActionTest {
     29    private MapFrame map;
     30    private ParallelWayAction mapMode;
     31    private DataSet dataSet;
     32
     33    @BeforeEach
     34    void setup() {
     35        OsmDataLayer layer = new OsmDataLayer(new DataSet(), "ParallelWayActionTest", null);
     36        MainApplication.getLayerManager().addLayer(layer);
     37        this.map = MainApplication.getMap();
     38        this.mapMode = new ParallelWayAction(this.map);
     39        this.dataSet = layer.getDataSet();
     40    }
     41
    2442    /**
    2543     * Unit test of {@link ParallelWayAction#enterMode} and {@link ParallelWayAction#exitMode}.
     
    2745    @Test
    2846    void testMode() {
    29         OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
    30         try {
    31             MainApplication.getLayerManager().addLayer(layer);
    32             MapFrame map = MainApplication.getMap();
    33             ParallelWayAction mapMode = new ParallelWayAction(map);
    34             MapMode oldMapMode = map.mapMode;
    35             assertTrue(map.selectMapMode(mapMode));
    36             assertEquals(mapMode, map.mapMode);
    37             assertTrue(map.selectMapMode(oldMapMode));
    38         } finally {
    39             MainApplication.getLayerManager().removeLayer(layer);
    40         }
     47        final MapMode oldMapMode = this.map.mapMode;
     48        assertTrue(this.map.selectMapMode(mapMode));
     49        assertEquals(this.mapMode, this.map.mapMode);
     50        assertTrue(this.map.selectMapMode(oldMapMode));
     51    }
     52
     53    /**
     54     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/20908">#20908</a>
     55     */
     56    @Test
     57    void testNonRegression20908() {
     58        Logging.clearLastErrorAndWarnings();
     59        this.map.selectMapMode(this.map.mapModeDraw);
     60        MapModeUtils.clickAt(LatLon.ZERO);
     61        MapModeUtils.clickAt(2, new LatLon(0.0001, 0));
     62        assertEquals(3, this.dataSet.allPrimitives().size());
     63        this.map.selectMapMode(mapMode);
     64        MapModeUtils.dragFromTo(new LatLon(0.00005, 0), new LatLon(0.00005, 0.0001));
     65        assertEquals(6, this.dataSet.allPrimitives().size());
     66        UndoRedoHandler.getInstance().undo();
     67        assertEquals(3, this.dataSet.allPrimitives().size());
     68        this.map.mapMode.mousePressed(MapModeUtils.mouseClickAt(new LatLon(0.00005, 0.0001)));
     69        assertTrue(Logging.getLastErrorAndWarnings().isEmpty(), String.join("\n", Logging.getLastErrorAndWarnings()));
    4170    }
    4271
  • trunk/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java

    r19226 r19227  
    8787        );
    8888    }
     89
    8990    /**
    9091     * Test of {@link ExceptionUtil#explainBadRequest} method.
     
    9495    @SuppressWarnings("unchecked")
    9596    void testExplainBadRequest(Supplier<String> message, Object exception) {
    96         assertEquals(message.get(), ExceptionUtil.explainBadRequest(exception instanceof Supplier ? ((Supplier<OsmApiException>) exception).get() : (OsmApiException) exception));
     97        assertEquals(message.get(), ExceptionUtil.explainBadRequest(
     98                exception instanceof Supplier ? ((Supplier<OsmApiException>) exception).get() : (OsmApiException) exception
     99        ));
    97100    }
    98101
Note: See TracChangeset for help on using the changeset viewer.