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.ArrayCharList; 022import org.apache.commons.collections.primitives.CharIterator; 023import org.apache.commons.collections.primitives.CharList; 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 BaseUnmodifiableCharIteratorTest extends TestCase { 030 031 // conventional 032 // ------------------------------------------------------------------------ 033 034 public BaseUnmodifiableCharIteratorTest(String testName) { 035 super(testName); 036 } 037 038 039 // framework 040 // ------------------------------------------------------------------------ 041 protected abstract CharIterator makeUnmodifiableCharIterator(); 042 043 protected CharIterator makeCharIterator() { 044 CharList list = new ArrayCharList(); 045 for(char i=0;i<10;i++) { 046 list.add(i); 047 } 048 return list.iterator(); 049 } 050 051 // tests 052 // ------------------------------------------------------------------------ 053 054 public final void testCharIteratorNotModifiable() { 055 CharIterator iter = makeUnmodifiableCharIterator(); 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 testIterateCharIterator() { 067 CharIterator iter = makeUnmodifiableCharIterator(); 068 for(CharIterator expected = makeCharIterator(); expected.hasNext(); ) { 069 assertTrue(iter.hasNext()); 070 assertEquals(expected.next(),iter.next()); 071 } 072 assertTrue(! iter.hasNext() ); 073 } 074 075}