Reputation: 367
Required to Mock class.method.method ,Given the example below It's always giving Null pointer Exception.
expect( EasyMock.mock(TBXClient.class).getStatus().getMessage()).andReturn("check");
Can anyone help me to resolve the same?
Upvotes: 0
Views: 78
Reputation: 5711
There are no mock chaining. The result of getStatus
should also be a mock on which you will mock getMessage
and then everything will work as expected
TBXClient client = mock(TBXClient.class);
Status status = mock(Status.class);
expect(client.getStatus()).andReturn(status);
expect(status.getMessage()).andReturn("check");
replay(client, status);
However, Status
looks a lot like a value type, so it probably doesn't need to be mocked. In this case, I would just do.
TBXClient client = mock(TBXClient.class);
expect(client.getStatus()).andReturn(Status.CHECK);
replay(client, status);
Upvotes: 2