5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
8 |
< |
import java.io.BufferedInputStream; |
9 |
< |
import java.io.BufferedOutputStream; |
10 |
< |
import java.io.ByteArrayInputStream; |
11 |
< |
import java.io.ByteArrayOutputStream; |
12 |
< |
import java.io.ObjectInputStream; |
13 |
< |
import java.io.ObjectOutputStream; |
14 |
< |
import java.util.*; |
8 |
> |
import java.util.Arrays; |
9 |
> |
import java.util.ArrayDeque; |
10 |
> |
import java.util.Collection; |
11 |
> |
import java.util.Deque; |
12 |
> |
import java.util.Iterator; |
13 |
> |
import java.util.NoSuchElementException; |
14 |
> |
import java.util.Queue; |
15 |
> |
import java.util.Random; |
16 |
|
|
17 |
|
public class ArrayDequeTest extends JSR166TestCase { |
18 |
|
public static void main(String[] args) { |
812 |
|
* A deserialized serialized deque has same elements in same order |
813 |
|
*/ |
814 |
|
public void testSerialization() throws Exception { |
815 |
< |
ArrayDeque q = populatedDeque(SIZE); |
816 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
817 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
818 |
< |
out.writeObject(q); |
819 |
< |
out.close(); |
820 |
< |
|
821 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
822 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
823 |
< |
ArrayDeque r = (ArrayDeque)in.readObject(); |
824 |
< |
assertEquals(q.size(), r.size()); |
825 |
< |
while (!q.isEmpty()) |
826 |
< |
assertEquals(q.remove(), r.remove()); |
815 |
> |
Queue x = populatedDeque(SIZE); |
816 |
> |
Queue y = serialClone(x); |
817 |
> |
|
818 |
> |
assertTrue(x != y); |
819 |
> |
assertEquals(x.size(), y.size()); |
820 |
> |
assertEquals(x.toString(), y.toString()); |
821 |
> |
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
822 |
> |
while (!x.isEmpty()) { |
823 |
> |
assertFalse(y.isEmpty()); |
824 |
> |
assertEquals(x.remove(), y.remove()); |
825 |
> |
} |
826 |
> |
assertTrue(y.isEmpty()); |
827 |
|
} |
828 |
|
|
829 |
|
} |