2 * (C) Copyright 2016 Pantheon Technologies, s.r.o. and others.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.opendaylight.yangtools.triemap;
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;
27 public class TestSerialization {
29 public void testSerialization() throws IOException, ClassNotFoundException {
30 TrieMap<String, String> map = TrieMap.create();
32 map.put("dude-0", "tom");
33 map.put("dude-1", "john");
34 map.put("dude-3", "ravi");
35 map.put("dude-4", "alex");
37 TrieMap<String, String> expected = map.immutableSnapshot();
39 final ByteArrayOutputStream bos = new ByteArrayOutputStream();
40 final ObjectOutputStream oos = new ObjectOutputStream(bos);
41 oos.writeObject(expected);
44 final byte[] bytes = bos.toByteArray();
45 final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
46 final ObjectInputStream ois = new ObjectInputStream(bis);
48 @SuppressWarnings("unchecked")
49 final TrieMap<String, String> actual = (TrieMap<String, String>) ois.readObject();
52 Assert.assertEquals(expected, actual);