1 package org.jgroups.tests; 2 3 import junit.framework.TestCase; 4 import org.jgroups.util.UnmodifiableVector; 5 6 import java.util.Iterator ; 7 import java.util.ListIterator ; 8 import java.util.Vector ; 9 10 public class UnmodifiableVectorTest extends TestCase { 11 Vector v; 12 UnmodifiableVector uv; 13 14 public UnmodifiableVectorTest(String name) { 15 super(name); 16 } 17 18 public void setUp() throws Exception { 19 super.setUp(); 20 v=new Vector(); 21 v.add("one"); v.add("two"); 22 uv=new UnmodifiableVector(v); 23 } 24 25 26 public void tearDown() throws Exception { 27 super.tearDown(); 28 } 29 30 31 public void testCreation() { 32 assertEquals(v.size(), uv.size()); 33 assertTrue(uv.contains("two")); 34 } 35 36 public void testAddition() { 37 try { 38 uv.add("three"); 39 fail("should throw an exception"); 40 } 41 catch(UnsupportedOperationException ex) { 42 } 44 } 45 46 public void testRemoval() { 47 try { 48 uv.add("two"); 49 fail("should throw an exception"); 50 } 51 catch(UnsupportedOperationException ex) { 52 } 54 } 55 56 public void testIteration() { 57 Object el; 58 for(Iterator it=uv.iterator(); it.hasNext();) { 59 el=it.next(); 60 System.out.println(el); 61 } 62 63 for(Iterator it=uv.iterator(); it.hasNext();) { 64 el=it.next(); 65 try { 66 it.remove(); 67 fail("should throw exception"); 68 } 69 catch(UnsupportedOperationException ex) { 70 } 72 } 73 } 74 75 public void testListIteration() { 76 Object el; 77 for(ListIterator it=uv.listIterator(); it.hasNext();) { 78 el=it.next(); 79 System.out.println(el); 80 } 81 82 for(ListIterator it=uv.listIterator(); it.hasNext();) { 83 el=it.next(); 84 try { 85 it.remove(); 86 fail("should throw exception"); 87 } 88 catch(UnsupportedOperationException ex) { 89 } 91 } 92 } 93 94 public static void main(String [] args) { 95 String [] testCaseName={UnmodifiableVectorTest.class.getName()}; 96 junit.textui.TestRunner.main(testCaseName); 97 } 98 99 } 100 | Popular Tags |