I have tried multiple ways to mock HttpResponse(custom class not related to any library) object but it's not mocking. Below is my code. please suggest if mistake. or any other suggestions to respond.
Note: I can't modify or write any factory method or any extra stuff on my MyClass
Class MyClass{
public void methodtoTest(ListOfObjects obj){
HttpResponse response = null;
response = HttpOperationHelper.executeHttpPostResponse(client, uri, heade, postBoday);
if(response.getStatusCode() == 200){
//some code is there
}
}
HttpOperationHelper is helper class in the project and executeHttpPostResponse is static method.
@PrepareForTest(HttpOperationHelper.class)
Class MyClassTest{
HttpResponse response = Mockito.mock(HttpResponse.class);
response = HttpResponse.getInstance(200, "body");
Powermockito.mockStatic(HttpOperationHelper.class);
Mockit.when(HttpOperationHelper.executeHttpPostResponse(anyObject(), anyObject(), anyObject(), anyString())).thenReturn(response);
}