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.Iterator;
22: import java.util.List;
23:
24: import junit.framework.Test;
25: import junit.framework.TestSuite;
26:
27: import org.apache.commons.collections.Unmodifiable;
28:
29: /**
30: * Tests the UnmodifiableIterator.
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 TestUnmodifiableIterator extends AbstractTestIterator {
37:
38: protected String[] testArray = { "One", "Two", "Three" };
39: protected List testList = new ArrayList(Arrays.asList(testArray));
40:
41: public static Test suite() {
42: return new TestSuite(TestUnmodifiableIterator.class);
43: }
44:
45: public TestUnmodifiableIterator(String testName) {
46: super (testName);
47: }
48:
49: public Iterator makeEmptyIterator() {
50: return UnmodifiableIterator.decorate(Collections.EMPTY_LIST
51: .iterator());
52: }
53:
54: public Iterator makeFullIterator() {
55: return UnmodifiableIterator.decorate(testList.iterator());
56: }
57:
58: public boolean supportsRemove() {
59: return false;
60: }
61:
62: //-----------------------------------------------------------------------
63: public void testIterator() {
64: assertTrue(makeEmptyIterator() instanceof Unmodifiable);
65: }
66:
67: public void testDecorateFactory() {
68: Iterator it = makeFullIterator();
69: assertSame(it, UnmodifiableIterator.decorate(it));
70:
71: it = testList.iterator();
72: assertTrue(it != UnmodifiableIterator.decorate(it));
73:
74: try {
75: UnmodifiableIterator.decorate(null);
76: fail();
77: } catch (IllegalArgumentException ex) {
78: }
79: }
80:
81: }
|