KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
22 import java.util.ListIterator 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 UnmodifiableListIterator.
31  *
32  * @version $Revision: 1.3 $ $Date: 2004/02/18 01:20:33 $
33  *
34  * @author Stephen Colebourne
35  */

36 public class TestUnmodifiableListIterator extends AbstractTestListIterator {
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(TestUnmodifiableListIterator.class);
43     }
44
45     public TestUnmodifiableListIterator(String JavaDoc testName) {
46         super(testName);
47     }
48
49     public ListIterator JavaDoc makeEmptyListIterator() {
50         return UnmodifiableListIterator.decorate(Collections.EMPTY_LIST.listIterator());
51     }
52
53     public ListIterator JavaDoc makeFullListIterator() {
54         return UnmodifiableListIterator.decorate(testList.listIterator());
55     }
56
57     public boolean supportsRemove() {
58         return false;
59     }
60
61     public boolean supportsAdd() {
62         return false;
63     }
64
65     public boolean supportsSet() {
66         return false;
67     }
68
69     //-----------------------------------------------------------------------
70
public void testListIterator() {
71         assertTrue(makeEmptyListIterator() instanceof Unmodifiable);
72     }
73     
74     public void testDecorateFactory() {
75         ListIterator JavaDoc it = makeFullListIterator();
76         assertSame(it, UnmodifiableListIterator.decorate(it));
77         
78         it = testList.listIterator();
79         assertTrue(it != UnmodifiableListIterator.decorate(it));
80         
81         try {
82             UnmodifiableListIterator.decorate(null);
83             fail();
84         } catch (IllegalArgumentException JavaDoc ex) {}
85     }
86
87 }
88
Popular Tags