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 TestRandomAccessFloatList extends TestCase { 028 029 // conventional 030 // ------------------------------------------------------------------------ 031 032 public TestRandomAccessFloatList(String testName) { 033 super(testName); 034 } 035 036 public static Test suite() { 037 return new TestSuite(TestRandomAccessFloatList.class); 038 } 039 040 // tests 041 // ------------------------------------------------------------------------ 042 043 public void testAddIsUnsupportedByDefault() { 044 RandomAccessFloatList list = new AbstractRandomAccessFloatListImpl(); 045 try { 046 list.add((float)1); 047 fail("Expected UnsupportedOperationException"); 048 } catch(UnsupportedOperationException e) { 049 // expected 050 } 051 try { 052 list.set(0,(float)1); 053 fail("Expected UnsupportedOperationException"); 054 } catch(UnsupportedOperationException e) { 055 // expected 056 } 057 } 058 059 public void testAddAllIsUnsupportedByDefault() { 060 RandomAccessFloatList list = new AbstractRandomAccessFloatListImpl(); 061 FloatList list2 = new ArrayFloatList(); 062 list2.add((float)3); 063 try { 064 list.addAll(list2); 065 fail("Expected UnsupportedOperationException"); 066 } catch(UnsupportedOperationException e) { 067 // expected 068 } 069 } 070 071 public void testSetIsUnsupportedByDefault() { 072 RandomAccessFloatList list = new AbstractRandomAccessFloatListImpl(); 073 try { 074 list.set(0,(float)1); 075 fail("Expected UnsupportedOperationException"); 076 } catch(UnsupportedOperationException e) { 077 // expected 078 } 079 } 080 081 public void testRemoveElementIsUnsupportedByDefault() { 082 RandomAccessFloatList list = new AbstractRandomAccessFloatListImpl(); 083 try { 084 list.removeElementAt(0); 085 fail("Expected UnsupportedOperationException"); 086 } catch(UnsupportedOperationException e) { 087 // expected 088 } 089 } 090 091 // inner classes 092 // ------------------------------------------------------------------------ 093 094 095 static class AbstractRandomAccessFloatListImpl extends RandomAccessFloatList { 096 public AbstractRandomAccessFloatListImpl() { 097 } 098 099 /** 100 * @see org.apache.commons.collections.primitives.FloatList#get(int) 101 */ 102 public float get(int index) { 103 throw new IndexOutOfBoundsException(); 104 } 105 106 /** 107 * @see org.apache.commons.collections.primitives.FloatCollection#size() 108 */ 109 public int size() { 110 return 0; 111 } 112 113 } 114}