KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > misc > CopyOnWriteArrayTest


1 package org.jboss.cache.tests.misc;
2
3 import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList;
4 import junit.framework.Test;
5 import junit.framework.TestCase;
6 import junit.framework.TestSuite;
7
8 import java.util.Iterator JavaDoc;
9 import java.util.LinkedList JavaDoc;
10
11 /**
12  * @author Bela Ban
13  * @version $Id: CopyOnWriteArrayTest.java,v 1.1.1.1 2005/03/31 10:15:10 belaban Exp $
14  */

15 public class CopyOnWriteArrayTest extends TestCase {
16    LinkedList JavaDoc l;
17    CopyOnWriteArrayList list;
18    Exception JavaDoc thread_ex=null;
19
20    protected void setUp() throws Exception JavaDoc {
21       super.setUp();
22       l=new LinkedList JavaDoc();
23       l.add("one");
24       l.add("two");
25       l.add("three");
26       list=new CopyOnWriteArrayList(l);
27       thread_ex=null;
28    }
29
30    protected void tearDown() throws Exception JavaDoc {
31       super.tearDown();
32       if(thread_ex != null)
33          throw thread_ex;
34    }
35
36
37    public void testInsertionandIteration() {
38       Object JavaDoc el;
39       System.out.println("list = " + list);
40
41       Iterator JavaDoc it=list.iterator();
42       System.out.println(it.next());
43
44       list.add("four");
45
46       int count=0;
47       while(it.hasNext()) {
48          el=it.next();
49          System.out.println(el);
50          ++count;
51       }
52       assertEquals(2, count);
53
54       System.out.println("list: " + list);
55       assertEquals(4, list.size());
56    }
57
58
59
60
61
62    public static Test suite() {
63       return new TestSuite(CopyOnWriteArrayTest.class);
64    }
65
66    public static void main(String JavaDoc[] args) {
67       junit.textui.TestRunner.run(suite());
68    }
69
70 }
71
Popular Tags