I am trying to mock an external API call but with the code structure I do not know whether mockito is going to help.
I have a SimpleController:
public class SimpleController extends Anothercontroller
{
@RequestMapping("/classA")
{
.......
String response = postCall(url, .....);
}
}
public class AnotherController
{
public String postCall (String url, ......)
{
//This is the apache library to make post calls
return WebUtil.post(......);
}
}
So now I need to mock the postCall which is a call to the external service.
Here I can mock at 2 places:
1) postCall() in the SimpleController, howevere I dont know how to do that since it favors inheritance over composition.
2) WebUtil.post(.....) however I don't know how mockito can mock a static method.
I don't want to refactor the code structure since there is also a lot of other code depenedent on it as well.