1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
7 |
|
---|
8 | import java.util.ArrayList;
|
---|
9 | import java.util.Collections;
|
---|
10 |
|
---|
11 | import org.junit.jupiter.api.BeforeEach;
|
---|
12 | import org.junit.jupiter.api.Test;
|
---|
13 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
14 | import org.openstreetmap.josm.TestUtils;
|
---|
15 | import org.openstreetmap.josm.command.CommandTest.CommandTestDataWithRelation;
|
---|
16 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
17 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
18 | import org.openstreetmap.josm.data.osm.User;
|
---|
19 | import org.openstreetmap.josm.data.osm.Way;
|
---|
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 RemoveNodesCommand} class.
|
---|
29 | */
|
---|
30 | class RemoveNodesCommandTest {
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * We need prefs for nodes.
|
---|
34 | */
|
---|
35 | @RegisterExtension
|
---|
36 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
37 | public JOSMTestRules test = new JOSMTestRules().preferences();
|
---|
38 | private CommandTestDataWithRelation testData;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Set up the test data.
|
---|
42 | */
|
---|
43 | @BeforeEach
|
---|
44 | public void createTestData() {
|
---|
45 | testData = new CommandTestDataWithRelation();
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Test {@link RemoveNodesCommand#executeCommand()}
|
---|
50 | */
|
---|
51 | @Test
|
---|
52 | void testExecute() {
|
---|
53 | RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
|
---|
54 | Collections.singleton(testData.existingNode));
|
---|
55 |
|
---|
56 | command.executeCommand();
|
---|
57 |
|
---|
58 | assertFalse(testData.existingWay.containsNode(testData.existingNode));
|
---|
59 | assertTrue(testData.existingWay.containsNode(testData.existingNode2));
|
---|
60 | assertTrue(testData.existingWay.isModified());
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Test {@link RemoveNodesCommand#undoCommand()}
|
---|
65 | */
|
---|
66 | @Test
|
---|
67 | void testUndo() {
|
---|
68 | RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
|
---|
69 | Collections.singleton(testData.existingNode));
|
---|
70 |
|
---|
71 | command.executeCommand();
|
---|
72 |
|
---|
73 | command.undoCommand();
|
---|
74 | assertTrue(testData.existingWay.containsNode(testData.existingNode));
|
---|
75 | assertTrue(testData.existingWay.containsNode(testData.existingNode2));
|
---|
76 | assertFalse(testData.existingWay.isModified());
|
---|
77 |
|
---|
78 | command.executeCommand();
|
---|
79 |
|
---|
80 | assertFalse(testData.existingWay.containsNode(testData.existingNode));
|
---|
81 | assertTrue(testData.existingWay.containsNode(testData.existingNode2));
|
---|
82 | assertTrue(testData.existingWay.isModified());
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Tests {@link RemoveNodesCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)}
|
---|
87 | */
|
---|
88 | @Test
|
---|
89 | void testFillModifiedData() {
|
---|
90 | ArrayList<OsmPrimitive> modified = new ArrayList<>();
|
---|
91 | ArrayList<OsmPrimitive> deleted = new ArrayList<>();
|
---|
92 | ArrayList<OsmPrimitive> added = new ArrayList<>();
|
---|
93 | RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
|
---|
94 | Collections.singleton(testData.existingNode));
|
---|
95 | command.fillModifiedData(modified, deleted, added);
|
---|
96 | assertArrayEquals(new Object[] {testData.existingWay }, modified.toArray());
|
---|
97 | assertArrayEquals(new Object[] {}, deleted.toArray());
|
---|
98 | assertArrayEquals(new Object[] {}, added.toArray());
|
---|
99 | }
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Tests {@link RemoveNodesCommand#getParticipatingPrimitives()}
|
---|
103 | */
|
---|
104 | @Test
|
---|
105 | void testGetParticipatingPrimitives() {
|
---|
106 | RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
|
---|
107 | Collections.singleton(testData.existingNode));
|
---|
108 | command.executeCommand();
|
---|
109 | assertArrayEquals(new Object[] {testData.existingWay }, command.getParticipatingPrimitives().toArray());
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Test {@link RemoveNodesCommand#getDescriptionText()}
|
---|
114 | */
|
---|
115 | @Test
|
---|
116 | void testDescription() {
|
---|
117 | assertTrue(new RemoveNodesCommand(testData.existingWay, Collections.singleton(testData.existingNode))
|
---|
118 | .getDescriptionText().matches("Removed nodes from .*"));
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Unit test of methods {@link RemoveNodesCommand#equals} and {@link RemoveNodesCommand#hashCode}.
|
---|
123 | */
|
---|
124 | @Test
|
---|
125 | void testEqualsContract() {
|
---|
126 | TestUtils.assumeWorkingEqualsVerifier();
|
---|
127 | EqualsVerifier.forClass(RemoveNodesCommand.class).usingGetClass()
|
---|
128 | .withPrefabValues(Way.class,
|
---|
129 | new Way(1), new Way(2))
|
---|
130 | .withPrefabValues(DataSet.class,
|
---|
131 | new DataSet(), new DataSet())
|
---|
132 | .withPrefabValues(User.class,
|
---|
133 | User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar"))
|
---|
134 | .withPrefabValues(OsmDataLayer.class,
|
---|
135 | new OsmDataLayer(new DataSet(), "1", null), new OsmDataLayer(new DataSet(), "2", null))
|
---|
136 | .suppress(Warning.NONFINAL_FIELDS)
|
---|
137 | .verify();
|
---|
138 | }
|
---|
139 | }
|
---|