2015-11-07 19 views
0

我有情況時,我想嘲笑的方法與此參數,我的方法看起來像下面的Mockito使用此參數嘲諷方法

this.listener = myCustomFactory.buildCustomListener(this); 

下面

@Mock 
MyCustomFactory myCustomFactory; 

給出我曾經嘲笑myCustomFactory實例有沒有可能用這個參數來模擬方法。 「這」指的是我正在寫單元測試類,我該類

Mockito.when(this.myCustomFactory.buildCustomListener(this.myClassObjectToBeTested).thenReturn(this.mockedListener); 
+0

是的,你試過嗎?是否有錯誤?應該可以使用 – Tunaki

+0

是的,它返回null,我也試過使用Mockito.any() – Pradeep

+0

@ Tunaki,謝謝你的回覆,請看答案 – Pradeep

回答

0

使用Mockito.any(Class<T> clazz)創建參考解決問題

Mockito.when(this.myCustomFactory.buildCustomListener(Mockito.any (MyClassToBeTested.class)); thenReturn(this.mockedListener);