1 | package org.openstreetmap.josm.actions;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 | import static org.openstreetmap.josm.testframework.MotherObject.createSegment;
|
---|
7 | import static org.openstreetmap.josm.testframework.MotherObject.createWay;
|
---|
8 |
|
---|
9 | import javax.swing.Action;
|
---|
10 |
|
---|
11 | import org.junit.Before;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
15 | import org.openstreetmap.josm.data.osm.Segment;
|
---|
16 | import org.openstreetmap.josm.data.osm.Way;
|
---|
17 | import org.openstreetmap.josm.testframework.MainMock;
|
---|
18 | import org.openstreetmap.josm.testframework.MotherObject;
|
---|
19 |
|
---|
20 |
|
---|
21 | public class CombineWayActionTest extends MainMock {
|
---|
22 |
|
---|
23 | private Action action = Main.main.menu.combineWay;
|
---|
24 | private Way way1;
|
---|
25 | private Way way2;
|
---|
26 | private Segment segment1;
|
---|
27 | private Segment segment2;
|
---|
28 |
|
---|
29 | @Before public void createTwoWays() {
|
---|
30 | Main.ds = new DataSet();
|
---|
31 | MotherObject.dataSet = Main.ds;
|
---|
32 | segment1 = createSegment();
|
---|
33 | segment2 = createSegment();
|
---|
34 | way1 = createWay(segment1);
|
---|
35 | way2 = createWay(segment2);
|
---|
36 | Main.ds.setSelected(way1, way2);
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Test public void noSelectionBreaks() throws Exception {
|
---|
40 | Main.ds.setSelected();
|
---|
41 | action.actionPerformed(null);
|
---|
42 | assertPopup();
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Test public void oneSelectedWayBreaks() throws Exception {
|
---|
46 | Main.ds.setSelected(way1);
|
---|
47 | action.actionPerformed(null);
|
---|
48 | assertPopup();
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Test public void segmentsAreMergedInNewWay() throws Exception {
|
---|
52 | action.actionPerformed(null);
|
---|
53 | Way w = way1.deleted ? way2 : way1;
|
---|
54 | assertFalse(w.deleted);
|
---|
55 | assertEquals(2, w.segments.size());
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Test public void nonConflictingPropertiesAreMerged() throws Exception {
|
---|
59 | way1.put("foo", "bar");
|
---|
60 | way2.put("baz", "imi");
|
---|
61 |
|
---|
62 | action.actionPerformed(null);
|
---|
63 | Way w = way1.deleted ? way2 : way1;
|
---|
64 |
|
---|
65 | assertEquals(2, w.keys.size());
|
---|
66 | assertEquals("bar", w.get("foo"));
|
---|
67 | assertEquals("imi", w.get("baz"));
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Test public void conflictingPropertiesOpenResolveDialog() throws Exception {
|
---|
71 | way1.put("foo", "bar");
|
---|
72 | way2.put("foo", "baz");
|
---|
73 | way2.put("imi", "ada");
|
---|
74 |
|
---|
75 | action.actionPerformed(null);
|
---|
76 | assertPopup();
|
---|
77 | Way w = way1.deleted ? way2 : way1;
|
---|
78 |
|
---|
79 | assertEquals(2, w.keys.size());
|
---|
80 | assertTrue(w.get("foo").equals("bar") || w.get("foo").equals("bar"));
|
---|
81 | assertEquals("ada", w.get("imi"));
|
---|
82 | }
|
---|
83 | }
|
---|