1 package org.opendaylight.yangtools.triemap;
3 import java.io.ByteArrayInputStream;
4 import java.io.ByteArrayOutputStream;
5 import java.io.IOException;
6 import java.io.ObjectInputStream;
7 import java.io.ObjectOutputStream;
9 import junit.framework.Assert;
11 import org.junit.Test;
13 public class TestSerialization {
15 public void testSerialization() throws IOException, ClassNotFoundException {
16 TrieMap<String, String> map = new TrieMap<String, String>();
18 map.put("dude-0", "tom");
19 map.put("dude-1", "john");
20 map.put("dude-3", "ravi");
21 map.put("dude-4", "alex");
23 TrieMap<String, String> expected = map.readOnlySnapshot();
25 final ByteArrayOutputStream bos = new ByteArrayOutputStream();
26 final ObjectOutputStream oos = new ObjectOutputStream(bos);
27 oos.writeObject(expected);
30 final byte[] bytes = bos.toByteArray();
31 final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
32 final ObjectInputStream ois = new ObjectInputStream(bis);
34 @SuppressWarnings("unchecked")
35 final TrieMap<String, String> actual = (TrieMap<String, String>) ois.readObject();
38 Assert.assertEquals(expected, actual);