Im getting the following error, when I try to mock overloaded methods by passing casted values .
For example in order to mock ABCClass.logWarn(Logger log,String , String description, Throwable e);
Im doing
`ABCClass.logWarn(null,WarningString, description, (Throwable)null);
...\\ The rest of the methods are standard...
verify(event).setStatus((Throwable)null);//**Line 76**
But when I run my test cases Im getting the following error
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:.....
Why is setStatus(null)
expected to be called, even after specifically calling thesetStatus((Throwable)null);
?
Additional Detail
Definition of 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();
}
Answer
Being new to Mockito I didnt quite realise what I was looking for. But this is precisely what I wanted.
Hope this helps anyone else stuck with a similar problem.
No comments:
Post a Comment