1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections.primitives.decorators;
18
19 import org.apache.commons.collections.primitives.ArrayByteList;
20 import org.apache.commons.collections.primitives.ByteIterator;
21 import org.apache.commons.collections.primitives.ByteList;
22 import org.apache.commons.collections.primitives.ByteListIterator;
23
24
25
26
27
28 public abstract class BaseUnmodifiableByteListIteratorTest extends BaseUnmodifiableByteIteratorTest {
29
30
31
32
33 public BaseUnmodifiableByteListIteratorTest(String testName) {
34 super(testName);
35 }
36
37
38
39
40
41 protected abstract ByteListIterator makeUnmodifiableByteListIterator();
42
43 protected ByteIterator makeUnmodifiableByteIterator() {
44 return makeUnmodifiableByteListIterator();
45 }
46
47 protected ByteIterator makeByteIterator() {
48 return makeByteListIterator();
49 }
50
51 protected ByteListIterator makeByteListIterator() {
52 ByteList list = new ArrayByteList();
53 for(byte i=0;i<10;i++) {
54 list.add(i);
55 }
56 return list.listIterator();
57 }
58
59
60
61
62 public final void testByteListIteratorNotModifiable() {
63 ByteListIterator iter = makeUnmodifiableByteListIterator();
64 assertTrue(iter.hasNext());
65 iter.next();
66 try {
67 iter.remove();
68 fail("Expected UnsupportedOperationException");
69 } catch(UnsupportedOperationException e) {
70
71 }
72 try {
73 iter.add((byte)1);
74 fail("Expected UnsupportedOperationException");
75 } catch(UnsupportedOperationException e) {
76
77 }
78 try {
79 iter.set((byte)3);
80 fail("Expected UnsupportedOperationException");
81 } catch(UnsupportedOperationException e) {
82
83 }
84 }
85
86 public final void testIterateByteListIterator() {
87 ByteListIterator iter = makeUnmodifiableByteListIterator();
88 ByteListIterator expected = makeByteListIterator();
89
90 assertTrue(! iter.hasPrevious());
91
92 while( expected.hasNext() ) {
93 assertTrue(iter.hasNext());
94 assertEquals(expected.nextIndex(),iter.nextIndex());
95 assertEquals(expected.previousIndex(),iter.previousIndex());
96 assertEquals(expected.next(),iter.next());
97 assertTrue(iter.hasPrevious());
98 assertEquals(expected.nextIndex(),iter.nextIndex());
99 assertEquals(expected.previousIndex(),iter.previousIndex());
100 }
101
102 assertTrue(! iter.hasNext() );
103
104 while( expected.hasPrevious() ) {
105 assertTrue(iter.hasPrevious());
106 assertEquals(expected.nextIndex(),iter.nextIndex());
107 assertEquals(expected.previousIndex(),iter.previousIndex());
108 assertEquals(expected.previous(),iter.previous());
109 assertTrue(iter.hasNext());
110 assertEquals(expected.nextIndex(),iter.nextIndex());
111 assertEquals(expected.previousIndex(),iter.previousIndex());
112 }
113 assertTrue(! iter.hasPrevious() );
114 }
115
116 }