source: josm/trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java@ 8276

Last change on this file since 8276 was 8276, checked in by Balaitous, 9 years ago

fix #11184 - "split way" is splitting an other way instead of the selected.
The case where the selected node is both one end and an intermediate node of the selected way was not taken into account.
Add test case.

File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.junit.Assert.assertTrue;
5
6import java.util.Arrays;
7
8import org.junit.BeforeClass;
9import org.junit.Test;
10import org.openstreetmap.josm.JOSMFixture;
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.coor.EastNorth;
13import org.openstreetmap.josm.data.osm.DataSet;
14import org.openstreetmap.josm.data.osm.Node;
15import org.openstreetmap.josm.data.osm.Way;
16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
17
18/**
19 * Unit tests for class SplitWayAction.
20 */
21public final class SplitWayActionTest {
22
23 /** Class under test. */
24 private static SplitWayAction action;
25
26 /**
27 * Setup test.
28 */
29 @BeforeClass
30 public static void setUp() {
31 JOSMFixture.createUnitTestFixture().init(true);
32
33 // Enable "Align in line" feature.
34 action = Main.main.menu.splitWay;
35 action.setEnabled(true);
36 }
37
38 /**
39 * Test case: When node is share by multiple ways, split selected way.
40 * see #11184
41 */
42 @Test
43 public void test11184() throws Exception {
44 DataSet dataSet = new DataSet();
45 OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
46
47 Node n1 = new Node(new EastNorth(0, 0));
48 Node n2 = new Node(new EastNorth(-1, 1));
49 Node n3 = new Node(new EastNorth(1, 1));
50 Node n4 = new Node(new EastNorth(-1, -1));
51 Node n5 = new Node(new EastNorth(1, -1));
52 Node n6 = new Node(new EastNorth(-1, 0));
53 Node n7 = new Node(new EastNorth(1, 0));
54 dataSet.addPrimitive(n1);
55 dataSet.addPrimitive(n2);
56 dataSet.addPrimitive(n3);
57 dataSet.addPrimitive(n4);
58 dataSet.addPrimitive(n5);
59 dataSet.addPrimitive(n6);
60 dataSet.addPrimitive(n7);
61
62 Way w1 = new Way();
63 Node[] w1NodesArray = new Node[] {n6, n1, n7};
64 w1.setNodes(Arrays.asList(w1NodesArray));
65 Way w2 = new Way();
66 w2.setNodes(Arrays.asList(new Node[] {n1, n2, n3, n1, n4, n5, n1}));
67 dataSet.addPrimitive(w1);
68 dataSet.addPrimitive(w2);
69
70 dataSet.addSelected(n1);
71 dataSet.addSelected(w2);
72
73 try {
74 Main.main.addLayer(layer);
75 action.actionPerformed(null);
76 } finally {
77 // Ensure we clean the place before leaving, even if test fails.
78 Main.map.mapView.removeLayer(layer);
79 }
80
81 // Ensures 3 ways.
82 assertTrue(String.format("Found %d ways after split action instead of 3.",
83 dataSet.getWays().size()),
84 dataSet.getWays().size() == 3);
85
86 // Ensures way w1 is unchanged.
87 assertTrue("Unselected ways disappear during split action.",
88 dataSet.getWays().contains(w1));
89 assertTrue("Unselected way seems to have change during split action.",
90 w1.getNodesCount() == 3);
91 for(int i = 0; i < 3; i++) {
92 assertTrue("Node change in unselected way during split action.",
93 w1.getNode(i) == w1NodesArray[i]);
94 }
95 }
96}
Note: See TracBrowser for help on using the repository browser.