KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > iterators > TestUnmodifiableIterator


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.util.Arrays JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
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: 1.3 $ $Date: 2004/02/18 01:20:33 $
33  *
34  * @author Stephen Colebourne
35  */

36 public class TestUnmodifiableIterator extends AbstractTestIterator {
37
38     protected String JavaDoc[] testArray = { "One", "Two", "Three" };
39     protected List JavaDoc testList = new ArrayList JavaDoc(Arrays.asList(testArray));
40
41     public static Test suite() {
42         return new TestSuite(TestUnmodifiableIterator.class);
43     }
44
45     public TestUnmodifiableIterator(String JavaDoc testName) {
46         super(testName);
47     }
48
49     public Iterator JavaDoc makeEmptyIterator() {
50         return UnmodifiableIterator.decorate(Collections.EMPTY_LIST.iterator());
51     }
52
53     public Iterator JavaDoc makeFullIterator() {
54         return UnmodifiableIterator.decorate(testList.iterator());
55     }
56
57     public boolean supportsRemove() {
58         return false;
59     }
60
61     //-----------------------------------------------------------------------
62
public void testIterator() {
63         assertTrue(makeEmptyIterator() instanceof Unmodifiable);
64     }
65     
66     public void testDecorateFactory() {
67         Iterator JavaDoc it = makeFullIterator();
68         assertSame(it, UnmodifiableIterator.decorate(it));
69         
70         it = testList.iterator();
71         assertTrue(it != UnmodifiableIterator.decorate(it));
72         
73         try {
74             UnmodifiableIterator.decorate(null);
75             fail();
76         } catch (IllegalArgumentException JavaDoc ex) {}
77     }
78
79 }
80
Popular Tags