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 junit.framework.TestCase;
020
021import org.apache.commons.collections.primitives.ArrayFloatList;
022import org.apache.commons.collections.primitives.FloatIterator;
023import org.apache.commons.collections.primitives.FloatList;
024
025/**
026 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $
027 * @author Rodney Waldhoff
028 */
029public abstract class BaseUnmodifiableFloatIteratorTest extends TestCase {
030
031    // conventional
032    // ------------------------------------------------------------------------
033
034    public BaseUnmodifiableFloatIteratorTest(String testName) {
035        super(testName);
036    }
037    
038
039    // framework
040    // ------------------------------------------------------------------------
041    protected abstract FloatIterator makeUnmodifiableFloatIterator();
042
043    protected FloatIterator makeFloatIterator() {
044        FloatList list = new ArrayFloatList();
045        for(float i=0;i<10;i++) {
046            list.add(i);
047        }
048        return list.iterator();
049    }
050
051    // tests
052    // ------------------------------------------------------------------------
053
054    public final void testFloatIteratorNotModifiable() {
055        FloatIterator iter = makeUnmodifiableFloatIterator();
056        assertTrue(iter.hasNext());
057        iter.next();
058        try {
059            iter.remove();
060            fail("Expected UnsupportedOperationException");
061        } catch(UnsupportedOperationException e) {
062            // expected
063        }
064    }
065
066    public final void testIterateFloatIterator() {        
067        FloatIterator iter = makeUnmodifiableFloatIterator();
068        for(FloatIterator expected = makeFloatIterator(); expected.hasNext(); ) {
069            assertTrue(iter.hasNext());
070            assertEquals(expected.next(),iter.next(),(float)0);
071        }
072        assertTrue(! iter.hasNext() );
073    }
074
075}