我正在junit上使用PowerMockRunner來模擬靜態方法。JUnit:攔截方法調用,然後調用不同的參數
我知道靜態方法可以使用when(...).thenReturn(...)
被嘲笑我需要模擬一定的方法,該方法有四個參數:
public static void addInputPath(String, Boolean, Integer, Double)
我需要第三個參數(整數)在任何調用此方法將被替換爲10
。所有其他參數應該按原樣傳遞。
換句話說,我需要做的是這樣的:
when(addInputPath(str, bool, intgr, dbl)).thenReturn(addInputPath(str, bool, 10, dbl));
有沒有辦法做到這一點?
此線程回答此問題: http://stackoverflow.com/questions/5462096/stubbing-a-method-that-takes-classt-as-parameter-with-mockito – kolakao
我不相信你可以替換一個參數,你可以做的是給你的方法的返回值給定的參數 –
@kolakao不知道這是我想要的。簡化我的問題。 –