I can’t figure out what is wrong with this, hopefully someone can help:
I have an enum, MyEnum that is used as a parameter to a method I am trying to mock. The mocking looks a bit like this:
when(myMockedObject.getMethod(MyEnum.XYZ)).thenReturn(myMockedValue);
and the actual code execution looks like this:
MyMockedValue theMockedValue = myMockedObject.getMethod(MyEnum.XYZ);
I’m expecting theMockedValue to equal myMockedValue. However, the mocking is not working and theMockedValue is always null. What is wrong with this?
This was down to my own dodgy code. I found a duplicated mock object, one instance was involved in the mocking and the other was being used in the code, resulting in null values being returned.
Just as I thought I was losing the battle with mockito and now I realise I do understand what is going on.