1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 |
|
---|
6 | import java.util.Arrays;
|
---|
7 |
|
---|
8 | import org.junit.Rule;
|
---|
9 | import org.junit.Test;
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
12 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
13 | import org.openstreetmap.josm.data.osm.Node;
|
---|
14 | import org.openstreetmap.josm.data.osm.Way;
|
---|
15 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
16 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
17 |
|
---|
18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests for class {@link UnJoinNodeWayAction}.
|
---|
22 | */
|
---|
23 | public final class UnJoinNodeWayActionTest {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Prepare the class for the test. The notification system must be disabled.
|
---|
27 | */
|
---|
28 | public static class UnJoinNodeWayActionTestClass extends UnJoinNodeWayAction {
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Disable notification.
|
---|
32 | */
|
---|
33 | @Override
|
---|
34 | public void notify(String msg, int messageType) {
|
---|
35 | return;
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Setup test.
|
---|
41 | */
|
---|
42 | @Rule
|
---|
43 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
44 | public JOSMTestRules test = new JOSMTestRules().platform();
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Test case: Ignore irrelevant nodes
|
---|
48 | * We create a three node way, then try to remove central node while another
|
---|
49 | * node outside is selected.
|
---|
50 | * see #10396
|
---|
51 | */
|
---|
52 | @Test
|
---|
53 | public void testTicket10396() {
|
---|
54 | DataSet dataSet = new DataSet();
|
---|
55 | OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
|
---|
56 |
|
---|
57 | Node n1 = new Node(new EastNorth(-1, -1));
|
---|
58 | Node n2 = new Node(new EastNorth(0, 0));
|
---|
59 | Node n3 = new Node(new EastNorth(1, -1));
|
---|
60 | Node n4 = new Node(new EastNorth(0, 1));
|
---|
61 | dataSet.addPrimitive(n1);
|
---|
62 | dataSet.addPrimitive(n2);
|
---|
63 | dataSet.addPrimitive(n3);
|
---|
64 | dataSet.addPrimitive(n4);
|
---|
65 |
|
---|
66 | Way w = new Way();
|
---|
67 | w.setNodes(Arrays.asList(new Node[] {n1, n2, n3}));
|
---|
68 | dataSet.addPrimitive(w);
|
---|
69 |
|
---|
70 | dataSet.addSelected(n2);
|
---|
71 | dataSet.addSelected(n4);
|
---|
72 | dataSet.addSelected(w);
|
---|
73 |
|
---|
74 | UnJoinNodeWayActionTestClass action = new UnJoinNodeWayActionTestClass();
|
---|
75 | action.setEnabled(true);
|
---|
76 | try {
|
---|
77 | Main.getLayerManager().addLayer(layer);
|
---|
78 | action.actionPerformed(null);
|
---|
79 | } finally {
|
---|
80 | // Ensure we clean the place before leaving, even if test fails.
|
---|
81 | Main.getLayerManager().removeLayer(layer);
|
---|
82 | }
|
---|
83 |
|
---|
84 | // Ensures node n2 remove from w
|
---|
85 | assertFalse("Node n2 wasn't removed from way w.", w.containsNode(n2));
|
---|
86 | }
|
---|
87 | }
|
---|