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;
26 public class TestSerialization {
28 public void testSerialization() throws IOException, ClassNotFoundException {
29 TrieMap<String, String> map = TrieMap.create();
31 map.put("dude-0", "tom");
32 map.put("dude-1", "john");
33 map.put("dude-3", "ravi");
34 map.put("dude-4", "alex");
36 TrieMap<String, String> expected = map.immutableSnapshot();
38 final ByteArrayOutputStream bos = new ByteArrayOutputStream();
39 final ObjectOutputStream oos = new ObjectOutputStream(bos);
40 oos.writeObject(expected);
43 final byte[] bytes = bos.toByteArray();
44 final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
45 final ObjectInputStream ois = new ObjectInputStream(bis);
47 @SuppressWarnings("unchecked")
48 final TrieMap<String, String> actual = (TrieMap<String, String>) ois.readObject();
51 Assert.assertEquals(expected, actual);