本文整理汇总了Java中org.powermock.reflect.internal.WhiteboxImpl.findMethodOrThrowException方法的典型用法代码示例。如果您正苦于以下问题:Java WhiteboxImpl.findMethodOrThrowException方法的具体用法?Java WhiteboxImpl.findMethodOrThrowException怎么用?Java WhiteboxImpl.findMethodOrThrowException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.powermock.reflect.internal.WhiteboxImpl
的用法示例。
在下文中一共展示了WhiteboxImpl.findMethodOrThrowException方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expectPrivate
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
* 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);
}
示例2: suppressMethod
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
* 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);
}
示例3: testFindMethod_classContainingMethodWithNoParameters
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testFindMethod_classContainingMethodWithNoParameters() throws Exception {
Method expected = ClassWithSeveralMethodsWithSameNameOneWithoutParameters.class.getMethod("getDouble");
Method actual = WhiteboxImpl.findMethodOrThrowException(
ClassWithSeveralMethodsWithSameNameOneWithoutParameters.class, "getDouble");
assertEquals(expected, actual);
}
示例4: testFindMethod_classContainingOnlyMethodsWithParameters
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testFindMethod_classContainingOnlyMethodsWithParameters() throws Exception {
try {
WhiteboxImpl.findMethodOrThrowException(ClassWithSeveralMethodsWithSameName.class, "getDouble");
fail("Should throw runtime exception!");
} catch (RuntimeException e) {
assertTrue("Error message did not match", e.getMessage().contains(
"Several matching methods found, please specify the argument parameter types"));
}
}
示例5: testFindMethod_noMethodFound
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testFindMethod_noMethodFound() throws Exception {
try {
WhiteboxImpl.findMethodOrThrowException(ClassWithSeveralMethodsWithSameName.class, "getDouble2");
fail("Should throw runtime exception!");
} catch (RuntimeException e) {
assertEquals("Error message did not match",
"No method found with name 'getDouble2' with parameter types: [ <none> ] in class "
+ ClassWithSeveralMethodsWithSameName.class.getName() + ".", e.getMessage());
}
}