PowerMock ExpectNew如何指定参数类型 [英] PowerMock expectNew how to specify the type of the parameters
本文介绍了PowerMock ExpectNew如何指定参数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用PowerMock模拟构造函数时,我想指定参数的类型.我用的方法
When I use PowerMock to mock the constructor,I want to specify the type of the paremeters. I use the method
PowerMock.expectNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments)
如果要指定String
类型,我应该在parameterTypes
中填写什么?
If I want to specify the String
type, what shoud I fill in the parameterTypes
?
推荐答案
给出以下示例类:
public class MyClass {
public MyClass(String theParam) {
//Some interesting code...
}
}
public class MyFactory {
public MyClass createMyClass() {
return new MyClass("foo");
}
}
然后您将执行expectNew
如下:
public class MyFactoryTest {
@Test
public void testCreateMyClass() {
//...
PowerMock.expectNew(MyClass.class, new Class[] {String.class}, "foo");
//...
}
}
这篇关于PowerMock ExpectNew如何指定参数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文