source: josm/trunk/test/unit/org/openstreetmap/josm/actions/UnJoinNodeWayActionTest.java@ 14219

Last change on this file since 14219 was 14138, checked in by Don-vip, 6 years ago

see #15229 - deprecate Main.platform and related methods - new class PlatformManager

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.junit.Assert.assertFalse;
5
6import java.util.Arrays;
7
8import org.junit.Rule;
9import org.junit.Test;
10import org.openstreetmap.josm.data.coor.EastNorth;
11import org.openstreetmap.josm.data.osm.DataSet;
12import org.openstreetmap.josm.data.osm.Node;
13import org.openstreetmap.josm.data.osm.Way;
14import org.openstreetmap.josm.gui.MainApplication;
15import org.openstreetmap.josm.gui.layer.OsmDataLayer;
16import org.openstreetmap.josm.testutils.JOSMTestRules;
17
18import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19
20/**
21 * Unit tests for class {@link UnJoinNodeWayAction}.
22 */
23public 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();
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 MainApplication.getLayerManager().addLayer(layer);
78 action.actionPerformed(null);
79 } finally {
80 // Ensure we clean the place before leaving, even if test fails.
81 MainApplication.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}
Note: See TracBrowser for help on using the repository browser.