KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package org.jboss.cache.tests;
8
9 import junit.framework.Test;
10 import junit.framework.TestCase;
11 import junit.framework.TestSuite;
12 import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList;
13
14 import java.util.LinkedList JavaDoc;
15 import java.util.Iterator JavaDoc;
16
17 /**
18  * @author Bela Ban
19  * @version $Id: CopyOnWriteArrayTest.java,v 1.1.2.2 2005/04/06 21:07:03 starksm Exp $
20  */

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