KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > UnmodifiableVectorTest


1 package org.jgroups.tests;
2
3 import junit.framework.TestCase;
4 import org.jgroups.util.UnmodifiableVector;
5
6 import java.util.Iterator JavaDoc;
7 import java.util.ListIterator JavaDoc;
8 import java.util.Vector JavaDoc;
9
10 public class UnmodifiableVectorTest extends TestCase {
11     Vector v;
12     UnmodifiableVector uv;
13
14     public UnmodifiableVectorTest(String JavaDoc name) {
15         super(name);
16     }
17
18     public void setUp() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc ex) {
42             // expected
43
}
44     }
45
46     public void testRemoval() {
47         try {
48             uv.add("two");
49             fail("should throw an exception");
50         }
51         catch(UnsupportedOperationException JavaDoc ex) {
52             // expected
53
}
54     }
55
56     public void testIteration() {
57         Object JavaDoc el;
58         for(Iterator JavaDoc it=uv.iterator(); it.hasNext();) {
59             el=it.next();
60             System.out.println(el);
61         }
62
63         for(Iterator JavaDoc it=uv.iterator(); it.hasNext();) {
64             el=it.next();
65             try {
66                 it.remove();
67                 fail("should throw exception");
68             }
69             catch(UnsupportedOperationException JavaDoc ex) {
70                 // expected
71
}
72         }
73     }
74
75     public void testListIteration() {
76         Object JavaDoc el;
77         for(ListIterator JavaDoc it=uv.listIterator(); it.hasNext();) {
78             el=it.next();
79             System.out.println(el);
80         }
81
82         for(ListIterator JavaDoc it=uv.listIterator(); it.hasNext();) {
83             el=it.next();
84              try {
85                  it.remove();
86                  fail("should throw exception");
87              }
88              catch(UnsupportedOperationException JavaDoc ex) {
89                  // expected
90
}
91         }
92     }
93
94     public static void main(String JavaDoc[] args) {
95         String JavaDoc[] testCaseName={UnmodifiableVectorTest.class.getName()};
96         junit.textui.TestRunner.main(testCaseName);
97     }
98
99 }
100
Popular Tags