当我尝试通过传递强制转换的值来模拟重载方法时,出现以下错误。
例如为了模拟
ABCClass.logWarn(Logger log,String , String description, Throwable e);
我正在做
`ABCClass.logWarn(null,WarningString, description, (Throwable)null);
...\\ The rest of the methods are standard...
verify(event).setStatus((Throwable)null);//**Line 76**
但是当我运行我的测试用例时,我收到以下错误
ABCClassTest.testLogWarn:76
Wanted but not invoked:
MockEvent.setStatus(null);
-> at com.path.ABCClassTest.testLogWarn(ABCClassTest.java:76)
However, there were other interactions with this mock:.....
为什么setStatus(null)
预期会被调用,即使在专门调用
setStatus((Throwable)null);
?
附加细节
logWarn的定义
private static void logWarn(String eventType, String eventName, String errMsg, Throwable e) {
AnEvent event = AnEventFactory.create(eventType);
event.setName(eventName);
if(e!=null)
event.setStatus(e);//so this is never called if the throwable is null.
//How do I modify the verify behavior?
/*
Bleh */
event.completed();
}