001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.collections.primitives.decorators; 018 019import org.apache.commons.collections.primitives.ArrayDoubleList; 020import org.apache.commons.collections.primitives.DoubleIterator; 021import org.apache.commons.collections.primitives.DoubleList; 022import org.apache.commons.collections.primitives.DoubleListIterator; 023 024/** 025 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $ 026 * @author Rodney Waldhoff 027 */ 028public abstract class BaseUnmodifiableDoubleListIteratorTest extends BaseUnmodifiableDoubleIteratorTest { 029 030 // conventional 031 // ------------------------------------------------------------------------ 032 033 public BaseUnmodifiableDoubleListIteratorTest(String testName) { 034 super(testName); 035 } 036 037 038 // framework 039 // ------------------------------------------------------------------------ 040 041 protected abstract DoubleListIterator makeUnmodifiableDoubleListIterator(); 042 043 protected DoubleIterator makeUnmodifiableDoubleIterator() { 044 return makeUnmodifiableDoubleListIterator(); 045 } 046 047 protected DoubleIterator makeDoubleIterator() { 048 return makeDoubleListIterator(); 049 } 050 051 protected DoubleListIterator makeDoubleListIterator() { 052 DoubleList list = new ArrayDoubleList(); 053 for(double i=0;i<10;i++) { 054 list.add(i); 055 } 056 return list.listIterator(); 057 } 058 059 // tests 060 // ------------------------------------------------------------------------ 061 062 public final void testDoubleListIteratorNotModifiable() { 063 DoubleListIterator iter = makeUnmodifiableDoubleListIterator(); 064 assertTrue(iter.hasNext()); 065 iter.next(); 066 try { 067 iter.remove(); 068 fail("Expected UnsupportedOperationException"); 069 } catch(UnsupportedOperationException e) { 070 // expected 071 } 072 try { 073 iter.add((double)1); 074 fail("Expected UnsupportedOperationException"); 075 } catch(UnsupportedOperationException e) { 076 // expected 077 } 078 try { 079 iter.set((double)3); 080 fail("Expected UnsupportedOperationException"); 081 } catch(UnsupportedOperationException e) { 082 // expected 083 } 084 } 085 086 public final void testIterateDoubleListIterator() { 087 DoubleListIterator iter = makeUnmodifiableDoubleListIterator(); 088 DoubleListIterator expected = makeDoubleListIterator(); 089 090 assertTrue(! iter.hasPrevious()); 091 092 while( expected.hasNext() ) { 093 assertTrue(iter.hasNext()); 094 assertEquals(expected.nextIndex(),iter.nextIndex()); 095 assertEquals(expected.previousIndex(),iter.previousIndex()); 096 assertEquals(expected.next(),iter.next(),(double)0); 097 assertTrue(iter.hasPrevious()); 098 assertEquals(expected.nextIndex(),iter.nextIndex()); 099 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}