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