In the spirit of providing a possible solution (and unlike my comments above), you can try one of the following
Option 1
If TestClass implements an interface, you can achieve a similar test using andDelegateTo () , as described in this post, which says Easymock does not support spying
Option 2
Take TestClass need for espionage by expanding TestClass specifically for your testing requirements. This is a general approach to working with legacy code bases, where you cannot modify the tested code.
I use Mockito in this example so that it is consistent with your question, however the concept will work the same with Easymock.
public class TestClassUsingMockito { private class ClassForTesting extends TestClass { private Lock lock; private IndexData indexData; public ClassForTesting(IndexData indexData, Lock lock) { this.indexData = indexData; this.lock = lock; } @Override protected IndexData getIndex(InputClass input) { return indexData; } } @Test public void testAddUsesWriteLock() {
What is the analogue of Mockito.spy / doReturn in EasyMock?
So, by removing the need for Spy () in your tests, calling Mockito
Mockito.doReturn(lock).when(indexData).getWriteLock();
Can be written in EasyMock as
expect(indexData.getWriteLock()).andStubReturn(lock);
EasyMock example of the same Mockito test above
public class TestClassUsingEasymock extends EasyMockSupport { private class ClassForTesting extends TestClass { private Lock lock; private IndexData indexData; public ClassForTesting(IndexData indexData, Lock lock) { this.indexData = indexData; this.lock = lock; } @Override protected IndexData getIndex(InputClass input) { return indexData; } } @Test public void testAddUsesWriteLock() {