ReflectionUtils { public static Object invoke(Method method, Object self) throws InvocationTargetException { try { return forceAccessible(method).invoke(self); } catch (IllegalArgumentException | IllegalAccessException e) { throw new IllegalStateException(e); } }  static String getSimpleName(Class<?> klass); static String getPrettyName(Class<?> klass); static @Nullable Method findMethod(Class<?> klass, Class<? extends Annotation> annotation,
      Class<?>... signature); static Object invoke(Method method, Object self); static Object readField(Class<?> klass, String name); static Object readField(Class<?> klass, @Nullable Object self, String name); static M forceAccessible(M member); static void invokePostConstruct(List<?> objects); static void invokePreDestroy(List<?> objects); static final Function<Object, String> TO_SIMPLECLASSNAME; static final Function<Object, String> TO_CLASSNAME; static final Function<Object, String> TO_PRETTYCLASSNAME; }
@Test public void testInvoke() throws SecurityException, InvocationTargetException, NoSuchMethodException { assertEquals(3, ReflectionUtils.invoke(String.class.getMethod("length"), "xyz")); }
@Test(expected = IllegalStateException.class) public void testInvoke_illegalState() throws SecurityException, InvocationTargetException, NoSuchMethodException { assertEquals(3, ReflectionUtils.invoke(String.class.getMethod("length"), 10)); }