1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command.conflict;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
7 |
|
---|
8 | import org.junit.jupiter.api.BeforeEach;
|
---|
9 | import org.junit.jupiter.api.Test;
|
---|
10 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
11 | import org.openstreetmap.josm.TestUtils;
|
---|
12 | import org.openstreetmap.josm.command.CommandTest.CommandTestData;
|
---|
13 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
14 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
15 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
16 | import org.openstreetmap.josm.data.osm.Node;
|
---|
17 | import org.openstreetmap.josm.data.osm.User;
|
---|
18 | import org.openstreetmap.josm.data.osm.Way;
|
---|
19 | import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
|
---|
20 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
21 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
22 |
|
---|
23 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
24 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
25 | import nl.jqno.equalsverifier.Warning;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Unit tests of {@link CoordinateConflictResolveCommand} class.
|
---|
29 | */
|
---|
30 | class CoordinateConflictResolveCommandTest {
|
---|
31 |
|
---|
32 | private CommandTestData testData;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Setup test.
|
---|
36 | */
|
---|
37 | @RegisterExtension
|
---|
38 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
39 | public JOSMTestRules test = new JOSMTestRules();
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Setup test.
|
---|
43 | */
|
---|
44 | @BeforeEach
|
---|
45 | public void setUp() {
|
---|
46 | testData = new CommandTestData();
|
---|
47 | }
|
---|
48 |
|
---|
49 | private Conflict<Node> createConflict() {
|
---|
50 | return new Conflict<>(testData.existingNode, testData.existingNode2);
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Unit test of {@code CoordinateConflictResolveCommand#executeCommand} and {@code CoordinateConflictResolveCommand#undoCommand} methods.
|
---|
55 | */
|
---|
56 | @Test
|
---|
57 | void testExecuteKeepMineUndoCommand() {
|
---|
58 | Conflict<Node> conflict = createConflict();
|
---|
59 | CoordinateConflictResolveCommand cmd = new CoordinateConflictResolveCommand(conflict, MergeDecisionType.KEEP_MINE);
|
---|
60 | assertTrue(cmd.executeCommand());
|
---|
61 | assertEquals(LatLon.ZERO, conflict.getMy().getCoor());
|
---|
62 | cmd.undoCommand();
|
---|
63 | assertEquals(LatLon.ZERO, conflict.getMy().getCoor());
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Unit test of {@code CoordinateConflictResolveCommand#executeCommand} and {@code CoordinateConflictResolveCommand#undoCommand} methods.
|
---|
68 | */
|
---|
69 | @Test
|
---|
70 | void testExecuteKeepTheirUndoCommand() {
|
---|
71 | Conflict<Node> conflict = createConflict();
|
---|
72 | CoordinateConflictResolveCommand cmd = new CoordinateConflictResolveCommand(conflict, MergeDecisionType.KEEP_THEIR);
|
---|
73 | assertTrue(cmd.executeCommand());
|
---|
74 | assertEquals(conflict.getTheir().getCoor(), conflict.getMy().getCoor());
|
---|
75 | cmd.undoCommand();
|
---|
76 | //assertEquals(LatLon.ZERO, conflict.getMy().getCoor()); // FIXME it does not work
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Unit test of {@code CoordinateConflictResolveCommand#getDescriptionIcon} method.
|
---|
81 | */
|
---|
82 | @Test
|
---|
83 | void testGetDescriptionIcon() {
|
---|
84 | Conflict<Node> conflict = createConflict();
|
---|
85 | assertNotNull(new CoordinateConflictResolveCommand(conflict, null).getDescriptionIcon());
|
---|
86 | }
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Unit test of methods {@link CoordinateConflictResolveCommand#equals} and {@link CoordinateConflictResolveCommand#hashCode}.
|
---|
90 | */
|
---|
91 | @Test
|
---|
92 | void testEqualsContract() {
|
---|
93 | TestUtils.assumeWorkingEqualsVerifier();
|
---|
94 | EqualsVerifier.forClass(CoordinateConflictResolveCommand.class).usingGetClass()
|
---|
95 | .withPrefabValues(Conflict.class,
|
---|
96 | new Conflict<>(new Node(), new Node()), new Conflict<>(new Way(), new Way()))
|
---|
97 | .withPrefabValues(DataSet.class,
|
---|
98 | new DataSet(), new DataSet())
|
---|
99 | .withPrefabValues(User.class,
|
---|
100 | User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar"))
|
---|
101 | .withPrefabValues(OsmDataLayer.class,
|
---|
102 | new OsmDataLayer(new DataSet(), "1", null), new OsmDataLayer(new DataSet(), "2", null))
|
---|
103 | .suppress(Warning.NONFINAL_FIELDS)
|
---|
104 | .verify();
|
---|
105 | }
|
---|
106 | }
|
---|