source: josm/test/unit/org/openstreetmap/josm/actions/CombineWayActionTest.java@ 298

Last change on this file since 298 was 298, checked in by imi, 17 years ago
  • added license description to head of each source file
File size: 2.4 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertTrue;
7import static org.openstreetmap.josm.testframework.MotherObject.createSegment;
8import static org.openstreetmap.josm.testframework.MotherObject.createWay;
9
10import javax.swing.Action;
11
12import org.junit.Before;
13import org.junit.Test;
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.data.osm.DataSet;
16import org.openstreetmap.josm.data.osm.Segment;
17import org.openstreetmap.josm.data.osm.Way;
18import org.openstreetmap.josm.testframework.MainMock;
19import org.openstreetmap.josm.testframework.MotherObject;
20
21
22public class CombineWayActionTest extends MainMock {
23
24 private Action action = Main.main.menu.combineWay;
25 private Way way1;
26 private Way way2;
27 private Segment segment1;
28 private Segment segment2;
29
30 @Before public void createTwoWays() {
31 Main.ds = new DataSet();
32 MotherObject.dataSet = Main.ds;
33 segment1 = createSegment();
34 segment2 = createSegment();
35 way1 = createWay(segment1);
36 way2 = createWay(segment2);
37 Main.ds.setSelected(way1, way2);
38 }
39
40 @Test public void noSelectionBreaks() throws Exception {
41 Main.ds.setSelected();
42 action.actionPerformed(null);
43 assertPopup();
44 }
45
46 @Test public void oneSelectedWayBreaks() throws Exception {
47 Main.ds.setSelected(way1);
48 action.actionPerformed(null);
49 assertPopup();
50 }
51
52 @Test public void segmentsAreMergedInNewWay() throws Exception {
53 action.actionPerformed(null);
54 Way w = way1.deleted ? way2 : way1;
55 assertFalse(w.deleted);
56 assertEquals(2, w.segments.size());
57 }
58
59 @Test public void nonConflictingPropertiesAreMerged() throws Exception {
60 way1.put("foo", "bar");
61 way2.put("baz", "imi");
62
63 action.actionPerformed(null);
64 Way w = way1.deleted ? way2 : way1;
65
66 assertEquals(2, w.keys.size());
67 assertEquals("bar", w.get("foo"));
68 assertEquals("imi", w.get("baz"));
69 }
70
71 @Test public void conflictingPropertiesOpenResolveDialog() throws Exception {
72 way1.put("foo", "bar");
73 way2.put("foo", "baz");
74 way2.put("imi", "ada");
75
76 action.actionPerformed(null);
77 assertPopup();
78 Way w = way1.deleted ? way2 : way1;
79
80 assertEquals(2, w.keys.size());
81 assertTrue(w.get("foo").equals("bar") || w.get("foo").equals("bar"));
82 assertEquals("ada", w.get("imi"));
83 }
84}
Note: See TracBrowser for help on using the repository browser.