01: package org.jgroups.tests;
02:
03: import junit.framework.TestCase;
04: import org.jgroups.util.UnmodifiableVector;
05:
06: import java.util.Iterator;
07: import java.util.ListIterator;
08: import java.util.Vector;
09:
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");
22: v.add("two");
23: uv = new UnmodifiableVector(v);
24: }
25:
26: public void tearDown() throws Exception {
27: super .tearDown();
28: }
29:
30: public void testCreation() {
31: assertEquals(v.size(), uv.size());
32: assertTrue(uv.contains("two"));
33: }
34:
35: public void testAddition() {
36: try {
37: uv.add("three");
38: fail("should throw an exception");
39: } catch (UnsupportedOperationException ex) {
40: // expected
41: }
42: }
43:
44: public void testRemoval() {
45: try {
46: uv.add("two");
47: fail("should throw an exception");
48: } catch (UnsupportedOperationException ex) {
49: // expected
50: }
51: }
52:
53: public void testIteration() {
54: Object el;
55: for (Iterator it = uv.iterator(); it.hasNext();) {
56: el = it.next();
57: System.out.println(el);
58: }
59:
60: for (Iterator it = uv.iterator(); it.hasNext();) {
61: el = it.next();
62: try {
63: it.remove();
64: fail("should throw exception");
65: } catch (UnsupportedOperationException ex) {
66: // expected
67: }
68: }
69: }
70:
71: public void testListIteration() {
72: Object el;
73: for (ListIterator it = uv.listIterator(); it.hasNext();) {
74: el = it.next();
75: System.out.println(el);
76: }
77:
78: for (ListIterator it = uv.listIterator(); it.hasNext();) {
79: el = it.next();
80: try {
81: it.remove();
82: fail("should throw exception");
83: } catch (UnsupportedOperationException ex) {
84: // expected
85: }
86: }
87: }
88:
89: public static void main(String[] args) {
90: String[] testCaseName = { UnmodifiableVectorTest.class
91: .getName() };
92: junit.textui.TestRunner.main(testCaseName);
93: }
94:
95: }
|