Skip to content
Advertisement

Mockito when method not working

I am using mockito as mocking framework. I have a scenerio here, my when(abc.method()).thenReturn(value) does not return value, instead it returns null.

JavaScript

}

Java class

JavaScript

When ever i run the test file the when is not working and i am using mockito1.8.5 jar in the buildpath. The service call is being mocked but returns the null value.

JavaScript

This object dqCntlWfDefnTyp is null

I have done this before and there was no problem with the when, It seems to be working with files i have done before. I had followed the same procedure for the test file but i couldnt figure out the issue. Can anyone please assist me

Thanks to all the folks in advance

Advertisement

Answer

Mockito mock works when we mock the objects loosely.

Here is the change i have made to make it work:

JavaScript

Instead of passing the object of the Mock class, I passed the class with the Matcher any() and it works.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement