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 SimplifyWayAction}.
|
---|
19 | */
|
---|
20 | public final class SimplifyWayActionTest {
|
---|
21 |
|
---|
22 | /** Class under test. */
|
---|
23 | private static SimplifyWayAction action;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup test.
|
---|
27 | */
|
---|
28 | @BeforeClass
|
---|
29 | public static void setUp() {
|
---|
30 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
31 | action = Main.main.menu.simplifyWay;
|
---|
32 | action.setEnabled(true);
|
---|
33 | }
|
---|
34 |
|
---|
35 | private static Way createWaySelected(DataSet ds, double latStart) {
|
---|
36 | Node n1 = new Node(new LatLon(latStart, 1.0));
|
---|
37 | ds.addPrimitive(n1);
|
---|
38 | Node n2 = new Node(new LatLon(latStart+1.0, 1.0));
|
---|
39 | ds.addPrimitive(n2);
|
---|
40 | Way w = new Way();
|
---|
41 | w.addNode(n1);
|
---|
42 | w.addNode(n2);
|
---|
43 | ds.addPrimitive(w);
|
---|
44 | ds.addSelected(w);
|
---|
45 | return w;
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Test without any selection.
|
---|
50 | */
|
---|
51 | @Test
|
---|
52 | public void testSelectionEmpty() {
|
---|
53 | DataSet ds = new DataSet();
|
---|
54 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
55 | try {
|
---|
56 | Main.main.addLayer(layer);
|
---|
57 | assertTrue(ds.getSelected().isEmpty());
|
---|
58 | action.actionPerformed(null);
|
---|
59 | } finally {
|
---|
60 | Main.main.removeLayer(layer);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Test with a single way.
|
---|
66 | */
|
---|
67 | @Test
|
---|
68 | public void testSingleWay() {
|
---|
69 | DataSet ds = new DataSet();
|
---|
70 | createWaySelected(ds, 0.0);
|
---|
71 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
72 | try {
|
---|
73 | Main.main.addLayer(layer);
|
---|
74 | assertEquals(1, ds.getSelected().size());
|
---|
75 | action.actionPerformed(null);
|
---|
76 | } finally {
|
---|
77 | Main.main.removeLayer(layer);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Test with more than 10 ways.
|
---|
83 | */
|
---|
84 | @Test
|
---|
85 | public void testMoreThanTenWays() {
|
---|
86 | DataSet ds = new DataSet();
|
---|
87 | for (int i = 0; i < 11; i++) {
|
---|
88 | createWaySelected(ds, i);
|
---|
89 | }
|
---|
90 | OsmDataLayer layer = new OsmDataLayer(ds, "", null);
|
---|
91 | try {
|
---|
92 | Main.main.addLayer(layer);
|
---|
93 | assertEquals(11, ds.getSelected().size());
|
---|
94 | action.actionPerformed(null);
|
---|
95 | } finally {
|
---|
96 | Main.main.removeLayer(layer);
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|