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

Last change on this file since 19078 was 19078, checked in by taylor.smock, 4 months ago

Fix #4142: Track fully downloaded objects (patch by stoecker, GerdP, and myself)

The serialization move from PrimitiveData to AbstractPrimitive should be
reverted prior to 24.05 (see #23677).

The serialization move was required since we want to ensure that all downstream
users of AbstractPrimitive were not using the flags field, which was done by
making the field private instead of protected. They may still be using that
field (via updateFlags) which would not be caught by compile-time or runtime
errors.

Additionally, a good chunk of common functionality was moved up from
OsmPrimitive, even though much of it wasn't useful for PrimitiveData.

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.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 node.setReferrersDownloaded(true);
93 layer.data.addPrimitive(node);
94 return node;
95 }
96
97 /**
98 * Create and add a new test way.
99 * @param id the id
100 * @param nodes The nodes
101 * @return The way.
102 */
103 public Way createWay(int id, Node... nodes) {
104 Way way = new Way();
105 way.setOsmId(id, 1);
106 way.setNodes(Arrays.asList(nodes));
107 way.put("existing", "existing");
108 way.setReferrersDownloaded(true);
109 layer.data.addPrimitive(way);
110 return way;
111 }
112
113 /**
114 * Create and add a new test relation.
115 * @param id the id
116 * @param members The members
117 * @return The relation.
118 */
119 public Relation createRelation(int id, RelationMember... members) {
120 Relation relation = new Relation(id, 1);
121 for (RelationMember member : members) {
122 relation.addMember(member);
123 }
124 relation.put("existing", "existing");
125 relation.setReferrersDownloaded(true);
126 layer.data.addPrimitive(relation);
127 return relation;
128 }
129 }
130
131 /**
132 * A change test data consisting of two nodes, a way and a relation.
133 * @author Michael Zangl
134 */
135 public static class CommandTestDataWithRelation extends CommandTestData {
136 /**
137 * A test relation
138 */
139 public final Relation existingRelation;
140
141 /**
142 * Creates the new test data and adds {@link #layer} to the layer manager.
143 */
144 public CommandTestDataWithRelation() {
145 existingRelation = createRelation(20, new RelationMember("node", existingNode), new RelationMember("way", existingWay));
146 }
147 }
148}
Note: See TracBrowser for help on using the repository browser.