source: josm/trunk/test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java@ 10956

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

see #12974 - Unit tests hang (patch by michael2402) - gsoc-core

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertNull;
7import static org.junit.Assert.assertTrue;
8
9import org.junit.Rule;
10import org.junit.Test;
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.Relation;
16import org.openstreetmap.josm.data.osm.RelationMember;
17import org.openstreetmap.josm.data.osm.Way;
18import org.openstreetmap.josm.gui.layer.Layer;
19import org.openstreetmap.josm.gui.layer.OsmDataLayer;
20import org.openstreetmap.josm.testutils.JOSMTestRules;
21
22/**
23 * Unit tests for class {@link SelectByInternalPointAction}.
24 */
25public final class SelectByInternalPointActionTest {
26
27 /**
28 * Setup test.
29 */
30 @Rule
31 public JOSMTestRules rules = new JOSMTestRules().preferences().projection();
32
33 /**
34 * Unit test - no dataset.
35 */
36 @Test
37 public void testNoDataSet() {
38 assertNull(Main.getLayerManager().getEditDataSet());
39 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size());
40 assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null));
41 SelectByInternalPointAction.performSelection(null, false, false);
42 }
43
44 private static Layer initDataSet() {
45 DataSet ds = new DataSet();
46 Node n1 = new Node(new EastNorth(1, 1));
47 Node n2 = new Node(new EastNorth(1, 2));
48 Node n3 = new Node(new EastNorth(2, 2));
49 Node n4 = new Node(new EastNorth(2, 1));
50 ds.addPrimitive(n1);
51 ds.addPrimitive(n2);
52 ds.addPrimitive(n3);
53 ds.addPrimitive(n4);
54 Way w = new Way();
55 w.addNode(n1);
56 w.addNode(n2);
57 w.addNode(n3);
58 w.addNode(n4);
59 w.addNode(n1);
60 assertTrue(w.isClosed());
61 ds.addPrimitive(w);
62 Relation r = new Relation();
63 r.addMember(new RelationMember("outer", w));
64 ds.addPrimitive(r);
65 OsmDataLayer layer = new OsmDataLayer(ds, "", null);
66 Main.getLayerManager().addLayer(layer);
67 return layer;
68 }
69
70 /**
71 * Unit test of {@link SelectByInternalPointAction#getSurroundingObjects} method.
72 */
73 @Test
74 public void testGetSurroundingObjects() {
75 initDataSet();
76 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size());
77 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(0, 0)).size());
78 assertEquals(1, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(1.5, 1.5)).size());
79 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(3, 3)).size());
80 }
81
82 /**
83 * Unit test of {@link SelectByInternalPointAction#getSmallestSurroundingObject} method.
84 */
85 @Test
86 public void testGetSmallestSurroundingObject() {
87 initDataSet();
88 assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null));
89 assertNotNull(SelectByInternalPointAction.getSmallestSurroundingObject(new EastNorth(1.5, 1.5)));
90 }
91
92 /**
93 * Unit test of {@link SelectByInternalPointAction#performSelection} method.
94 */
95 @Test
96 public void testPerformSelection() {
97 initDataSet();
98 DataSet ds = Main.getLayerManager().getEditDataSet();
99
100 assertEquals(0, ds.getSelected().size());
101 SelectByInternalPointAction.performSelection(null, false, false);
102 assertEquals(0, ds.getSelected().size());
103 SelectByInternalPointAction.performSelection(new EastNorth(0, 0), false, false);
104 assertEquals(0, ds.getSelected().size());
105 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, false);
106 assertEquals(1, ds.getSelected().size());
107 ds.clearSelection();
108 ds.addSelected(ds.getNodes());
109 assertEquals(4, ds.getSelected().size());
110 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), true, false);
111 assertEquals(5, ds.getSelected().size());
112 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, true);
113 assertEquals(4, ds.getSelected().size());
114 }
115}
Note: See TracBrowser for help on using the repository browser.