-3

I have mocked the request and the response using the easymock, but its still going through each line in the request method and getting exception.

Eg:

public class helper{

public String getCB(){
  Response response = serviceImpl.getDefaultMethod(request);
  return response.getString();
}

Test:

expect(MockServiceImpl.getDefaultMethod(mockRequest)).andReturn(mockResponse);

Getting an exception, Its going inside the getDefaultMethod().

I'm not understanding why its going through the code in that method. Can anyone please help me?

Arne Burmeister
  • 20,046
  • 8
  • 53
  • 94
  • 1
    please add [MCVE](http://stackoverflow.com/help/mcve)s for both, the production code and the test. – Timothy Truckle Dec 23 '16 at 09:58
  • I tried with the posted example, it didn't worked for me. https://stackoverflow.com/questions/60500323/i-am-mocking-the-method-but-in-the-test-when-i-called-the-method-debugger-going – Anvesh Reddy Mar 06 '20 at 06:12
  • https://stackoverflow.com/questions/60500323/i-am-mocking-the-method-but-in-the-test-when-i-called-the-method-debugger-going – Anvesh Reddy Mar 06 '20 at 06:14

2 Answers2

0

AFAIK easymock is not able to mock static method calls.

You should move the line

Response response = ServiceImpl.getDefaultMethod(request);

out of the method and mock request.

The other approach was to use PowerMock, but IMHO that's a surrender to bad design.

Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51
0

If the method is not static and not final, it should work.

If it doesn't, it means you are not calling this method on a mock but on an real instance of the class. Showing us the mock creation and injection will help us confirm that.

Henri
  • 5,551
  • 1
  • 22
  • 29