KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > primitives > decorators > BaseUnmodifiableDoubleListIteratorTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.commons.collections.primitives.decorators;
18
19 import org.apache.commons.collections.primitives.ArrayDoubleList;
20 import org.apache.commons.collections.primitives.DoubleIterator;
21 import org.apache.commons.collections.primitives.DoubleList;
22 import org.apache.commons.collections.primitives.DoubleListIterator;
23
24 /**
25  * @version $Revision: 480451 $ $Date: 2006-11-28 23:45:08 -0800 (Tue, 28 Nov 2006) $
26  * @author Rodney Waldhoff
27  */

28 public abstract class BaseUnmodifiableDoubleListIteratorTest extends BaseUnmodifiableDoubleIteratorTest {
29
30     // conventional
31
// ------------------------------------------------------------------------
32

33     public BaseUnmodifiableDoubleListIteratorTest(String JavaDoc testName) {
34         super(testName);
35     }
36     
37
38     // framework
39
// ------------------------------------------------------------------------
40

41     protected abstract DoubleListIterator makeUnmodifiableDoubleListIterator();
42
43     protected DoubleIterator makeUnmodifiableDoubleIterator() {
44         return makeUnmodifiableDoubleListIterator();
45     }
46
47     protected DoubleIterator makeDoubleIterator() {
48         return makeDoubleListIterator();
49     }
50     
51     protected DoubleListIterator makeDoubleListIterator() {
52         DoubleList list = new ArrayDoubleList();
53         for(double i=0;i<10;i++) {
54             list.add(i);
55         }
56         return list.listIterator();
57     }
58
59     // tests
60
// ------------------------------------------------------------------------
61

62     public final void testDoubleListIteratorNotModifiable() {
63         DoubleListIterator iter = makeUnmodifiableDoubleListIterator();
64         assertTrue(iter.hasNext());
65         iter.next();
66         try {
67             iter.remove();
68             fail("Expected UnsupportedOperationException");
69         } catch(UnsupportedOperationException JavaDoc e) {
70             // expected
71
}
72         try {
73             iter.add((double)1);
74             fail("Expected UnsupportedOperationException");
75         } catch(UnsupportedOperationException JavaDoc e) {
76             // expected
77
}
78         try {
79             iter.set((double)3);
80             fail("Expected UnsupportedOperationException");
81         } catch(UnsupportedOperationException JavaDoc e) {
82             // expected
83
}
84     }
85
86     public final void testIterateDoubleListIterator() {
87         DoubleListIterator iter = makeUnmodifiableDoubleListIterator();
88         DoubleListIterator expected = makeDoubleListIterator();
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(),(double)0);
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(),(double)0);
109             assertTrue(iter.hasNext());
110             assertEquals(expected.nextIndex(),iter.nextIndex());
111             assertEquals(expected.previousIndex(),iter.previousIndex());
112         }
113         assertTrue(! iter.hasPrevious() );
114     }
115
116 }
Popular Tags