When passing an object to a mock in the toString method and the expectation wasn't setup, the call results in a stackoverflow.
I think it would be better to catch this exception and just use the objects classname. An improvement may be to detect, if easymock is processing an expectattion failure and just throw a special exception in the case there is another mock called while calculating toString. This way easymock doesn't have to wait for an stackoverflow to occure.
Example:
public class StackOverflowTest extends TestCase {
public interface IInformationProvider {
public String getName(Wrapper wrapper);
}
public static class Wrapper {
private final IInformationProvider fProvider; public Wrapper(IInformationProvider provider) { fProvider = provider; } @Override public String toString() { return fProvider.getName(this); }
}
public void test_overflow() {
IMocksControl control = createStrictControl();
IInformationProvider mockedInfoProvider = control.createMock(IInformationProvider.class);
control.replay(); new Wrapper(mockedInfoProvider).toString(); control.verify();
}
}