ReflectionUtil { public static RuntimeException convertReflectionExceptionToUnchecked(Exception e) { if ((e instanceof IllegalAccessException) || (e instanceof NoSuchMethodException)) { return new IllegalArgumentException(e); } else if (e instanceof InvocationTargetException) { return new RuntimeException(((InvocationTargetException) e).getTargetException()); } else if (e instanceof RuntimeException) { return (RuntimeException) e; } return new UncheckedException(e); }  static Method getSetterMethod(Class<?> clazz, String propertyName, Class<?> parameterType); static Method getGetterMethod(Class<?> clazz, String propertyName); static Method getMethod(final Class<?> clazz, final String methodName, Class<?>... parameterTypes); static Method getAccessibleMethodByName(final Class clazz, final String methodName); static Field getField(final Class clazz, final String fieldName); static T invokeGetter(Object obj, String propertyName); static void invokeSetter(Object obj, String propertyName, Object value); static T getFieldValue(final Object obj, final String fieldName); static T getFieldValue(final Object obj, final Field field); static void setFieldValue(final Object obj, final String fieldName, final Object value); static void setField(final Object obj, Field field, final Object value); static T getProperty(Object obj, String propertyName); static void setProperty(Object obj, String propertyName, final Object value); static T invokeMethod(Object obj, String methodName, Object... args); static T invokeMethod(final Object obj, final String methodName, final Object[] args,
			final Class<?>[] parameterTypes); static T invokeMethodByName(final Object obj, final String methodName, final Object[] args); static T invokeMethod(final Object obj, Method method, Object... args); static T invokeConstructor(final Class<T> cls, Object... args); static void makeAccessible(Method method); static void makeAccessible(Field field); static RuntimeException convertReflectionExceptionToUnchecked(Exception e);  }
@Test public void convertReflectionExceptionToUnchecked() { IllegalArgumentException iae = new IllegalArgumentException(); RuntimeException e = ReflectionUtil.convertReflectionExceptionToUnchecked(iae); assertThat(e).isEqualTo(iae); Exception ex = new Exception(); e = ReflectionUtil.convertReflectionExceptionToUnchecked(new InvocationTargetException(ex)); assertThat(e.getCause()).isEqualTo(ex); RuntimeException re = new RuntimeException("abc"); e = ReflectionUtil.convertReflectionExceptionToUnchecked(re); assertThat(e).hasMessage("abc"); e = ReflectionUtil.convertReflectionExceptionToUnchecked(ex); assertThat(e).isInstanceOf(UncheckedException.class); }