79466158

Date: 2025-02-25 10:26:44
Score: 1
Natty:
Report link

Since SomeController.class is itself a mock, u need to mock its methods responses. What u did was to mock a method someMethod() inside the method createReturnType() that is actually called. What will happen is that the method createReturnType() in the mcoked class will be ignored of what is inside it returning null. A fixation to ur code is to either:

1- mock the method createReturnType() itself to get a result
2- @Spy SomeController.class instead of mocking it

But in either ways, its not a best practice to test mock the class of the methods that is needed to be tested since testing is calling the actual method testing its behaviour.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Spyinstead
  • Low reputation (1):
Posted by: Mohamed Essam