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

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

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

File size: 4.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command.conflict;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNotNull;
6import static org.junit.jupiter.api.Assertions.assertTrue;
7
8import org.junit.jupiter.api.BeforeEach;
9import org.junit.jupiter.api.Test;
10import org.junit.jupiter.api.extension.RegisterExtension;
11import org.openstreetmap.josm.TestUtils;
12import org.openstreetmap.josm.command.CommandTest.CommandTestData;
13import org.openstreetmap.josm.data.conflict.Conflict;
14import org.openstreetmap.josm.data.coor.LatLon;
15import org.openstreetmap.josm.data.osm.DataSet;
16import org.openstreetmap.josm.data.osm.Node;
17import org.openstreetmap.josm.data.osm.User;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
20import org.openstreetmap.josm.gui.layer.OsmDataLayer;
21import org.openstreetmap.josm.testutils.JOSMTestRules;
22
23import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24import nl.jqno.equalsverifier.EqualsVerifier;
25import nl.jqno.equalsverifier.Warning;
26
27/**
28 * Unit tests of {@link CoordinateConflictResolveCommand} class.
29 */
30class 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}
Note: See TracBrowser for help on using the repository browser.