source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/NodeDataTest.java@ 17275

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

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import static org.junit.jupiter.api.Assertions.assertNull;
5import static org.junit.jupiter.api.Assertions.assertTrue;
6
7import java.io.ByteArrayInputStream;
8import java.io.ByteArrayOutputStream;
9import java.io.IOException;
10import java.io.ObjectInputStream;
11import java.io.ObjectOutputStream;
12
13import org.junit.Assert;
14import org.junit.jupiter.api.Test;
15import org.openstreetmap.josm.data.coor.LatLon;
16
17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
18
19class NodeDataTest {
20
21 @SuppressFBWarnings(value = "OBJECT_DESERIALIZATION")
22 private static NodeData serializeUnserialize(NodeData data) throws IOException, ClassNotFoundException {
23 try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
24 ObjectOutputStream out = new ObjectOutputStream(bytes)) {
25 out.writeObject(data);
26 try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
27 return (NodeData) in.readObject();
28 }
29 }
30 }
31
32 @Test
33 void testSerializationForDragAndDrop() throws Exception {
34 final NodeData data = new NodeData();
35 data.setCoor(new LatLon(31.14, 15.9));
36 data.setId(314);
37 data.setVersion(14);
38 data.setChangesetId(314159);
39 final NodeData readData = serializeUnserialize(data);
40 Assert.assertEquals(data.toString(), readData.toString());
41 }
42
43 /**
44 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/13395">#13395</a>.
45 * @throws Exception if an error occurs
46 */
47 @Test
48 void testTicket13395() throws Exception {
49 Node n = new Node(1925320646, 1);
50 n.setCoor(null);
51 assertNull(n.getCoor());
52 assertTrue(n.isIncomplete());
53
54 NodeData data = n.save();
55 assertNull(data.getCoor());
56 assertTrue(data.isIncomplete());
57
58 NodeData readData = serializeUnserialize(data);
59 assertNull(readData.getCoor());
60 assertTrue(readData.isIncomplete());
61 }
62}
Note: See TracBrowser for help on using the repository browser.