Is there a simple way to mock this call:
objectA.getB().getC();
right now the way I do this is:
A mockA = EasyMock.createMock(A.class);
B mockB = EasyMock.createMock(B.class);
C mockC = EasyMock.createMock(C.class);
expect(mockA.getB()).andReturn(mockB);
expect(mockB.getC()).andReturn(mockC);
This is a bit of an overkill since all I care is to get mockC. Is there an easier way to do it?
I know the question is about EasyMock, but i can't just sit on my hands and not tell you about Mockito. The mocking you would like to do, is fairly easy in Mockito.
A mockA = Mockito.mock(A.class, RETURNS_DEEP_STUBS);
C mockC = Mockito.mock(C.class);
Mockito.when(mockA.getB().getC()).thenReturn(mockC);
Note that Mockito started off as enhancement to EasyMock, you may read more about it here: https://code.google.com/p/mockito/wiki/MockitoVSEasyMock
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With