01: /*
02: * Copyright 2001-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.collections.iterators;
17:
18: import java.util.ArrayList;
19: import java.util.Arrays;
20: import java.util.Collections;
21: import java.util.List;
22: import java.util.ListIterator;
23:
24: import junit.framework.Test;
25: import junit.framework.TestSuite;
26:
27: import org.apache.commons.collections.Unmodifiable;
28:
29: /**
30: * Tests the UnmodifiableListIterator.
31: *
32: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
33: *
34: * @author Stephen Colebourne
35: */
36: public class TestUnmodifiableListIterator extends
37: AbstractTestListIterator {
38:
39: protected String[] testArray = { "One", "Two", "Three" };
40: protected List testList = new ArrayList(Arrays.asList(testArray));
41:
42: public static Test suite() {
43: return new TestSuite(TestUnmodifiableListIterator.class);
44: }
45:
46: public TestUnmodifiableListIterator(String testName) {
47: super (testName);
48: }
49:
50: public ListIterator makeEmptyListIterator() {
51: return UnmodifiableListIterator.decorate(Collections.EMPTY_LIST
52: .listIterator());
53: }
54:
55: public ListIterator makeFullListIterator() {
56: return UnmodifiableListIterator.decorate(testList
57: .listIterator());
58: }
59:
60: public boolean supportsRemove() {
61: return false;
62: }
63:
64: public boolean supportsAdd() {
65: return false;
66: }
67:
68: public boolean supportsSet() {
69: return false;
70: }
71:
72: //-----------------------------------------------------------------------
73: public void testListIterator() {
74: assertTrue(makeEmptyListIterator() instanceof Unmodifiable);
75: }
76:
77: public void testDecorateFactory() {
78: ListIterator it = makeFullListIterator();
79: assertSame(it, UnmodifiableListIterator.decorate(it));
80:
81: it = testList.listIterator();
82: assertTrue(it != UnmodifiableListIterator.decorate(it));
83:
84: try {
85: UnmodifiableListIterator.decorate(null);
86: fail();
87: } catch (IllegalArgumentException ex) {
88: }
89: }
90:
91: }
|