ReflectionHelper { public static Object invokeMethod(final Object targetObject, final String methodName, final Object... params) { try { final List<Method> methodsByName = findMethodsByName(targetObject.getClass(), methodName); final Method method = methodsByName.stream() .filter(candidate -> candidate.getParameterCount() == params.length) .findFirst() .orElseThrow(ReflectionHelper::noAppropriateMethodFound); method.setAccessible(true); return method.invoke(targetObject, params); } catch (InvocationTargetException | IllegalAccessException e) { throw new IllegalStateException(e); } }  static T instantiate(final Class<? extends T> type, final Object... params); static Object invokeMethod(final Object targetObject,
                                      final String methodName,
                                      final Object... params); static boolean argumentTypesCompatible(final Executable executable,
                                                  final Object[] prms); static boolean typeIsCompatible(final Object paramObject, final Class<?> type); static Class<?> wrapPrimitive(final Class<?> type);  }
@Test public void invokeMethodWithoutParam() { class MethodWithoutParam { String foo() { return "bar"; } } assertThat(invokeMethod(new MethodWithoutParam(), "foo"), CoreMatchers.is("bar")); }
@Test public void invokeMethodWithParams() { class MethodWithTwoParams { String foo(final String fizz, final int buzz) { return fizz + buzz; } } assertThat(invokeMethod(new MethodWithTwoParams(), "foo", "abc", 123), CoreMatchers.is("abc123")); }