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-29 02:45:08 -0500 (Wed, 29 Nov 2006) $
25 * @author Rodney Waldhoff
26 */
27 public class TestRandomAccessShortList extends TestCase {
28
29 // conventional
30 // ------------------------------------------------------------------------
31
32 public TestRandomAccessShortList(String testName) {
33 super(testName);
34 }
35
36 public static Test suite() {
37 return new TestSuite(TestRandomAccessShortList.class);
38 }
39
40 // tests
41 // ------------------------------------------------------------------------
42
43 public void testAddIsUnsupportedByDefault() {
44 RandomAccessShortList list = new AbstractRandomAccessShortListImpl();
45 try {
46 list.add((short)1);
47 fail("Expected UnsupportedOperationException");
48 } catch(UnsupportedOperationException e) {
49 // expected
50 }
51 try {
52 list.set(0,(short)1);
53 fail("Expected UnsupportedOperationException");
54 } catch(UnsupportedOperationException e) {
55 // expected
56 }
57 }
58
59 public void testAddAllIsUnsupportedByDefault() {
60 RandomAccessShortList list = new AbstractRandomAccessShortListImpl();
61 ShortList list2 = new ArrayShortList();
62 list2.add((short)3);
63 try {
64 list.addAll(list2);
65 fail("Expected UnsupportedOperationException");
66 } catch(UnsupportedOperationException e) {
67 // expected
68 }
69 }
70
71 public void testSetIsUnsupportedByDefault() {
72 RandomAccessShortList list = new AbstractRandomAccessShortListImpl();
73 try {
74 list.set(0,(short)1);
75 fail("Expected UnsupportedOperationException");
76 } catch(UnsupportedOperationException e) {
77 // expected
78 }
79 }
80
81 public void testRemoveElementIsUnsupportedByDefault() {
82 RandomAccessShortList list = new AbstractRandomAccessShortListImpl();
83 try {
84 list.removeElementAt(0);
85 fail("Expected UnsupportedOperationException");
86 } catch(UnsupportedOperationException e) {
87 // expected
88 }
89 }
90
91 // inner classes
92 // ------------------------------------------------------------------------
93
94
95 static class AbstractRandomAccessShortListImpl extends RandomAccessShortList {
96 public AbstractRandomAccessShortListImpl() {
97 }
98
99 /**
100 * @see org.apache.commons.collections.primitives.ShortList#get(int)
101 */
102 public short get(int index) {
103 throw new IndexOutOfBoundsException();
104 }
105
106 /**
107 * @see org.apache.commons.collections.primitives.ShortCollection#size()
108 */
109 public int size() {
110 return 0;
111 }
112
113 }
114 }