d39a4829359610da62d36260bac36447c1b095ff
[yangtools.git] / third-party / triemap / src / test / java / org / opendaylight / yangtools / triemap / TestSerialization.java
1 package org.opendaylight.yangtools.triemap;
2
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;
8 import org.junit.Assert;
9 import org.junit.Test;
10
11 public class TestSerialization {
12     @Test
13     public void testSerialization() throws IOException, ClassNotFoundException {
14         TrieMap<String, String> map = new TrieMap<>();
15
16         map.put("dude-0", "tom");
17         map.put("dude-1", "john");
18         map.put("dude-3", "ravi");
19         map.put("dude-4", "alex");
20
21         TrieMap<String, String> expected = map.readOnlySnapshot();
22
23         final ByteArrayOutputStream bos = new ByteArrayOutputStream();
24         final ObjectOutputStream oos = new ObjectOutputStream(bos);
25         oos.writeObject(expected);
26         oos.close();
27
28         final byte[] bytes = bos.toByteArray();
29         final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
30         final ObjectInputStream ois = new ObjectInputStream(bis);
31
32         @SuppressWarnings("unchecked")
33         final TrieMap<String, String> actual = (TrieMap<String, String>) ois.readObject();
34         ois.close();
35
36         Assert.assertEquals(expected, actual);
37     }
38 }