当前位置: 首页>>代码示例>>Java>>正文


Java WhiteboxImpl.findMethodOrThrowException方法代码示例

本文整理汇总了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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:31,代码来源:PowerMock.java

示例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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:13,代码来源:SuppressCode.java

示例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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:8,代码来源:WhiteBoxTest.java

示例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"));
	}
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:11,代码来源:WhiteBoxTest.java

示例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());
	}
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:12,代码来源:WhiteBoxTest.java


注:本文中的org.powermock.reflect.internal.WhiteboxImpl.findMethodOrThrowException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。