1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertNull;
|
---|
5 | import static org.junit.Assert.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.Test;
|
---|
15 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
16 |
|
---|
17 | public class NodeDataTest {
|
---|
18 |
|
---|
19 | private static NodeData serializeUnserialize(NodeData data) throws IOException, ClassNotFoundException {
|
---|
20 | try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
---|
21 | ObjectOutputStream out = new ObjectOutputStream(bytes)) {
|
---|
22 | out.writeObject(data);
|
---|
23 | try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
|
---|
24 | return (NodeData) in.readObject();
|
---|
25 | }
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Test
|
---|
30 | public void testSerializationForDragAndDrop() throws Exception {
|
---|
31 | final NodeData data = new NodeData();
|
---|
32 | data.setCoor(new LatLon(31.14, 15.9));
|
---|
33 | data.setId(314);
|
---|
34 | data.setVersion(14);
|
---|
35 | data.setChangesetId(314159);
|
---|
36 | final NodeData readData = serializeUnserialize(data);
|
---|
37 | Assert.assertEquals(data.toString(), readData.toString());
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/13395">#13395</a>.
|
---|
42 | * @throws Exception if an error occurs
|
---|
43 | */
|
---|
44 | @Test
|
---|
45 | public void testTicket13395() throws Exception {
|
---|
46 | Node n = new Node(1925320646, 1);
|
---|
47 | n.setCoor(null);
|
---|
48 | assertNull(n.getCoor());
|
---|
49 | assertTrue(n.isIncomplete());
|
---|
50 |
|
---|
51 | NodeData data = n.save();
|
---|
52 | assertNull(data.getCoor());
|
---|
53 | assertTrue(data.isIncomplete());
|
---|
54 |
|
---|
55 | NodeData readData = serializeUnserialize(data);
|
---|
56 | assertNull(readData.getCoor());
|
---|
57 | assertTrue(readData.isIncomplete());
|
---|
58 | }
|
---|
59 | }
|
---|