org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation()方法的一些代码示例,展示了WhiteboxImpl.performMethodInvocation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WhiteboxImpl.performMethodInvocation()方法的具体详情如下:
包路径:org.powermock.reflect.internal.WhiteboxImpl
类名称:WhiteboxImpl
方法名:performMethodInvocation

WhiteboxImpl.performMethodInvocation介绍

[英]Perform method invocation.
[中]执行方法调用。

代码示例

代码示例来源:origin: org.powermock.api/powermock-api-easymock

@SuppressWarnings("unchecked")
private static <T> IExpectationSetters<T> doExpectPrivate(Object instance, Method methodToExpect, Object... arguments) throws Exception {
  WhiteboxImpl.performMethodInvocation(instance, methodToExpect, arguments);
  return (IExpectationSetters<T>) org.easymock.classextension.EasyMock.expectLastCall();
}

代码示例来源:origin: org.powermock/powermock-reflect

/**
 * Do invoke method.
 *
 * @param <T>             the generic type
 * @param tested          the tested
 * @param declaringClass  the declaring class
 * @param methodToExecute the method to execute
 * @param arguments       the arguments
 * @return the t
 * @throws Exception the exception
 */
@SuppressWarnings("unchecked")
private static <T> T doInvokeMethod(Object tested, Class<?> declaringClass, String methodToExecute,
                  Object... arguments) throws Exception {
  Method methodToInvoke = findMethodOrThrowException(tested, declaringClass, methodToExecute, arguments);
  // Invoke test
  return (T) performMethodInvocation(tested, methodToInvoke, arguments);
}

代码示例来源:origin: org.powermock/powermock-reflect

/**
 * Invoke a private method in that is located in a subclass of an instance.
 * This might be useful to test overloaded private methods.
 * 
 * Use this for overloaded methods only, if possible use
 *
 * @param <T>             the generic type
 * @param object          the object
 * @param declaringClass  the declaring class
 * @param methodToExecute the method to execute
 * @param parameterTypes  the parameter types
 * @param arguments       the arguments
 * @return the t
 * @throws Exception Exception that may occur when invoking this method.
 *                   {@link #invokeMethod(Object, Object...)} or
 *                   {@link #invokeMethod(Object, String, Object...)} instead.
 */
@SuppressWarnings("unchecked")
public static synchronized <T> T invokeMethod(Object object, Class<?> declaringClass, String methodToExecute,
                       Class<?>[] parameterTypes, Object... arguments) throws Exception {
  if (object == null) {
    throw new IllegalArgumentException("object cannot be null");
  }
  final Method methodToInvoke = getMethod(declaringClass, methodToExecute, parameterTypes);
  // Invoke method
  return (T) performMethodInvocation(object, methodToInvoke, arguments);
}

代码示例来源:origin: org.powermock.reflect/powermock-reflect

/**
 * Do invoke method.
 * 
 * @param <T>
 *            the generic type
 * @param tested
 *            the tested
 * @param declaringClass
 *            the declaring class
 * @param methodToExecute
 *            the method to execute
 * @param arguments
 *            the arguments
 * @return the t
 * @throws Exception
 *             the exception
 */
@SuppressWarnings("unchecked")
private static <T> T doInvokeMethod(Object tested, Class<?> declaringClass, String methodToExecute,
    Object... arguments) throws Exception {
  Method methodToInvoke = findMethodOrThrowException(tested, declaringClass, methodToExecute, arguments);
  // Invoke test
  return (T) performMethodInvocation(tested, methodToInvoke, arguments);
}

代码示例来源:origin: org.powermock.reflect/powermock-reflect

return (T) performMethodInvocation(object, methodToInvoke, arguments);

代码示例来源:origin: org.powermock/powermock-reflect

/**
 * Invoke a private or inner class method in a subclass (defined by
 * {@code definedIn}) in cases where power mock cannot automatically
 * determine the type of the parameters, for example when mixing primitive
 * types and wrapper types in the same method. For most situations use
 *
 * @param <T>             the generic type
 * @param tested          the tested
 * @param methodToExecute the method to execute
 * @param definedIn       the defined in
 * @param argumentTypes   the argument types
 * @param arguments       the arguments
 * @return the t
 * @throws Exception Exception that may occur when invoking this method.
 *                   {@link #invokeMethod(Class, String, Object...)} instead.
 */
@SuppressWarnings("unchecked")
public static synchronized <T> T invokeMethod(Object tested, String methodToExecute, Class<?> definedIn,
                       Class<?>[] argumentTypes, Object... arguments) throws Exception {
  Method method = getMethod(definedIn, methodToExecute, argumentTypes);
  if (method == null) {
    throwExceptionIfMethodWasNotFound(definedIn, methodToExecute, null, arguments);
  }
  return (T) performMethodInvocation(tested, method, arguments);
}

代码示例来源:origin: org.powermock.reflect/powermock-reflect

throwExceptionIfMethodWasNotFound(definedIn, methodToExecute, null, arguments);
return (T) performMethodInvocation(tested, method, arguments);

代码示例来源:origin: org.powermock/powermock-reflect

/**
 * Invoke a private or inner class method in cases where power mock cannot
 * automatically determine the type of the parameters, for example when
 * mixing primitive types and wrapper types in the same method. For most
 * situations use {@link #invokeMethod(Class, String, Object...)} instead.
 *
 * @param <T>             the generic type
 * @param tested          the tested
 * @param methodToExecute the method to execute
 * @param argumentTypes   the argument types
 * @param arguments       the arguments
 * @return the t
 * @throws Exception Exception that may occur when invoking this method.
 */
@SuppressWarnings("unchecked")
public static synchronized <T> T invokeMethod(Object tested, String methodToExecute, Class<?>[] argumentTypes,
                       Object... arguments) throws Exception {
  final Class<?> unmockedType = getType(tested);
  Method method = getMethod(unmockedType, methodToExecute, argumentTypes);
  if (method == null) {
    throwExceptionIfMethodWasNotFound(unmockedType, methodToExecute, null, arguments);
  }
  return (T) performMethodInvocation(tested, method, arguments);
}

代码示例来源:origin: org.powermock.reflect/powermock-reflect

/**
 * Invoke a private or inner class method in cases where power mock cannot
 * automatically determine the type of the parameters, for example when
 * mixing primitive types and wrapper types in the same method. For most
 * situations use {@link #invokeMethod(Class, String, Object...)} instead.
 * 
 * @param <T>
 *            the generic type
 * @param tested
 *            the tested
 * @param methodToExecute
 *            the method to execute
 * @param argumentTypes
 *            the argument types
 * @param arguments
 *            the arguments
 * @return the t
 * @throws Exception
 *             Exception that may occur when invoking this method.
 */
@SuppressWarnings("unchecked")
public static synchronized <T> T invokeMethod(Object tested, String methodToExecute, Class<?>[] argumentTypes,
    Object... arguments) throws Exception {
  final Class<?> unmockedType = getType(tested);
  Method method = getMethod(unmockedType, methodToExecute, argumentTypes);
  if (method == null) {
    throwExceptionIfMethodWasNotFound(unmockedType, methodToExecute, null, arguments);
  }
  return (T) performMethodInvocation(tested, method, arguments);
}

相关文章

WhiteboxImpl类方法