New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stackoverflow with toString #53

Open
henri-tremblay opened this Issue Jun 3, 2015 · 0 comments

Comments

Projects
None yet
1 participant
@henri-tremblay
Contributor

henri-tremblay commented Jun 3, 2015

Migrated from: CodeHaus issue EASYMOCK-42
Original reporter: Henri Tremblay


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

}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment