1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command.conflict;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 | import static org.junit.Assert.assertTrue;
|
---|
7 |
|
---|
8 | import org.junit.After;
|
---|
9 | import org.junit.Before;
|
---|
10 | import org.junit.Rule;
|
---|
11 | import org.junit.Test;
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
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 | public class CoordinateConflictResolveCommandTest {
|
---|
31 |
|
---|
32 | private OsmDataLayer layer;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Setup test.
|
---|
36 | */
|
---|
37 | @Rule
|
---|
38 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
39 | public JOSMTestRules test = new JOSMTestRules().platform();
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Setup test.
|
---|
43 | */
|
---|
44 | @Before
|
---|
45 | public void setUp() {
|
---|
46 | layer = new OsmDataLayer(new DataSet(), null, null);
|
---|
47 | Main.getLayerManager().addLayer(layer);
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Cleanup test resources.
|
---|
52 | */
|
---|
53 | @After
|
---|
54 | public void tearDown() {
|
---|
55 | Main.getLayerManager().removeLayer(layer);
|
---|
56 | }
|
---|
57 |
|
---|
58 | private static Conflict<Node> createConflict() {
|
---|
59 | return new Conflict<>(new Node(LatLon.ZERO), new Node(new LatLon(50, 50)));
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Unit test of {@code CoordinateConflictResolveCommand#executeCommand} and {@code CoordinateConflictResolveCommand#undoCommand} methods.
|
---|
64 | */
|
---|
65 | @Test
|
---|
66 | public void testExecuteKeepMineUndoCommand() {
|
---|
67 | Conflict<Node> conflict = createConflict();
|
---|
68 | CoordinateConflictResolveCommand cmd = new CoordinateConflictResolveCommand(conflict, MergeDecisionType.KEEP_MINE);
|
---|
69 | assertTrue(cmd.executeCommand());
|
---|
70 | assertEquals(LatLon.ZERO, conflict.getMy().getCoor());
|
---|
71 | cmd.undoCommand();
|
---|
72 | assertEquals(LatLon.ZERO, conflict.getMy().getCoor());
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Unit test of {@code CoordinateConflictResolveCommand#executeCommand} and {@code CoordinateConflictResolveCommand#undoCommand} methods.
|
---|
77 | */
|
---|
78 | @Test
|
---|
79 | public void testExecuteKeepTheirUndoCommand() {
|
---|
80 | Conflict<Node> conflict = createConflict();
|
---|
81 | CoordinateConflictResolveCommand cmd = new CoordinateConflictResolveCommand(conflict, MergeDecisionType.KEEP_THEIR);
|
---|
82 | assertTrue(cmd.executeCommand());
|
---|
83 | assertEquals(conflict.getTheir().getCoor(), conflict.getMy().getCoor());
|
---|
84 | cmd.undoCommand();
|
---|
85 | //assertEquals(LatLon.ZERO, conflict.getMy().getCoor()); // FIXME it does not work
|
---|
86 | }
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Unit test of {@code CoordinateConflictResolveCommand#getDescriptionIcon} method.
|
---|
90 | */
|
---|
91 | @Test
|
---|
92 | public void testGetDescriptionIcon() {
|
---|
93 | Conflict<Node> conflict = createConflict();
|
---|
94 | assertNotNull(new CoordinateConflictResolveCommand(conflict, null).getDescriptionIcon());
|
---|
95 | }
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Unit test of methods {@link CoordinateConflictResolveCommand#equals} and {@link CoordinateConflictResolveCommand#hashCode}.
|
---|
99 | */
|
---|
100 | @Test
|
---|
101 | public void testEqualsContract() {
|
---|
102 | EqualsVerifier.forClass(CoordinateConflictResolveCommand.class).usingGetClass()
|
---|
103 | .withPrefabValues(Conflict.class,
|
---|
104 | new Conflict<>(new Node(), new Node()), new Conflict<>(new Way(), new Way()))
|
---|
105 | .withPrefabValues(DataSet.class,
|
---|
106 | new DataSet(), new DataSet())
|
---|
107 | .withPrefabValues(User.class,
|
---|
108 | User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar"))
|
---|
109 | .withPrefabValues(OsmDataLayer.class,
|
---|
110 | new OsmDataLayer(new DataSet(), "1", null), new OsmDataLayer(new DataSet(), "2", null))
|
---|
111 | .suppress(Warning.NONFINAL_FIELDS)
|
---|
112 | .verify();
|
---|
113 | }
|
---|
114 | }
|
---|