1808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes/* 2808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * Copyright (C) 2009 The Android Open Source Project 3808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * 4808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 5808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * you may not use this file except in compliance with the License. 6808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * You may obtain a copy of the License at 7808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * 8808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 9808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * 10808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * Unless required by applicable law or agreed to in writing, software 11808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 12808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * See the License for the specific language governing permissions and 14808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes * limitations under the License. 15808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes */ 16808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes 17808049474c23a2e8c3849ff7700d118bc406784dElliott Hughespackage java.lang.reflect; 18808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes 19808049474c23a2e8c3849ff7700d118bc406784dElliott Hughespublic class MethodTest extends junit.framework.TestCase { 20808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes public void test_getExceptionTypes() throws Exception { 21808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes Method method = MethodTestHelper.class.getMethod("m1", new Class[0]); 22808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes Class[] exceptions = method.getExceptionTypes(); 23808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes assertEquals(1, exceptions.length); 24808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes assertEquals(IndexOutOfBoundsException.class, exceptions[0]); 25808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes // Check that corrupting our array doesn't affect other callers. 26808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes exceptions[0] = NullPointerException.class; 27808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes exceptions = method.getExceptionTypes(); 28808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes assertEquals(1, exceptions.length); 29808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes assertEquals(IndexOutOfBoundsException.class, exceptions[0]); 30808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes } 31808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes 32808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes public void test_getParameterTypes() throws Exception { 33808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes Class[] expectedParameters = new Class[] { Object.class }; 34808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes Method method = MethodTestHelper.class.getMethod("m2", expectedParameters); 35808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes Class[] parameters = method.getParameterTypes(); 36808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes assertEquals(1, parameters.length); 37808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes assertEquals(expectedParameters[0], parameters[0]); 38808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes // Check that corrupting our array doesn't affect other callers. 39808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes parameters[0] = String.class; 40808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes parameters = method.getParameterTypes(); 41808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes assertEquals(1, parameters.length); 42808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes assertEquals(expectedParameters[0], parameters[0]); 43808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes } 44808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes 45808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes static class MethodTestHelper { 46808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes public void m1() throws IndexOutOfBoundsException { } 47808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes public void m2(Object o) { } 48808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes } 49808049474c23a2e8c3849ff7700d118bc406784dElliott Hughes} 50