Migrate to tech.pantheon.TrieMap
[yangtools.git] / third-party / triemap / src / test / java / org / opendaylight / yangtools / triemap / TestSerialization.java
1 /*
2  * (C) Copyright 2016 Pantheon Technologies, s.r.o. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.opendaylight.yangtools.triemap;
17
18 import java.io.ByteArrayInputStream;
19 import java.io.ByteArrayOutputStream;
20 import java.io.IOException;
21 import java.io.ObjectInputStream;
22 import java.io.ObjectOutputStream;
23 import org.junit.Assert;
24 import org.junit.Test;
25
26 @Deprecated
27 public class TestSerialization {
28     @Test
29     public void testSerialization() throws IOException, ClassNotFoundException {
30         TrieMap<String, String> map = TrieMap.create();
31
32         map.put("dude-0", "tom");
33         map.put("dude-1", "john");
34         map.put("dude-3", "ravi");
35         map.put("dude-4", "alex");
36
37         TrieMap<String, String> expected = map.immutableSnapshot();
38
39         final ByteArrayOutputStream bos = new ByteArrayOutputStream();
40         final ObjectOutputStream oos = new ObjectOutputStream(bos);
41         oos.writeObject(expected);
42         oos.close();
43
44         final byte[] bytes = bos.toByteArray();
45         final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
46         final ObjectInputStream ois = new ObjectInputStream(bis);
47
48         @SuppressWarnings("unchecked")
49         final TrieMap<String, String> actual = (TrieMap<String, String>) ois.readObject();
50         ois.close();
51
52         Assert.assertEquals(expected, actual);
53     }
54 }