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

Last change on this file since 10378 was 9669, checked in by bastiK, 8 years ago

add missing svn:eol-style=native (see #12410)

  • Property svn:eol-style set to native
File size: 5.0 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.BeforeClass;
10import org.junit.Test;
11import org.openstreetmap.josm.JOSMFixture;
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.data.coor.EastNorth;
14import org.openstreetmap.josm.data.osm.DataSet;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.data.osm.Relation;
17import org.openstreetmap.josm.data.osm.RelationMember;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.gui.layer.Layer;
20import org.openstreetmap.josm.gui.layer.OsmDataLayer;
21
22/**
23 * Unit tests for class {@link SelectByInternalPointAction}.
24 */
25public final class SelectByInternalPointActionTest {
26
27 /**
28 * Setup test.
29 */
30 @BeforeClass
31 public static void setUp() {
32 JOSMFixture.createUnitTestFixture().init(true);
33 }
34
35 /**
36 * Unit test - no dataset.
37 */
38 @Test
39 public void testNoDataSet() {
40 while (Main.main.hasEditLayer()) {
41 Main.main.removeLayer(Main.main.getEditLayer());
42 }
43 assertNull(JosmAction.getCurrentDataSet());
44 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size());
45 assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null));
46 SelectByInternalPointAction.performSelection(null, false, false);
47 }
48
49 private static Layer initDataSet() {
50 DataSet ds = new DataSet();
51 Node n1 = new Node(new EastNorth(1, 1));
52 Node n2 = new Node(new EastNorth(1, 2));
53 Node n3 = new Node(new EastNorth(2, 2));
54 Node n4 = new Node(new EastNorth(2, 1));
55 ds.addPrimitive(n1);
56 ds.addPrimitive(n2);
57 ds.addPrimitive(n3);
58 ds.addPrimitive(n4);
59 Way w = new Way();
60 w.addNode(n1);
61 w.addNode(n2);
62 w.addNode(n3);
63 w.addNode(n4);
64 w.addNode(n1);
65 assertTrue(w.isClosed());
66 ds.addPrimitive(w);
67 Relation r = new Relation();
68 r.addMember(new RelationMember("outer", w));
69 ds.addPrimitive(r);
70 OsmDataLayer layer = new OsmDataLayer(ds, "", null);
71 Main.main.addLayer(layer);
72 return layer;
73 }
74
75 /**
76 * Unit test of {@link SelectByInternalPointAction#getSurroundingObjects} method.
77 */
78 @Test
79 public void testGetSurroundingObjects() {
80 Layer layer = initDataSet();
81 try {
82 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size());
83 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(0, 0)).size());
84 assertEquals(1, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(1.5, 1.5)).size());
85 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(3, 3)).size());
86 } finally {
87 // Ensure we clean the place before leaving, even if test fails.
88 Main.main.removeLayer(layer);
89 }
90 }
91
92 /**
93 * Unit test of {@link SelectByInternalPointAction#getSmallestSurroundingObject} method.
94 */
95 @Test
96 public void testGetSmallestSurroundingObject() {
97 Layer layer = initDataSet();
98 try {
99 assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null));
100 assertNotNull(SelectByInternalPointAction.getSmallestSurroundingObject(new EastNorth(1.5, 1.5)));
101 } finally {
102 // Ensure we clean the place before leaving, even if test fails.
103 Main.main.removeLayer(layer);
104 }
105 }
106
107 /**
108 * Unit test of {@link SelectByInternalPointAction#performSelection} method.
109 */
110 @Test
111 public void testPerformSelection() {
112 Layer layer = initDataSet();
113 try {
114 DataSet ds = JosmAction.getCurrentDataSet();
115
116 assertEquals(0, ds.getSelected().size());
117 SelectByInternalPointAction.performSelection(null, false, false);
118 assertEquals(0, ds.getSelected().size());
119 SelectByInternalPointAction.performSelection(new EastNorth(0, 0), false, false);
120 assertEquals(0, ds.getSelected().size());
121 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, false);
122 assertEquals(1, ds.getSelected().size());
123 ds.clearSelection();
124 ds.addSelected(ds.getNodes());
125 assertEquals(4, ds.getSelected().size());
126 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), true, false);
127 assertEquals(5, ds.getSelected().size());
128 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, true);
129 assertEquals(4, ds.getSelected().size());
130 } finally {
131 // Ensure we clean the place before leaving, even if test fails.
132 Main.main.removeLayer(layer);
133 }
134 }
135}
Note: See TracBrowser for help on using the repository browser.