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