我想使用groovy的MockFor和proxyDelegateInstance模擬一個具有構造函數參數的java類,但我似乎無法弄清楚它的正確性。我的Java類看起來像:Groovy模擬Java參數的類
class MyJavaClass {
private MyObject myObj
public MyJavaClass(MyObject myObj) {
this.myObj = myObj;
}
}
class MyGroovyTest {
@Test
void testMyJavaClass() {
def mock = new MockFor(MyJavaClass)
MyJavaClass mjc = new MyJavaClass()
def mockProxy = mock.proxyDelegateInstance([mjc] as Object[])
// if I pass mockProxy to anything, I get an error that a matching
// constructor could not be found. I've tried variations on the args
// to proxyDelegateInstance (such as using mjc as a single arg rather than
// an array of one element)
}
}
我可以在groovy中做到這一點嗎?如果是這樣,我該怎麼做?
感謝, 傑夫
您最終使用的是什麼? – user944849 2016-09-28 16:43:52