1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import org.junit.BeforeClass;
|
---|
8 | import org.junit.Test;
|
---|
9 | import org.openstreetmap.josm.JOSMFixture;
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
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 |
|
---|
17 | /**
|
---|
18 | * Unit tests for class {@link UnGlueAction}.
|
---|
19 | */
|
---|
20 | public final class UnGlueActionTest {
|
---|
21 |
|
---|
22 | /** Class under test. */
|
---|
23 | private static UnGlueAction action;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup test.
|
---|
27 | */
|
---|
28 | @BeforeClass
|
---|
29 | public static void setUp() {
|
---|
30 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
31 | action = Main.main.menu.unglueNodes;
|
---|
32 | action.setEnabled(true);
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Test without any selection.
|
---|
37 | */
|
---|
38 | @Test
|
---|
39 | public void testSelectionEmpty() {
|
---|
40 | DataSet ds = new DataSet();
|
---|
41 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
42 | try {
|
---|
43 | Main.getLayerManager().addLayer(layer);
|
---|
44 | assertTrue(ds.getSelected().isEmpty());
|
---|
45 | assertTrue(ds.allPrimitives().isEmpty());
|
---|
46 | action.actionPerformed(null);
|
---|
47 | assertTrue(ds.allPrimitives().isEmpty());
|
---|
48 | } finally {
|
---|
49 | Main.getLayerManager().removeLayer(layer);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Test with a single node, that doesn't belong to a way.
|
---|
55 | */
|
---|
56 | @Test
|
---|
57 | public void testSingleNodeNotInWay() {
|
---|
58 | DataSet ds = new DataSet();
|
---|
59 | Node n = new Node(LatLon.ZERO);
|
---|
60 | ds.addPrimitive(n);
|
---|
61 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
62 | ds.setSelected(n);
|
---|
63 | try {
|
---|
64 | Main.getLayerManager().addLayer(layer);
|
---|
65 | assertEquals(1, ds.getSelected().size());
|
---|
66 | assertEquals(1, ds.allPrimitives().size());
|
---|
67 | action.actionPerformed(null);
|
---|
68 | assertEquals(1, ds.allPrimitives().size());
|
---|
69 | } finally {
|
---|
70 | Main.getLayerManager().removeLayer(layer);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Test with a single node, that belongs to a single way.
|
---|
76 | */
|
---|
77 | @Test
|
---|
78 | public void testSingleNodeInSingleWay() {
|
---|
79 | DataSet ds = new DataSet();
|
---|
80 | Node n1 = new Node(LatLon.ZERO);
|
---|
81 | ds.addPrimitive(n1);
|
---|
82 | Node n2 = new Node(new LatLon(1.0, 1.0));
|
---|
83 | ds.addPrimitive(n2);
|
---|
84 | Way w = new Way();
|
---|
85 | w.addNode(n1);
|
---|
86 | w.addNode(n2);
|
---|
87 | ds.addPrimitive(w);
|
---|
88 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
89 | ds.setSelected(n1);
|
---|
90 | try {
|
---|
91 | Main.getLayerManager().addLayer(layer);
|
---|
92 | assertEquals(1, ds.getSelected().size());
|
---|
93 | assertEquals(3, ds.allPrimitives().size());
|
---|
94 | action.actionPerformed(null);
|
---|
95 | assertEquals(3, ds.allPrimitives().size());
|
---|
96 | } finally {
|
---|
97 | Main.getLayerManager().removeLayer(layer);
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Test with a single node, that belongs to two ways.
|
---|
103 | */
|
---|
104 | @Test
|
---|
105 | public void testSingleNodeInTwoWays() {
|
---|
106 | DataSet ds = new DataSet();
|
---|
107 | Node n1 = new Node(LatLon.ZERO);
|
---|
108 | ds.addPrimitive(n1);
|
---|
109 | Node n2 = new Node(new LatLon(1.0, 1.0));
|
---|
110 | ds.addPrimitive(n2);
|
---|
111 | Way w1 = new Way();
|
---|
112 | w1.addNode(n1);
|
---|
113 | w1.addNode(n2);
|
---|
114 | ds.addPrimitive(w1);
|
---|
115 | Node n3 = new Node(new LatLon(-1.0, -1.0));
|
---|
116 | ds.addPrimitive(n3);
|
---|
117 | Way w2 = new Way();
|
---|
118 | w2.addNode(n1);
|
---|
119 | w2.addNode(n3);
|
---|
120 | ds.addPrimitive(w2);
|
---|
121 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
122 | ds.setSelected(n1);
|
---|
123 | try {
|
---|
124 | Main.getLayerManager().addLayer(layer);
|
---|
125 | assertEquals(1, ds.getSelected().size());
|
---|
126 | assertEquals(5, ds.allPrimitives().size());
|
---|
127 | action.actionPerformed(null);
|
---|
128 | assertEquals(6, ds.allPrimitives().size());
|
---|
129 | } finally {
|
---|
130 | Main.getLayerManager().removeLayer(layer);
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|