Tuesday, February 5, 2013

Verifying void methods with Mockito

I had the following problem with Mockito


class MyClass{
 void logSupportingServiceWarn(File dummyFile, String aString){
 }
}

MyClass task = Mockito.spy(new MyClass())
Mockito.never(task.logSupportingServiceWarn(dummyFile, null));

> Java gives the following error :
'void' type not allowed here

Well, this is an issue with Java because it does not allow you to pass in void as a parameter.
Actually it's documented on the website, but I could still not find the exact syntax.

Instead do this :


Mockito.verify(task, Mockito.never()).logSupportingServiceWarn(dummyFile, null);



No comments:

Post a Comment