1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.conflict.properties;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 | import static org.junit.Assert.*;
|
---|
7 |
|
---|
8 | import java.util.Observable;
|
---|
9 | import java.util.Observer;
|
---|
10 |
|
---|
11 | import org.junit.Before;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
18 | import org.openstreetmap.josm.data.projection.Epsg4326;
|
---|
19 | import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
|
---|
20 | import org.openstreetmap.josm.gui.conflict.pair.properties.PropertiesMergeModel;
|
---|
21 |
|
---|
22 | public class PropertiesMergeModelTest {
|
---|
23 |
|
---|
24 | static public class ObserverTest implements Observer {
|
---|
25 | public int numInvocations;
|
---|
26 |
|
---|
27 | public void update(Observable o, Object arg) {
|
---|
28 | numInvocations++;
|
---|
29 | test();
|
---|
30 | }
|
---|
31 |
|
---|
32 | public void test() {
|
---|
33 | }
|
---|
34 |
|
---|
35 | public void assertNumInvocations(int count) {
|
---|
36 | assertEquals(count, numInvocations);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | PropertiesMergeModel model;
|
---|
41 |
|
---|
42 | @Before
|
---|
43 | public void setUp() {
|
---|
44 | model = new PropertiesMergeModel();
|
---|
45 | Main.proj = new Epsg4326();
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Test
|
---|
49 | public void populate() {
|
---|
50 | Node n1 = new Node(1);
|
---|
51 | Node n2 = new Node(1);
|
---|
52 | model.populate(n1, n2);
|
---|
53 |
|
---|
54 | Way w1 = new Way(1);
|
---|
55 | Way w2 = new Way(1);
|
---|
56 | model.populate(w2, w2);
|
---|
57 |
|
---|
58 | Relation r1 = new Relation(1);
|
---|
59 | Relation r2 = new Relation(1);
|
---|
60 | model.populate(r1, r2);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Test
|
---|
64 | public void decidingAboutCoords() {
|
---|
65 | Node n1 = new Node(1);
|
---|
66 | Node n2 = new Node(1);
|
---|
67 | model.populate(n1, n2);
|
---|
68 | assertFalse(model.hasCoordConflict());
|
---|
69 |
|
---|
70 | n1.setCoor(new LatLon(1,1));
|
---|
71 | model.populate(n1, n2);
|
---|
72 | assertTrue(model.hasCoordConflict());
|
---|
73 |
|
---|
74 |
|
---|
75 | n1 = new Node(1);
|
---|
76 | n2.setCoor(new LatLon(2,2));
|
---|
77 | model.populate(n1, n2);
|
---|
78 | assertTrue(model.hasCoordConflict());
|
---|
79 |
|
---|
80 | n1.setCoor(new LatLon(1,1));
|
---|
81 | n2.setCoor(new LatLon(2,2));
|
---|
82 | model.populate(n1, n2);
|
---|
83 | assertTrue(model.hasCoordConflict());
|
---|
84 |
|
---|
85 | // decide KEEP_MINE and ensure notification via Observable
|
---|
86 | //
|
---|
87 | ObserverTest observerTest;
|
---|
88 | model.addObserver(
|
---|
89 | observerTest = new ObserverTest() {
|
---|
90 | @Override
|
---|
91 | public void test() {
|
---|
92 | assertTrue(model.isCoordMergeDecision(MergeDecisionType.KEEP_MINE));
|
---|
93 | }
|
---|
94 | }
|
---|
95 | );
|
---|
96 | model.decideCoordsConflict(MergeDecisionType.KEEP_MINE);
|
---|
97 | assertTrue(model.isCoordMergeDecision(MergeDecisionType.KEEP_MINE));
|
---|
98 | observerTest.assertNumInvocations(1);
|
---|
99 |
|
---|
100 | // decide KEEP_THEIR and ensure notification via Observable
|
---|
101 | //
|
---|
102 | model.deleteObserver(observerTest);
|
---|
103 | model.addObserver(
|
---|
104 | observerTest = new ObserverTest() {
|
---|
105 | @Override
|
---|
106 | public void test() {
|
---|
107 | assertTrue(model.isCoordMergeDecision(MergeDecisionType.KEEP_THEIR));
|
---|
108 | }
|
---|
109 | }
|
---|
110 | );
|
---|
111 | model.decideCoordsConflict(MergeDecisionType.KEEP_THEIR);
|
---|
112 | assertTrue(model.isCoordMergeDecision(MergeDecisionType.KEEP_THEIR));
|
---|
113 | observerTest.assertNumInvocations(1);
|
---|
114 | model.deleteObserver(observerTest);
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | }
|
---|