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 TestShortCollections extends TestCase {
028
029    //------------------------------------------------------------ Conventional
030
031    public TestShortCollections(String testName) {
032        super(testName);
033    }
034
035    public static Test suite() {
036        return new TestSuite(TestShortCollections.class);
037    }
038
039    //---------------------------------------------------------------- Tests
040
041    public void testSingletonShortListIterator() {
042        ShortListIterator iter = ShortCollections.singletonShortListIterator((short)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((short)18);
051            fail("Expected UnsupportedOperationException");
052        } catch(UnsupportedOperationException e) {
053            // expected
054        }
055    }
056
057    public void testSingletonShortIterator() {
058        ShortIterator iter = ShortCollections.singletonShortIterator((short)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 testSingletonShortList() {
071        ShortList list = ShortCollections.singletonShortList((short)17);
072        assertEquals(1,list.size());
073        assertEquals(17,list.get(0));        
074        try {
075            list.add((short)18);
076            fail("Expected UnsupportedOperationException");
077        } catch(UnsupportedOperationException e) {
078            // expected
079        }
080    }
081
082    public void testUnmodifiableShortListNull() {
083        try {
084            ShortCollections.unmodifiableShortList(null);
085            fail("Expected NullPointerException");
086        } catch(NullPointerException e) {
087            // expected
088        }
089    }
090
091    public void testEmptyShortList() {
092        assertSame(ShortCollections.EMPTY_SHORT_LIST,ShortCollections.getEmptyShortList());
093        assertTrue(ShortCollections.EMPTY_SHORT_LIST.isEmpty());
094        try {
095            ShortCollections.EMPTY_SHORT_LIST.add((short)1);
096            fail("Expected UnsupportedOperationExcpetion");
097        } catch(UnsupportedOperationException e) {
098            // expected
099        }
100    }
101
102    public void testUnmodifiableShortIteratorNull() {
103        try {
104            ShortCollections.unmodifiableShortIterator(null);
105            fail("Expected NullPointerException");
106        } catch(NullPointerException e) {
107            // expected
108        }
109    }
110
111    public void testEmptyShortIterator() {
112        assertSame(ShortCollections.EMPTY_SHORT_ITERATOR,ShortCollections.getEmptyShortIterator());
113        assertTrue(! ShortCollections.EMPTY_SHORT_ITERATOR.hasNext());
114        try {
115            ShortCollections.EMPTY_SHORT_ITERATOR.remove();
116            fail("Expected UnsupportedOperationExcpetion");
117        } catch(UnsupportedOperationException e) {
118            // expected
119        }
120    }
121
122    public void testUnmodifiableShortListIteratorNull() {
123        try {
124            ShortCollections.unmodifiableShortListIterator(null);
125            fail("Expected NullPointerException");
126        } catch(NullPointerException e) {
127            // expected
128        }
129    }
130
131    public void testEmptyShortListIterator() {
132        assertSame(ShortCollections.EMPTY_SHORT_LIST_ITERATOR,ShortCollections.getEmptyShortListIterator());
133        assertTrue(! ShortCollections.EMPTY_SHORT_LIST_ITERATOR.hasNext());
134        assertTrue(! ShortCollections.EMPTY_SHORT_LIST_ITERATOR.hasPrevious());
135        try {
136            ShortCollections.EMPTY_SHORT_LIST_ITERATOR.add((short)1);
137            fail("Expected UnsupportedOperationExcpetion");
138        } catch(UnsupportedOperationException e) {
139            // expected
140        }
141    }
142}
143