1 /* 2 * Copyright (C) 2009 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 17 package java.lang.reflect; 18 19 public class ConstructorTest extends junit.framework.TestCase { 20 public void test_getExceptionTypes() throws Exception { 21 Constructor<?> constructor = ConstructorTestHelper.class.getConstructor(new Class[0]); 22 Class[] exceptions = constructor.getExceptionTypes(); 23 assertEquals(1, exceptions.length); 24 assertEquals(IndexOutOfBoundsException.class, exceptions[0]); 25 // Check that corrupting our array doesn't affect other callers. 26 exceptions[0] = NullPointerException.class; 27 exceptions = constructor.getExceptionTypes(); 28 assertEquals(1, exceptions.length); 29 assertEquals(IndexOutOfBoundsException.class, exceptions[0]); 30 } 31 32 public void test_getParameterTypes() throws Exception { 33 Class[] expectedParameters = new Class[] { Object.class }; 34 Constructor<?> constructor = ConstructorTestHelper.class.getConstructor(expectedParameters); 35 Class[] parameters = constructor.getParameterTypes(); 36 assertEquals(1, parameters.length); 37 assertEquals(expectedParameters[0], parameters[0]); 38 // Check that corrupting our array doesn't affect other callers. 39 parameters[0] = String.class; 40 parameters = constructor.getParameterTypes(); 41 assertEquals(1, parameters.length); 42 assertEquals(expectedParameters[0], parameters[0]); 43 } 44 45 static class ConstructorTestHelper { 46 public ConstructorTestHelper() throws IndexOutOfBoundsException { } 47 public ConstructorTestHelper(Object o) { } 48 } 49 } 50