1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.conflict.pair;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
---|
6 |
|
---|
7 | import java.util.NoSuchElementException;
|
---|
8 |
|
---|
9 | import org.junit.jupiter.api.Test;
|
---|
10 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
11 | import org.openstreetmap.josm.command.SequenceCommand;
|
---|
12 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
13 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
14 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
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.testutils.JOSMTestRules;
|
---|
19 |
|
---|
20 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Unit tests of {@link ConflictResolver} class.
|
---|
24 | */
|
---|
25 | class ConflictResolverTest {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Setup test.
|
---|
29 | */
|
---|
30 | @RegisterExtension
|
---|
31 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
32 | public JOSMTestRules test = new JOSMTestRules().preferences();
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Unit test of {@link ConflictResolver#buildResolveCommand} - empty case.
|
---|
36 | */
|
---|
37 | @Test
|
---|
38 | void testBuildResolveCommandEmpty() {
|
---|
39 | assertThrows(NoSuchElementException.class, () -> new ConflictResolver().buildResolveCommand());
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Unit test of {@link ConflictResolver#buildResolveCommand} - node case.
|
---|
44 | */
|
---|
45 | @Test
|
---|
46 | void testBuildResolveCommandNode() {
|
---|
47 | ConflictResolver resolver = new ConflictResolver();
|
---|
48 | Node n1 = new Node(LatLon.SOUTH_POLE);
|
---|
49 | n1.put("source", "my");
|
---|
50 | Node n2 = new Node(LatLon.NORTH_POLE);
|
---|
51 | n2.put("source", "theirs");
|
---|
52 | new DataSet(n1, n2);
|
---|
53 | resolver.populate(new Conflict<>(n1, n2));
|
---|
54 | resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
|
---|
55 | assertFalse(((SequenceCommand) resolver.buildResolveCommand()).getChildren().isEmpty());
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Unit test of {@link ConflictResolver#buildResolveCommand} - way case.
|
---|
60 | */
|
---|
61 | @Test
|
---|
62 | void testBuildResolveCommandWay() {
|
---|
63 | ConflictResolver resolver = new ConflictResolver();
|
---|
64 | Way w1 = new Way();
|
---|
65 | w1.put("source", "my");
|
---|
66 | Way w2 = new Way();
|
---|
67 | w2.put("source", "theirs");
|
---|
68 | new DataSet(w1, w2);
|
---|
69 | resolver.populate(new Conflict<>(w1, w2));
|
---|
70 | resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
|
---|
71 | assertFalse(((SequenceCommand) resolver.buildResolveCommand()).getChildren().isEmpty());
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Unit test of {@link ConflictResolver#buildResolveCommand} - relation case.
|
---|
76 | */
|
---|
77 | @Test
|
---|
78 | void testBuildResolveCommandRelation() {
|
---|
79 | ConflictResolver resolver = new ConflictResolver();
|
---|
80 | Relation r1 = new Relation();
|
---|
81 | r1.put("source", "my");
|
---|
82 | Relation r2 = new Relation();
|
---|
83 | r2.put("source", "theirs");
|
---|
84 | new DataSet(r1, r2);
|
---|
85 | resolver.populate(new Conflict<>(r1, r2));
|
---|
86 | resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
|
---|
87 | assertFalse(((SequenceCommand) resolver.buildResolveCommand()).getChildren().isEmpty());
|
---|
88 | }
|
---|
89 | }
|
---|