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.ArrayLongList; 020import org.apache.commons.collections.primitives.LongIterator; 021import org.apache.commons.collections.primitives.LongList; 022import org.apache.commons.collections.primitives.LongListIterator; 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 BaseUnmodifiableLongListIteratorTest extends BaseUnmodifiableLongIteratorTest { 029 030 // conventional 031 // ------------------------------------------------------------------------ 032 033 public BaseUnmodifiableLongListIteratorTest(String testName) { 034 super(testName); 035 } 036 037 038 // framework 039 // ------------------------------------------------------------------------ 040 041 protected abstract LongListIterator makeUnmodifiableLongListIterator(); 042 043 protected LongIterator makeUnmodifiableLongIterator() { 044 return makeUnmodifiableLongListIterator(); 045 } 046 047 protected LongIterator makeLongIterator() { 048 return makeLongListIterator(); 049 } 050 051 protected LongListIterator makeLongListIterator() { 052 LongList list = new ArrayLongList(); 053 for(int i=0;i<10;i++) { 054 list.add(i); 055 } 056 return list.listIterator(); 057 } 058 059 // tests 060 // ------------------------------------------------------------------------ 061 062 public final void testLongListIteratorNotModifiable() { 063 LongListIterator iter = makeUnmodifiableLongListIterator(); 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(1); 074 fail("Expected UnsupportedOperationException"); 075 } catch(UnsupportedOperationException e) { 076 // expected 077 } 078 try { 079 iter.set(3); 080 fail("Expected UnsupportedOperationException"); 081 } catch(UnsupportedOperationException e) { 082 // expected 083 } 084 } 085 086 public final void testIterateLongListIterator() { 087 LongListIterator iter = makeUnmodifiableLongListIterator(); 088 LongListIterator expected = makeLongListIterator(); 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}