Code example for Method

Methods: getExceptionTypes

0
import java.lang.reflect.Method; 
 
public class MethodTest extends junit.framework.TestCase {
    public void test_getExceptionTypes() throws Exception { 
        Method method = MethodTestHelper.class.getMethod("m1", new Class[0]);
        Class[] exceptions = method.getExceptionTypes();
        assertEquals(1, exceptions.length);
        assertEquals(IndexOutOfBoundsException.class, exceptions[0]);
        // Check that corrupting our array doesn't affect other callers. 
        exceptions[0] = NullPointerException.class;
        exceptions = method.getExceptionTypes();
        assertEquals(1, exceptions.length);
        assertEquals(IndexOutOfBoundsException.class, exceptions[0]);
    } 
 
    public void test_getParameterTypes() throws Exception { 
        Class[] expectedParameters = new Class[] { Object.class };
        Method method = MethodTestHelper.class.getMethod("m2", expectedParameters);
        Class[] parameters = method.getParameterTypes();
        assertEquals(1, parameters.length);
Stop searching for code, let great code find you!  Add Codota to your java IDE