1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertTrue;
|
---|
7 | import static org.openstreetmap.josm.testframework.MotherObject.createSegment;
|
---|
8 | import static org.openstreetmap.josm.testframework.MotherObject.createWay;
|
---|
9 |
|
---|
10 | import javax.swing.Action;
|
---|
11 |
|
---|
12 | import org.junit.Before;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.Main;
|
---|
15 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
16 | import org.openstreetmap.josm.data.osm.Segment;
|
---|
17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
18 | import org.openstreetmap.josm.testframework.MainMock;
|
---|
19 | import org.openstreetmap.josm.testframework.MotherObject;
|
---|
20 |
|
---|
21 |
|
---|
22 | public 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 | }
|
---|