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; 018 019import junit.framework.Test; 020import junit.framework.TestCase; 021import junit.framework.TestSuite; 022 023/** 024 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $ 025 * @author Rodney Waldhoff 026 */ 027public class TestIntCollections extends TestCase { 028 029 //------------------------------------------------------------ Conventional 030 031 public TestIntCollections(String testName) { 032 super(testName); 033 } 034 035 public static Test suite() { 036 return new TestSuite(TestIntCollections.class); 037 } 038 039 //---------------------------------------------------------------- Tests 040 041 public void testSingletonIntListIterator() { 042 IntListIterator iter = IntCollections.singletonIntListIterator(17); 043 assertTrue(!iter.hasPrevious()); 044 assertTrue(iter.hasNext()); 045 assertEquals(17,iter.next()); 046 assertTrue(iter.hasPrevious()); 047 assertTrue(!iter.hasNext()); 048 assertEquals(17,iter.previous()); 049 try { 050 iter.set(18); 051 fail("Expected UnsupportedOperationException"); 052 } catch(UnsupportedOperationException e) { 053 // expected 054 } 055 } 056 057 public void testSingletonIntIterator() { 058 IntIterator iter = IntCollections.singletonIntIterator(17); 059 assertTrue(iter.hasNext()); 060 assertEquals(17,iter.next()); 061 assertTrue(!iter.hasNext()); 062 try { 063 iter.remove(); 064 fail("Expected UnsupportedOperationException"); 065 } catch(UnsupportedOperationException e) { 066 // expected 067 } 068 } 069 070 public void testSingletonIntList() { 071 IntList list = IntCollections.singletonIntList(17); 072 assertEquals(1,list.size()); 073 assertEquals(17,list.get(0)); 074 try { 075 list.add(18); 076 fail("Expected UnsupportedOperationException"); 077 } catch(UnsupportedOperationException e) { 078 // expected 079 } 080 } 081 082 public void testUnmodifiableIntListNull() { 083 try { 084 IntCollections.unmodifiableIntList(null); 085 fail("Expected NullPointerException"); 086 } catch(NullPointerException e) { 087 // expected 088 } 089 } 090 091 public void testEmptyIntList() { 092 assertSame(IntCollections.EMPTY_INT_LIST,IntCollections.getEmptyIntList()); 093 assertTrue(IntCollections.EMPTY_INT_LIST.isEmpty()); 094 try { 095 IntCollections.EMPTY_INT_LIST.add(1); 096 fail("Expected UnsupportedOperationExcpetion"); 097 } catch(UnsupportedOperationException e) { 098 // expected 099 } 100 } 101 102 public void testUnmodifiableIntIteratorNull() { 103 try { 104 IntCollections.unmodifiableIntIterator(null); 105 fail("Expected NullPointerException"); 106 } catch(NullPointerException e) { 107 // expected 108 } 109 } 110 111 public void testEmptyIntIterator() { 112 assertSame(IntCollections.EMPTY_INT_ITERATOR,IntCollections.getEmptyIntIterator()); 113 assertTrue(! IntCollections.EMPTY_INT_ITERATOR.hasNext()); 114 try { 115 IntCollections.EMPTY_INT_ITERATOR.remove(); 116 fail("Expected UnsupportedOperationExcpetion"); 117 } catch(UnsupportedOperationException e) { 118 // expected 119 } 120 } 121 122 public void testUnmodifiableIntListIteratorNull() { 123 try { 124 IntCollections.unmodifiableIntListIterator(null); 125 fail("Expected NullPointerException"); 126 } catch(NullPointerException e) { 127 // expected 128 } 129 } 130 131 public void testEmptyIntListIterator() { 132 assertSame(IntCollections.EMPTY_INT_LIST_ITERATOR,IntCollections.getEmptyIntListIterator()); 133 assertTrue(! IntCollections.EMPTY_INT_LIST_ITERATOR.hasNext()); 134 assertTrue(! IntCollections.EMPTY_INT_LIST_ITERATOR.hasPrevious()); 135 try { 136 IntCollections.EMPTY_INT_LIST_ITERATOR.add(1); 137 fail("Expected UnsupportedOperationExcpetion"); 138 } catch(UnsupportedOperationException e) { 139 // expected 140 } 141 } 142} 143