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

Last change on this file since 10758 was 10758, checked in by Don-vip, 8 years ago

sonar - squid:S3578 - Test methods should comply with a naming convention

  • Property svn:eol-style set to native
File size: 2.5 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.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 {@link UnJoinNodeWayAction}.
20 */
21public final class UnJoinNodeWayActionTest {
22
23 /**
24 * Prepare the class for the test. The notification system must be disabled.
25 */
26 public static class UnJoinNodeWayActionTestClass extends UnJoinNodeWayAction {
27
28 /**
29 * Disable notification.
30 */
31 @Override
32 public void notify(String msg, int messageType) {
33 return;
34 }
35 }
36
37 /**
38 * Setup test.
39 */
40 @BeforeClass
41 public static void setUp() {
42 JOSMFixture.createUnitTestFixture().init(true);
43 }
44
45 /**
46 * Test case: Ignore irrelevant nodes
47 * We create a three node way, then try to remove central node while another
48 * node outside is selected.
49 * see #10396
50 */
51 @Test
52 public void testTicket10396() {
53 DataSet dataSet = new DataSet();
54 OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
55
56 Node n1 = new Node(new EastNorth(-1, -1));
57 Node n2 = new Node(new EastNorth(0, 0));
58 Node n3 = new Node(new EastNorth(1, -1));
59 Node n4 = new Node(new EastNorth(0, 1));
60 dataSet.addPrimitive(n1);
61 dataSet.addPrimitive(n2);
62 dataSet.addPrimitive(n3);
63 dataSet.addPrimitive(n4);
64
65 Way w = new Way();
66 w.setNodes(Arrays.asList(new Node[] {n1, n2, n3}));
67 dataSet.addPrimitive(w);
68
69 dataSet.addSelected(n2);
70 dataSet.addSelected(n4);
71 dataSet.addSelected(w);
72
73 UnJoinNodeWayActionTestClass action = new UnJoinNodeWayActionTestClass();
74 action.setEnabled(true);
75 try {
76 Main.getLayerManager().addLayer(layer);
77 action.actionPerformed(null);
78 } finally {
79 // Ensure we clean the place before leaving, even if test fails.
80 Main.getLayerManager().removeLayer(layer);
81 }
82
83 // Ensures node n2 remove from w
84 assertFalse("Node n2 wasn't removed from way w.", w.containsNode(n2));
85 }
86}
Note: See TracBrowser for help on using the repository browser.