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.MergeDecisionType;
|
---|
20 |
|
---|
21 | public class PropertiesMergeModelTest {
|
---|
22 |
|
---|
23 | static public class ObserverTest implements Observer {
|
---|
24 | public int numInvocations;
|
---|
25 |
|
---|
26 | public void update(Observable o, Object arg) {
|
---|
27 | numInvocations++;
|
---|
28 | test();
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void test() {
|
---|
32 | }
|
---|
33 |
|
---|
34 | public void assertNumInvocations(int count) {
|
---|
35 | assertEquals(count, numInvocations);
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | PropertiesMergeModel model;
|
---|
40 |
|
---|
41 | @Before
|
---|
42 | public void setUp() {
|
---|
43 | model = new PropertiesMergeModel();
|
---|
44 | Main.proj = new Epsg4326();
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Test
|
---|
48 | public void populate() {
|
---|
49 | Node n1 = new Node(1);
|
---|
50 | Node n2 = new Node(1);
|
---|
51 | model.populate(n1, n2);
|
---|
52 |
|
---|
53 | Way w1 = new Way(1);
|
---|
54 | Way w2 = new Way(1);
|
---|
55 | model.populate(w2, w2);
|
---|
56 |
|
---|
57 | Relation r1 = new Relation(1);
|
---|
58 | Relation r2 = new Relation(1);
|
---|
59 | model.populate(r1, r2);
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Test
|
---|
63 | public void decidingAboutCoords() {
|
---|
64 | Node n1 = new Node(1);
|
---|
65 | Node n2 = new Node(1);
|
---|
66 | model.populate(n1, n2);
|
---|
67 | assertFalse(model.hasCoordConflict());
|
---|
68 |
|
---|
69 | n1.setCoor(new LatLon(1,1));
|
---|
70 | model.populate(n1, n2);
|
---|
71 | assertTrue(model.hasCoordConflict());
|
---|
72 |
|
---|
73 |
|
---|
74 | n1 = new Node(1);
|
---|
75 | n2.setCoor(new LatLon(2,2));
|
---|
76 | model.populate(n1, n2);
|
---|
77 | assertTrue(model.hasCoordConflict());
|
---|
78 |
|
---|
79 | n1.setCoor(new LatLon(1,1));
|
---|
80 | n2.setCoor(new LatLon(2,2));
|
---|
81 | model.populate(n1, n2);
|
---|
82 | assertTrue(model.hasCoordConflict());
|
---|
83 |
|
---|
84 | // decide KEEP_MINE and ensure notification via Observable
|
---|
85 | //
|
---|
86 | ObserverTest observerTest;
|
---|
87 | model.addObserver(
|
---|
88 | observerTest = new ObserverTest() {
|
---|
89 | @Override
|
---|
90 | public void test() {
|
---|
91 | assertTrue(model.isCoordMergeDecision(MergeDecisionType.KEEP_MINE));
|
---|
92 | }
|
---|
93 | }
|
---|
94 | );
|
---|
95 | model.decideCoordsConflict(MergeDecisionType.KEEP_MINE);
|
---|
96 | assertTrue(model.isCoordMergeDecision(MergeDecisionType.KEEP_MINE));
|
---|
97 | observerTest.assertNumInvocations(1);
|
---|
98 |
|
---|
99 | // decide KEEP_THEIR and ensure notification via Observable
|
---|
100 | //
|
---|
101 | model.deleteObserver(observerTest);
|
---|
102 | model.addObserver(
|
---|
103 | observerTest = new ObserverTest() {
|
---|
104 | @Override
|
---|
105 | public void test() {
|
---|
106 | assertTrue(model.isCoordMergeDecision(MergeDecisionType.KEEP_THEIR));
|
---|
107 | }
|
---|
108 | }
|
---|
109 | );
|
---|
110 | model.decideCoordsConflict(MergeDecisionType.KEEP_THEIR);
|
---|
111 | assertTrue(model.isCoordMergeDecision(MergeDecisionType.KEEP_THEIR));
|
---|
112 | observerTest.assertNumInvocations(1);
|
---|
113 | model.deleteObserver(observerTest);
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | }
|
---|