KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > primitives > TestShortCollections


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.commons.collections.primitives;
18
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22
23 /**
24  * @version $Revision: 480451 $ $Date: 2006-11-28 23:45:08 -0800 (Tue, 28 Nov 2006) $
25  * @author Rodney Waldhoff
26  */

27 public class TestShortCollections extends TestCase {
28
29     //------------------------------------------------------------ Conventional
30

31     public TestShortCollections(String JavaDoc testName) {
32         super(testName);
33     }
34
35     public static Test suite() {
36         return new TestSuite(TestShortCollections.class);
37     }
38
39     //---------------------------------------------------------------- Tests
40

41     public void testSingletonShortListIterator() {
42         ShortListIterator iter = ShortCollections.singletonShortListIterator((short)17);
43         assertTrue(!iter.hasPrevious());
44         assertTrue(iter.hasNext());
45         assertEquals(17,iter.next());
46         assertTrue(iter.hasPrevious());
47         assertTrue(!iter.hasNext());
48         assertEquals(17,iter.previous());
49         try {
50             iter.set((short)18);
51             fail("Expected UnsupportedOperationException");
52         } catch(UnsupportedOperationException JavaDoc e) {
53             // expected
54
}
55     }
56
57     public void testSingletonShortIterator() {
58         ShortIterator iter = ShortCollections.singletonShortIterator((short)17);
59         assertTrue(iter.hasNext());
60         assertEquals(17,iter.next());
61         assertTrue(!iter.hasNext());
62         try {
63             iter.remove();
64             fail("Expected UnsupportedOperationException");
65         } catch(UnsupportedOperationException JavaDoc e) {
66             // expected
67
}
68     }
69
70     public void testSingletonShortList() {
71         ShortList list = ShortCollections.singletonShortList((short)17);
72         assertEquals(1,list.size());
73         assertEquals(17,list.get(0));
74         try {
75             list.add((short)18);
76             fail("Expected UnsupportedOperationException");
77         } catch(UnsupportedOperationException JavaDoc e) {
78             // expected
79
}
80     }
81
82     public void testUnmodifiableShortListNull() {
83         try {
84             ShortCollections.unmodifiableShortList(null);
85             fail("Expected NullPointerException");
86         } catch(NullPointerException JavaDoc e) {
87             // expected
88
}
89     }
90
91     public void testEmptyShortList() {
92         assertSame(ShortCollections.EMPTY_SHORT_LIST,ShortCollections.getEmptyShortList());
93         assertTrue(ShortCollections.EMPTY_SHORT_LIST.isEmpty());
94         try {
95             ShortCollections.EMPTY_SHORT_LIST.add((short)1);
96             fail("Expected UnsupportedOperationExcpetion");
97         } catch(UnsupportedOperationException JavaDoc e) {
98             // expected
99
}
100     }
101
102     public void testUnmodifiableShortIteratorNull() {
103         try {
104             ShortCollections.unmodifiableShortIterator(null);
105             fail("Expected NullPointerException");
106         } catch(NullPointerException JavaDoc 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 JavaDoc e) {
118             // expected
119
}
120     }
121
122     public void testUnmodifiableShortListIteratorNull() {
123         try {
124             ShortCollections.unmodifiableShortListIterator(null);
125             fail("Expected NullPointerException");
126         } catch(NullPointerException JavaDoc 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 JavaDoc e) {
139             // expected
140
}
141     }
142 }
143
144
Popular Tags