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.ArrayShortList; 020import org.apache.commons.collections.primitives.ShortIterator; 021import org.apache.commons.collections.primitives.ShortList; 022import org.apache.commons.collections.primitives.ShortListIterator; 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 BaseUnmodifiableShortListIteratorTest extends BaseUnmodifiableShortIteratorTest { 029 030 // conventional 031 // ------------------------------------------------------------------------ 032 033 public BaseUnmodifiableShortListIteratorTest(String testName) { 034 super(testName); 035 } 036 037 038 // framework 039 // ------------------------------------------------------------------------ 040 041 protected abstract ShortListIterator makeUnmodifiableShortListIterator(); 042 043 protected ShortIterator makeUnmodifiableShortIterator() { 044 return makeUnmodifiableShortListIterator(); 045 } 046 047 protected ShortIterator makeShortIterator() { 048 return makeShortListIterator(); 049 } 050 051 protected ShortListIterator makeShortListIterator() { 052 ShortList list = new ArrayShortList(); 053 for(short i=0;i<10;i++) { 054 list.add(i); 055 } 056 return list.listIterator(); 057 } 058 059 // tests 060 // ------------------------------------------------------------------------ 061 062 public final void testShortListIteratorNotModifiable() { 063 ShortListIterator iter = makeUnmodifiableShortListIterator(); 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((short)1); 074 fail("Expected UnsupportedOperationException"); 075 } catch(UnsupportedOperationException e) { 076 // expected 077 } 078 try { 079 iter.set((short)3); 080 fail("Expected UnsupportedOperationException"); 081 } catch(UnsupportedOperationException e) { 082 // expected 083 } 084 } 085 086 public final void testIterateShortListIterator() { 087 ShortListIterator iter = makeUnmodifiableShortListIterator(); 088 ShortListIterator expected = makeShortListIterator(); 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()); 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()); 109 assertTrue(iter.hasNext()); 110 assertEquals(expected.nextIndex(),iter.nextIndex()); 111 assertEquals(expected.previousIndex(),iter.previousIndex()); 112 } 113 assertTrue(! iter.hasPrevious() ); 114 } 115 116}