| | 1 | // License: GPL. For details, see LICENSE file. |
| | 2 | package org.openstreetmap.josm.actions; |
| | 3 | |
| | 4 | import static org.junit.Assert.assertTrue; |
| | 5 | |
| | 6 | import java.util.Arrays; |
| | 7 | |
| | 8 | import org.junit.Rule; |
| | 9 | import org.junit.Test; |
| | 10 | import org.openstreetmap.josm.data.coor.EastNorth; |
| | 11 | import org.openstreetmap.josm.data.osm.DataSet; |
| | 12 | import org.openstreetmap.josm.data.osm.Node; |
| | 13 | import org.openstreetmap.josm.data.osm.Way; |
| | 14 | import org.openstreetmap.josm.gui.MainApplication; |
| | 15 | import org.openstreetmap.josm.gui.layer.OsmDataLayer; |
| | 16 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
| | 17 | import org.openstreetmap.josm.tools.Geometry; |
| | 18 | |
| | 19 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| | 20 | |
| | 21 | /** |
| | 22 | * Unit tests for class {@link JoinNodeWayAction}. |
| | 23 | */ |
| | 24 | public final class JoinNodeWayActionTest { |
| | 25 | |
| | 26 | /** |
| | 27 | * Setup test. |
| | 28 | */ |
| | 29 | @Rule |
| | 30 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") |
| | 31 | public JOSMTestRules test = new JOSMTestRules().projection().main().preferences(); |
| | 32 | |
| | 33 | /** |
| | 34 | * Test case: Move node onto two overlapping ways |
| | 35 | * see #18189 moveontoway.osm |
| | 36 | */ |
| | 37 | @Test |
| | 38 | public void testTicket18189() { |
| | 39 | DataSet dataSet = new DataSet(); |
| | 40 | OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null); |
| | 41 | MainApplication.getLayerManager().addLayer(layer); |
| | 42 | Node n1 = new Node(new EastNorth(1, 1)); |
| | 43 | Node n2 = new Node(new EastNorth(5, 5)); |
| | 44 | Node n3 = new Node(new EastNorth(1, 1.000000001)); // very small difference |
| | 45 | Node n4 = new Node(new EastNorth(5, 5)); |
| | 46 | Node n5 = new Node(new EastNorth(3, 3.1)); // node to move |
| | 47 | |
| | 48 | dataSet.addPrimitive(n1); |
| | 49 | dataSet.addPrimitive(n2); |
| | 50 | dataSet.addPrimitive(n3); |
| | 51 | dataSet.addPrimitive(n4); |
| | 52 | dataSet.addPrimitive(n5); |
| | 53 | |
| | 54 | Way w1 = new Way(); |
| | 55 | w1.setNodes(Arrays.asList(n1, n2)); |
| | 56 | dataSet.addPrimitive(w1); |
| | 57 | Way w2 = new Way(); |
| | 58 | w2.setNodes(Arrays.asList(n3, n4)); |
| | 59 | dataSet.addPrimitive(w2); |
| | 60 | |
| | 61 | dataSet.addSelected(n5); |
| | 62 | EastNorth expected = Geometry.closestPointToSegment(n1.getEastNorth(), n2.getEastNorth(), n5.getEastNorth()); |
| | 63 | |
| | 64 | JoinNodeWayAction action = JoinNodeWayAction.createMoveNodeOntoWayAction(); |
| | 65 | action.setEnabled(true); |
| | 66 | action.actionPerformed(null); |
| | 67 | // Make sure the node was only moved once |
| | 68 | assertTrue("Node n5 wasn't added to way w1.", w1.containsNode(n5)); |
| | 69 | assertTrue("Node n5 wasn't added to way w2.", w2.containsNode(n5)); |
| | 70 | assertTrue("Node was moved too unexpected position", n5.getEastNorth().equalsEpsilon(expected, 1e-7)); |
| | 71 | } |
| | 72 | } |