source: josm/trunk/test/unit/org/openstreetmap/josm/command/RemoveNodesCommandTest.java@ 13079

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

see #15560 - EqualsVerifier does not work with newer Java versions -> disable tests automatically in this case
Workaround to https://github.com/jqno/equalsverifier/issues/177 / https://github.com/raphw/byte-buddy/issues/370
Inspired by https://issues.apache.org/jira/browse/SOLR-11606

File size: 5.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.junit.Assert.assertArrayEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertTrue;
7
8import java.util.ArrayList;
9import java.util.Collections;
10
11import org.junit.Before;
12import org.junit.Rule;
13import org.junit.Test;
14import org.openstreetmap.josm.TestUtils;
15import org.openstreetmap.josm.command.CommandTest.CommandTestDataWithRelation;
16import org.openstreetmap.josm.data.osm.DataSet;
17import org.openstreetmap.josm.data.osm.OsmPrimitive;
18import org.openstreetmap.josm.data.osm.User;
19import org.openstreetmap.josm.data.osm.Way;
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 RemoveNodesCommand} class.
29 */
30public class RemoveNodesCommandTest {
31
32 /**
33 * We need prefs for nodes.
34 */
35 @Rule
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 @Before
44 public void createTestData() {
45 testData = new CommandTestDataWithRelation();
46 }
47
48 /**
49 * Test {@link RemoveNodesCommand#executeCommand()}
50 */
51 @Test
52 public void testExecute() {
53 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
54 Collections.singletonList(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 public void testUndo() {
68 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
69 Collections.singletonList(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 public 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.singletonList(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 public void testGetParticipatingPrimitives() {
106 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
107 Collections.singletonList(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 public void testDescription() {
117 assertTrue(new RemoveNodesCommand(testData.existingWay, Collections.singletonList(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 public 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}
Note: See TracBrowser for help on using the repository browser.