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

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

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

WhiteboxImpl.findMethodOrThrowException介绍

[英]Find method or throw exception.
[中]查找方法或抛出异常。

代码示例

代码示例来源: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.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/powermock-api-support

/**
 * Suppress a specific method call. Use this for overloaded methods.
 */
public static synchronized void suppressMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes) {
  Method method = null;
  if (parameterTypes.length > 0) {
    method = Whitebox.getMethod(clazz, methodName, parameterTypes);
  } else {
    method = WhiteboxImpl.findMethodOrThrowException(clazz, methodName, parameterTypes);
  }
  MockRepository.addMethodToSuppress(method);
}

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

/**
 * Suppress a specific method call. Use this for overloaded methods.
 */
public static synchronized void suppressMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes) {
  Method method = null;
  if (parameterTypes.length > 0) {
    method = Whitebox.getMethod(clazz, methodName, parameterTypes);
  } else {
    method = WhiteboxImpl.findMethodOrThrowException(clazz, methodName, parameterTypes);
  }
  MockRepository.addMethodToSuppress(method);
}

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

/**
 * Used to specify expectations on methods using the method name at a
 * specific place in the class hierarchy (specified by the
 * <code>where</code> parameter). Works on for example private or package
 * private methods.
 * <p>
 * Use this for overloaded methods.
 */
public static synchronized <T> IExpectationSetters<T> expectPrivate(Object instance, String methodName, Class<?> where,
    Class<?>[] parameterTypes, Object... arguments) throws Exception {
  if (instance == null) {
    throw new IllegalArgumentException("Instance or class to expect cannot be null.");
  }
  Method[] methods = null;
  if (methodName != null) {
    if (parameterTypes == null) {
      methods = Whitebox.getMethods(where, methodName);
    } else {
      methods = new Method[] { Whitebox.getMethod(where, methodName, parameterTypes) };
    }
  }
  Method methodToExpect;
  if (methods != null && methods.length == 1) {
    methodToExpect = methods[0];
  } else {
    methodToExpect = WhiteboxImpl.findMethodOrThrowException(instance, null, methodName, arguments);
  }
  return doExpectPrivate(instance, methodToExpect, arguments);
}

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

static <T> T doMockSpecific(Class<T> type, MockStrategy mockStrategy, String[] methodNamesToMock, ConstructorArgs constructorArgs,
    Class<?>... argumentTypes) {
  List<Method> methods = new LinkedList<Method>();
  for (String methodName : methodNamesToMock) {
    methods.add(WhiteboxImpl.findMethodOrThrowException(type, methodName, argumentTypes));
  }
  final Method[] methodArray = methods.toArray(new Method[0]);
  if (WhiteboxImpl.areAllMethodsStatic(methodArray)) {
    if (mockStrategy instanceof DefaultMockStrategy) {
      mockStatic(type, methodArray);
    } else if (mockStrategy instanceof StrictMockStrategy) {
      mockStaticStrict(type, methodArray);
    } else {
      mockStaticNice(type, methodArray);
    }
    return null;
  }
  T mock = null;
  if (mockStrategy instanceof DefaultMockStrategy) {
    mock = createMock(type, constructorArgs, methodArray);
  } else if (mockStrategy instanceof StrictMockStrategy) {
    mock = createStrictMock(type, constructorArgs, methodArray);
  } else {
    mock = createNiceMock(type, constructorArgs, methodArray);
  }
  return mock;
}

相关文章

WhiteboxImpl类方法