source: josm/trunk/test/unit/org/openstreetmap/josm/actions/UnGlueActionTest.java@ 17360

Last change on this file since 17360 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertTrue;
6
7import org.junit.jupiter.api.BeforeEach;
8import org.junit.jupiter.api.Test;
9import org.junit.jupiter.api.extension.RegisterExtension;
10import org.openstreetmap.josm.data.coor.LatLon;
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 UnGlueAction}.
22 */
23final class UnGlueActionTest {
24
25 /** Class under test. */
26 private static UnGlueAction action;
27
28 /**
29 * Setup test.
30 */
31 @RegisterExtension
32 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
33 public JOSMTestRules test = new JOSMTestRules().main().projection().preferences();
34
35 /**
36 * Setup test.
37 */
38 @BeforeEach
39 public void setUp() {
40 if (action == null) {
41 action = MainApplication.getMenu().unglueNodes;
42 action.setEnabled(true);
43 }
44 }
45
46 /**
47 * Test without any selection.
48 */
49 @Test
50 void testSelectionEmpty() {
51 DataSet ds = new DataSet();
52 OsmDataLayer layer = new OsmDataLayer(ds, "", null);
53 try {
54 MainApplication.getLayerManager().addLayer(layer);
55 assertTrue(ds.getSelected().isEmpty());
56 assertTrue(ds.allPrimitives().isEmpty());
57 action.actionPerformed(null);
58 assertTrue(ds.allPrimitives().isEmpty());
59 } finally {
60 MainApplication.getLayerManager().removeLayer(layer);
61 }
62 }
63
64 /**
65 * Test with a single node, that doesn't belong to a way.
66 */
67 @Test
68 void testSingleNodeNotInWay() {
69 DataSet ds = new DataSet();
70 Node n = new Node(LatLon.ZERO);
71 ds.addPrimitive(n);
72 OsmDataLayer layer = new OsmDataLayer(ds, "", null);
73 ds.setSelected(n);
74 try {
75 MainApplication.getLayerManager().addLayer(layer);
76 assertEquals(1, ds.getSelected().size());
77 assertEquals(1, ds.allPrimitives().size());
78 action.actionPerformed(null);
79 assertEquals(1, ds.allPrimitives().size());
80 } finally {
81 MainApplication.getLayerManager().removeLayer(layer);
82 }
83 }
84
85 /**
86 * Test with a single node, that belongs to a single way.
87 */
88 @Test
89 void testSingleNodeInSingleWay() {
90 DataSet ds = new DataSet();
91 Node n1 = new Node(LatLon.ZERO);
92 ds.addPrimitive(n1);
93 Node n2 = new Node(new LatLon(1.0, 1.0));
94 ds.addPrimitive(n2);
95 Way w = new Way();
96 w.addNode(n1);
97 w.addNode(n2);
98 ds.addPrimitive(w);
99 OsmDataLayer layer = new OsmDataLayer(ds, "", null);
100 ds.setSelected(n1);
101 try {
102 MainApplication.getLayerManager().addLayer(layer);
103 assertEquals(1, ds.getSelected().size());
104 assertEquals(3, ds.allPrimitives().size());
105 action.actionPerformed(null);
106 assertEquals(3, ds.allPrimitives().size());
107 } finally {
108 MainApplication.getLayerManager().removeLayer(layer);
109 }
110 }
111
112 /**
113 * Test with a single node, that belongs to two ways.
114 */
115 @Test
116 void testSingleNodeInTwoWays() {
117 DataSet ds = new DataSet();
118 Node n1 = new Node(LatLon.ZERO);
119 ds.addPrimitive(n1);
120 Node n2 = new Node(new LatLon(1.0, 1.0));
121 ds.addPrimitive(n2);
122 Way w1 = new Way();
123 w1.addNode(n1);
124 w1.addNode(n2);
125 ds.addPrimitive(w1);
126 Node n3 = new Node(new LatLon(-1.0, -1.0));
127 ds.addPrimitive(n3);
128 Way w2 = new Way();
129 w2.addNode(n1);
130 w2.addNode(n3);
131 ds.addPrimitive(w2);
132 OsmDataLayer layer = new OsmDataLayer(ds, "", null);
133 ds.setSelected(n1);
134 try {
135 MainApplication.getLayerManager().addLayer(layer);
136 assertEquals(1, ds.getSelected().size());
137 assertEquals(5, ds.allPrimitives().size());
138 action.actionPerformed(null);
139 assertEquals(6, ds.allPrimitives().size());
140 } finally {
141 MainApplication.getLayerManager().removeLayer(layer);
142 }
143 }
144}
Note: See TracBrowser for help on using the repository browser.