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