1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command.conflict;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
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.osm.DataSet;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.data.osm.User;
|
---|
17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
18 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
19 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
20 |
|
---|
21 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
22 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
23 | import nl.jqno.equalsverifier.Warning;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Unit tests of {@link ConflictAddCommand} class.
|
---|
27 | */
|
---|
28 | class ConflictAddCommandTest {
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Setup test.
|
---|
32 | */
|
---|
33 | @RegisterExtension
|
---|
34 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
35 | public JOSMTestRules test = new JOSMTestRules();
|
---|
36 | private CommandTestData testData;
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Setup test.
|
---|
40 | */
|
---|
41 | @BeforeEach
|
---|
42 | public void setUp() {
|
---|
43 | testData = new CommandTestData();
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Unit test of {@code ConflictAddCommand#executeCommand} and {@code ConflictAddCommand#undoCommand} methods.
|
---|
48 | */
|
---|
49 | @Test
|
---|
50 | void testExecuteUndoCommand() {
|
---|
51 | DataSet ds = testData.layer.getDataSet();
|
---|
52 | Conflict<Node> conflict = new Conflict<>(testData.existingNode, testData.existingNode2);
|
---|
53 | ConflictAddCommand cmd = new ConflictAddCommand(ds, conflict);
|
---|
54 | assertTrue(cmd.executeCommand());
|
---|
55 | assertFalse(ds.getConflicts().isEmpty());
|
---|
56 | assertTrue(ds.getConflicts().hasConflict(conflict));
|
---|
57 | cmd.undoCommand();
|
---|
58 | assertFalse(ds.getConflicts().hasConflict(conflict));
|
---|
59 | assertTrue(ds.getConflicts().isEmpty());
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Unit test of {@code ConflictAddCommand#getDescriptionIcon} method.
|
---|
64 | */
|
---|
65 | @Test
|
---|
66 | void testGetDescriptionIcon() {
|
---|
67 | Conflict<Node> conflict = new Conflict<>(testData.existingNode, testData.existingNode2);
|
---|
68 | assertNotNull(new ConflictAddCommand(testData.layer.getDataSet(), conflict).getDescriptionIcon());
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Unit test of methods {@link ConflictAddCommand#equals} and {@link ConflictAddCommand#hashCode}.
|
---|
73 | */
|
---|
74 | @Test
|
---|
75 | void testEqualsContract() {
|
---|
76 | TestUtils.assumeWorkingEqualsVerifier();
|
---|
77 | EqualsVerifier.forClass(ConflictAddCommand.class).usingGetClass()
|
---|
78 | .withPrefabValues(DataSet.class,
|
---|
79 | new DataSet(), new DataSet())
|
---|
80 | .withPrefabValues(User.class,
|
---|
81 | User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar"))
|
---|
82 | .withPrefabValues(Conflict.class,
|
---|
83 | new Conflict<>(new Node(), new Node()), new Conflict<>(new Way(), new Way()))
|
---|
84 | .withPrefabValues(OsmDataLayer.class,
|
---|
85 | new OsmDataLayer(new DataSet(), "1", null), new OsmDataLayer(new DataSet(), "2", null))
|
---|
86 | .suppress(Warning.NONFINAL_FIELDS)
|
---|
87 | .verify();
|
---|
88 | }
|
---|
89 | }
|
---|