source: josm/trunk/test/unit/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommandTest.java@ 12726

Last change on this file since 12726 was 12726, checked in by Don-vip, 7 years ago

see #13036 - deprecate Command() default constructor, fix unit tests and java warnings

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