1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections.primitives;
18
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22
23
24
25
26
27 public class TestRandomAccessCharList extends TestCase {
28
29
30
31
32 public TestRandomAccessCharList(String testName) {
33 super(testName);
34 }
35
36 public static Test suite() {
37 return new TestSuite(TestRandomAccessCharList.class);
38 }
39
40
41
42
43 public void testAddIsUnsupportedByDefault() {
44 RandomAccessCharList list = new AbstractRandomAccessCharListImpl();
45 try {
46 list.add((char)1);
47 fail("Expected UnsupportedOperationException");
48 } catch(UnsupportedOperationException e) {
49
50 }
51 try {
52 list.set(0,(char)1);
53 fail("Expected UnsupportedOperationException");
54 } catch(UnsupportedOperationException e) {
55
56 }
57 }
58
59 public void testAddAllIsUnsupportedByDefault() {
60 RandomAccessCharList list = new AbstractRandomAccessCharListImpl();
61 CharList list2 = new ArrayCharList();
62 list2.add((char)3);
63 try {
64 list.addAll(list2);
65 fail("Expected UnsupportedOperationException");
66 } catch(UnsupportedOperationException e) {
67
68 }
69 }
70
71 public void testSetIsUnsupportedByDefault() {
72 RandomAccessCharList list = new AbstractRandomAccessCharListImpl();
73 try {
74 list.set(0,(char)1);
75 fail("Expected UnsupportedOperationException");
76 } catch(UnsupportedOperationException e) {
77
78 }
79 }
80
81 public void testRemoveElementIsUnsupportedByDefault() {
82 RandomAccessCharList list = new AbstractRandomAccessCharListImpl();
83 try {
84 list.removeElementAt(0);
85 fail("Expected UnsupportedOperationException");
86 } catch(UnsupportedOperationException e) {
87
88 }
89 }
90
91
92
93
94
95 static class AbstractRandomAccessCharListImpl extends RandomAccessCharList {
96 public AbstractRandomAccessCharListImpl() {
97 }
98
99
100
101
102 public char get(int index) {
103 throw new IndexOutOfBoundsException();
104 }
105
106
107
108
109 public int size() {
110 return 0;
111 }
112
113 }
114 }