1 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 ; 15 import java.util.Iterator ; 16 17 21 public class CopyOnWriteArrayTest extends TestCase { 22 LinkedList l; 23 CopyOnWriteArrayList list; 24 Exception thread_ex=null; 25 26 protected void setUp() throws Exception { 27 super.setUp(); 28 l=new LinkedList (); 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 { 37 super.tearDown(); 38 if(thread_ex != null) 39 throw thread_ex; 40 } 41 42 43 public void testInsertionandIteration() { 44 Object el; 45 System.out.println("list = " + list); 46 47 Iterator 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 [] args) { 73 junit.textui.TestRunner.run(suite()); 74 } 75 76 } 77 | Popular Tags |