#39 Stackoverflow with toString

EasyMock_3.0
open
nobody
EasyMock (40)
5
2014-02-22
2010-07-23
Virtualwarp
No

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();

}
}

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks