8 |
|
import junit.framework.*; |
9 |
|
import java.util.*; |
10 |
|
import java.util.concurrent.*; |
11 |
+ |
import java.io.*; |
12 |
|
|
13 |
|
public class CopyOnWriteArrayListTest extends TestCase{ |
14 |
|
|
533 |
|
fail("List subList(int, int) should throw IndexOutofBounds exception"); |
534 |
|
}catch(IndexOutOfBoundsException e){} |
535 |
|
} |
536 |
+ |
|
537 |
+ |
public void testSerialization() { |
538 |
+ |
CopyOnWriteArrayList q = fullArray(10); |
539 |
+ |
|
540 |
+ |
try { |
541 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
542 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
543 |
+ |
out.writeObject(q); |
544 |
+ |
out.close(); |
545 |
+ |
|
546 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
547 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
548 |
+ |
CopyOnWriteArrayList r = (CopyOnWriteArrayList)in.readObject(); |
549 |
+ |
assertEquals(q.size(), r.size()); |
550 |
+ |
assertTrue(q.equals(r)); |
551 |
+ |
assertTrue(r.equals(q)); |
552 |
+ |
} catch(Exception e){ |
553 |
+ |
e.printStackTrace(); |
554 |
+ |
fail("unexpected exception"); |
555 |
+ |
} |
556 |
+ |
} |
557 |
|
|
558 |
|
} |