This repository was archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathSerializationTest.java
More file actions
executable file
·60 lines (46 loc) · 1.83 KB
/
SerializationTest.java
File metadata and controls
executable file
·60 lines (46 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.ardverk.collection;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import junit.framework.TestCase;
import org.junit.Test;
public class SerializationTest {
@Test
public void serialize() throws IOException, ClassNotFoundException {
Trie<String, String> trie1
= new PatriciaTrie<String, String>(
StringKeyAnalyzer.CHAR);
trie1.put("Hello", "World");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(trie1);
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
@SuppressWarnings("unchecked")
Trie<String, String> trie2 = (Trie<String, String>)ois.readObject();
ois.close();
TestCase.assertEquals(trie1.size(), trie2.size());
TestCase.assertEquals("World", trie2.get("Hello"));
}
@Test
public void prefixMap() throws IOException, ClassNotFoundException {
Trie<String, String> trie1
= new PatriciaTrie<String, String>(
StringKeyAnalyzer.CHAR);
trie1.put("Hello", "World");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(trie1);
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
@SuppressWarnings("unchecked")
Trie<String, String> trie2 = (Trie<String, String>)ois.readObject();
ois.close();
TestCase.assertEquals(1, trie1.prefixMap("Hello").size());
TestCase.assertEquals(1, trie2.prefixMap("Hello").size());
}
}