source: josm/trunk/test/unit/org/openstreetmap/josm/actions/SimplifyWayActionTest.java@ 10334

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

add more unit tests

  • Property svn:eol-style set to native
File size: 2.7 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.assertTrue;
6
7import org.junit.BeforeClass;
8import org.junit.Test;
9import org.openstreetmap.josm.JOSMFixture;
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.coor.LatLon;
12import org.openstreetmap.josm.data.osm.DataSet;
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.data.osm.Way;
15import org.openstreetmap.josm.gui.layer.OsmDataLayer;
16
17/**
18 * Unit tests for class {@link SimplifyWayAction}.
19 */
20public 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}
Note: See TracBrowser for help on using the repository browser.