0

How do you mock a chained method call in EasyMock? I have a chained method call:

srvc.getServiceManager().getDetails(Integer.parseInt(msgId)); 

I've tried to do

expect(srvc.getServiceManager().getDetails(Integer.parseInt(msgId))) .andReturn((String) notNull()); 

This throws a NullPointerException.

Trying to break this into two expectations also does not work. In that case I get

matcher calls were used outside expectations

How do I get around this issue?

1 Answer 1

1

Breaking into two expectations is perfectly fine, something like below:

final Service mockService = createMock(Service.class); final ServiceManager mockServiceManager = createMock(ServiceManager.class); final Capture<Integer> capturedMsgId = new Capture<Integer>(); expect(mockService.getServiceManager()).andReturn(mockServiceManager); expect(mockServiceManager.getDetails(capture(capturedMsgId))).andReturn("someString"); 

You shouldn't get any exception about it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.