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

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