source: josm/trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java@ 19050

Last change on this file since 19050 was 19050, checked in by taylor.smock, 6 weeks ago

Revert most var changes from r19048, fix most new compile warnings and checkstyle issues

Also, document why various ErrorProne checks were originally disabled and fix
generic SonarLint issues.

File size: 4.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import java.util.Arrays;
5
6import org.junit.jupiter.api.Test;
7import org.openstreetmap.josm.TestUtils;
8import org.openstreetmap.josm.data.coor.LatLon;
9import org.openstreetmap.josm.data.osm.DataSet;
10import org.openstreetmap.josm.data.osm.Node;
11import org.openstreetmap.josm.data.osm.Relation;
12import org.openstreetmap.josm.data.osm.RelationMember;
13import org.openstreetmap.josm.data.osm.User;
14import org.openstreetmap.josm.data.osm.Way;
15import org.openstreetmap.josm.gui.MainApplication;
16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
17import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
18import org.openstreetmap.josm.testutils.annotations.I18n;
19
20import nl.jqno.equalsverifier.EqualsVerifier;
21import nl.jqno.equalsverifier.Warning;
22
23/**
24 * Unit tests of {@link Command} class.
25 */
26@I18n
27// We need prefs for nodes / data sets.
28@BasicPreferences
29public class CommandTest {
30 /**
31 * Unit test of methods {@link Command#equals} and {@link Command#hashCode}.
32 */
33 @Test
34 void testEqualsContract() {
35 TestUtils.assumeWorkingEqualsVerifier();
36 EqualsVerifier.forClass(Command.class).usingGetClass()
37 .withPrefabValues(DataSet.class,
38 new DataSet(), new DataSet())
39 .withPrefabValues(User.class,
40 User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar"))
41 .withPrefabValues(OsmDataLayer.class,
42 new OsmDataLayer(new DataSet(), "1", null), new OsmDataLayer(new DataSet(), "2", null))
43 .suppress(Warning.NONFINAL_FIELDS)
44 .verify();
45 }
46
47 /**
48 * A change test data consisting of two nodes and a way.
49 * @author Michael Zangl
50 */
51 public static class CommandTestData {
52 /**
53 * A test layer
54 */
55 public final OsmDataLayer layer;
56 /**
57 * A test node
58 */
59 public final Node existingNode;
60 /**
61 * A second test node
62 */
63 public final Node existingNode2;
64 /**
65 * A test way
66 */
67 public final Way existingWay;
68
69 /**
70 * Creates the new test data and adds {@link #layer} to the layer manager.
71 */
72 public CommandTestData() {
73 layer = new OsmDataLayer(new DataSet(), "layer", null);
74 MainApplication.getLayerManager().addLayer(layer);
75
76 existingNode = createNode(5);
77 existingNode2 = createNode(6);
78
79 existingWay = createWay(10, existingNode, existingNode2);
80 }
81
82 /**
83 * Create and add a new test node.
84 * @param id the id
85 * @return The node.
86 */
87 public Node createNode(long id) {
88 Node node = new Node();
89 node.setOsmId(id, 1);
90 node.setCoor(LatLon.ZERO);
91 node.put("existing", "existing");
92 layer.data.addPrimitive(node);
93 return node;
94 }
95
96 /**
97 * Create and add a new test way.
98 * @param id the id
99 * @param nodes The nodes
100 * @return The way.
101 */
102 public Way createWay(int id, Node... nodes) {
103 Way way = new Way();
104 way.setOsmId(id, 1);
105 way.setNodes(Arrays.asList(nodes));
106 way.put("existing", "existing");
107 layer.data.addPrimitive(way);
108 return way;
109 }
110
111 /**
112 * Create and add a new test relation.
113 * @param id the id
114 * @param members The members
115 * @return The relation.
116 */
117 public Relation createRelation(int id, RelationMember... members) {
118 Relation relation = new Relation(id, 1);
119 for (RelationMember member : members) {
120 relation.addMember(member);
121 }
122 relation.put("existing", "existing");
123 layer.data.addPrimitive(relation);
124 return relation;
125 }
126 }
127
128 /**
129 * A change test data consisting of two nodes, a way and a relation.
130 * @author Michael Zangl
131 */
132 public static class CommandTestDataWithRelation extends CommandTestData {
133 /**
134 * A test relation
135 */
136 public final Relation existingRelation;
137
138 /**
139 * Creates the new test data and adds {@link #layer} to the layer manager.
140 */
141 public CommandTestDataWithRelation() {
142 existingRelation = createRelation(20, new RelationMember("node", existingNode), new RelationMember("way", existingWay));
143 }
144 }
145}
Note: See TracBrowser for help on using the repository browser.