I am trying to test that an Interface method was called with and exact value passed in. I'm getting the following error:
org.mockito.exceptions.misusing.UnfinishedVerificationException: Missing method call for verify(mock) here: -> at com.example.app.initialize(example.java:136)
Example of correct verification: verify(mock).doSomething()
The error is being thrown on this verification line:
Mockito.verify(callback).onInitializeResult("initialized");
My Interface class:
public interface InitCallback {
/**
* Returns whether or not the app was initialized. .
*/
void onInitializeResult(String result);
}
My Unit Test:
@Test
public void initializationTest(){
InitCallback callback = Mockito.spy(new InitCallback() {
@Override
public void onInitializeResult(String result) {
}
});
mExample.initialize(mContext, callback);
Mockito.verify(callback).onInitializeResult("initialized");
}
I also tried to replace the callback mock with:
InitCallback callback = Mockito.mock(InitCallback.class);
Mockito.doNothing().when(callback).onInitializeResult(Mockito.anyString());
However I still get the same error. The interface only has 1 method and it is not final. Any Thoughts?