Changeset 19720 in josm for trunk/test
- Timestamp:
- 2026-11-29T16:53:50+01:00 (15 hours ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/actions/mapmode/ParallelWayActionTest.java
r19624 r19720 5 5 import static org.junit.jupiter.api.Assertions.assertTrue; 6 6 7 import java.awt.event.WindowFocusListener; 8 9 import org.awaitility.Awaitility; 10 import org.awaitility.Durations; 7 11 import org.junit.jupiter.api.BeforeEach; 8 12 import org.junit.jupiter.api.Test; … … 130 134 131 135 /** 136 * A drag whose mouse release was lost is dropped by the next press, which then starts a new drag. 137 * <p> 138 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/25012">#25012</a>: the press cleared the 139 * offset path but left the mode at dragging, so the next drag event threw a {@link NullPointerException}. 140 */ 141 @Test 142 void testNonRegression25012() { 143 Node a = new Node(LatLon.ZERO); 144 Node b = new Node(new LatLon(0, 0.0001)); 145 Way w = new Way(); 146 w.addNode(a); 147 w.addNode(b); 148 this.dataSet.addPrimitive(a); 149 this.dataSet.addPrimitive(b); 150 this.dataSet.addPrimitive(w); 151 this.map.selectMapMode(mapMode); 152 153 // a drag whose release never arrives, e.g. because the focus moved to another application 154 mapMode.mousePressed(MapModeUtils.mouseClickAt(new LatLon(0, 0.00005))); 155 Awaitility.await().pollDelay(Durations.FIVE_HUNDRED_MILLISECONDS).until(() -> true); 156 mapMode.mouseDragged(MapModeUtils.mouseClickAt(new LatLon(0, 0.00005))); 157 mapMode.mouseDragged(MapModeUtils.mouseClickAt(new LatLon(0.00005, 0.00005))); 158 assertEquals(3, this.dataSet.allPrimitives().size(), "nothing is created before the release"); 159 160 MapModeUtils.dragFromTo(new LatLon(0, 0.00005), new LatLon(-0.00005, 0.00005)); 161 assertEquals(2, this.dataSet.getWays().size(), this.dataSet.getWays().toString()); 162 assertEquals(6, this.dataSet.allPrimitives().size()); 163 } 164 165 /** 166 * Losing the focus cancels the drag in progress, and the late release does not create or select anything. 167 * <p> 168 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/25012">#25012</a>: the preview stayed on 169 * screen until the next click. 170 * @throws ReflectiveOperationException if the private fields cannot be accessed 171 */ 172 @Test 173 void testFocusLostCancelsDrag25012() throws ReflectiveOperationException { 174 Node a = new Node(LatLon.ZERO); 175 Node b = new Node(new LatLon(0, 0.0001)); 176 Way w = new Way(); 177 w.addNode(a); 178 w.addNode(b); 179 this.dataSet.addPrimitive(a); 180 this.dataSet.addPrimitive(b); 181 this.dataSet.addPrimitive(w); 182 this.map.selectMapMode(mapMode); 183 184 mapMode.mousePressed(MapModeUtils.mouseClickAt(new LatLon(0, 0.00005))); 185 Awaitility.await().pollDelay(Durations.FIVE_HUNDRED_MILLISECONDS).until(() -> true); 186 mapMode.mouseDragged(MapModeUtils.mouseClickAt(new LatLon(0, 0.00005))); 187 mapMode.mouseDragged(MapModeUtils.mouseClickAt(new LatLon(0.00005, 0.00005))); 188 assertEquals(Mode.DRAGGING, TestUtils.getPrivateField(mapMode, "mode")); 189 190 ((WindowFocusListener) TestUtils.getPrivateField(mapMode, "focusListener")).windowLostFocus(null); 191 assertEquals(Mode.NORMAL, TestUtils.getPrivateField(mapMode, "mode"), "the preview is still drawn"); 192 193 // the release arrives later, e.g. on a platform where it goes to the window of the press anyway, here back 194 // on the way, where a click would select it 195 this.dataSet.clearSelection(); 196 mapMode.mouseReleased(MapModeUtils.mouseClickAt(new LatLon(0, 0.00005))); 197 assertEquals(3, this.dataSet.allPrimitives().size(), "the cancelled drag has been committed"); 198 assertTrue(this.dataSet.getSelected().isEmpty(), "the release has been taken as a click"); 199 200 MapModeUtils.dragFromTo(new LatLon(0, 0.00005), new LatLon(-0.00005, 0.00005)); 201 assertEquals(6, this.dataSet.allPrimitives().size()); 202 } 203 204 /** 132 205 * Unit test of {@link Mode} enum. 133 206 */
Note:
See TracChangeset
for help on using the changeset viewer.
