ClassUtil { public static Method[] getBeanMethods(Class<?> type, String propertyName, Class<?> propertyType, boolean caseSensitive) throws IllegalAccessException, NoSuchMethodException { Method methods[] = new Method[2]; methods[0] = getMethod(type, "get"+propertyName, propertyType, null, caseSensitive); methods[1] = getMethod(type, "set"+propertyName, null, propertyType, caseSensitive); return methods; }  static Object findEnumConstant(Class<?> type, String constantName); static Object findEnumConstant(Class<?> type, String constantName, boolean caseSensitive); static Class<?>[] getClassHierarchy(Class<?> type); static boolean hasBeanMethods(Class<?> type, String propertyName, Class<?> propertyType, boolean caseSensitive); static Method[] getBeanMethods(Class<?> type, String propertyName, Class<?> propertyType, boolean caseSensitive); static Method getMethod(Class<?> type, String name, Class<?> returnType, Class<?> paramType, boolean caseSensitive);  }
@Test public void getBeanMethods() throws Exception { Method expectedGetMethod = Person.class.getMethod("getFirstName"); Method expectedSetMethod = Person.class.getMethod("setFirstName", String.class); Method[] methods = ClassUtil.getBeanMethods(InternetPerson.class, "firstname", String.class, false); Assert.assertEquals(expectedGetMethod, methods[0]); Assert.assertEquals(expectedSetMethod, methods[1]); methods = ClassUtil.getBeanMethods(InternetPerson.class, "FirstName", String.class, true); Assert.assertEquals(expectedGetMethod, methods[0]); Assert.assertEquals(expectedSetMethod, methods[1]); }
@Test(expected=NoSuchMethodException.class) public void getBeanMethodsOnlyGet() throws Exception { Method[] methods = ClassUtil.getBeanMethods(InternetPerson.class, "email2", String.class, false); }