1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
6 |
|
---|
7 | import java.io.ByteArrayInputStream;
|
---|
8 | import java.io.ByteArrayOutputStream;
|
---|
9 | import java.io.IOException;
|
---|
10 | import java.io.ObjectInputStream;
|
---|
11 | import java.io.ObjectOutputStream;
|
---|
12 |
|
---|
13 | import org.junit.Assert;
|
---|
14 | import org.junit.jupiter.api.Test;
|
---|
15 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
16 |
|
---|
17 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
18 |
|
---|
19 | class 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 | }
|
---|