1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package libcore.java.lang; 18 19import junit.framework.TestCase; 20 21public final class ArrayIndexOutOfBoundsExceptionTest extends TestCase { 22 public void testAput() throws Exception { 23 byte[] bs = new byte[1]; 24 try { 25 bs[2] = 0; 26 fail(); 27 } catch (ArrayIndexOutOfBoundsException ex) { 28 assertEquals("length=1; index=2", ex.getMessage()); 29 } 30 } 31 32 public void testAget() throws Exception { 33 byte[] bs = new byte[1]; 34 try { 35 byte b = bs[2]; 36 fail(); 37 } catch (ArrayIndexOutOfBoundsException ex) { 38 assertEquals("length=1; index=2", ex.getMessage()); 39 } 40 } 41 42 public void testAputWide() throws Exception { 43 double[] ds = new double[1]; 44 try { 45 ds[2] = 0.0; 46 fail(); 47 } catch (ArrayIndexOutOfBoundsException ex) { 48 assertEquals("length=1; index=2", ex.getMessage()); 49 } 50 } 51 52 public void testAgetWide() throws Exception { 53 double[] ds = new double[1]; 54 try { 55 double d = ds[2]; 56 fail(); 57 } catch (ArrayIndexOutOfBoundsException ex) { 58 assertEquals("length=1; index=2", ex.getMessage()); 59 } 60 } 61 62 public void testAputObject() throws Exception { 63 Object[] os = new Object[1]; 64 try { 65 os[2] = null; 66 fail(); 67 } catch (ArrayIndexOutOfBoundsException ex) { 68 assertEquals("length=1; index=2", ex.getMessage()); 69 } 70 } 71 72 public void testAgetObject() throws Exception { 73 Object[] os = new Object[1]; 74 try { 75 Object o = os[2]; 76 fail(); 77 } catch (ArrayIndexOutOfBoundsException ex) { 78 assertEquals("length=1; index=2", ex.getMessage()); 79 } 80 } 81} 82