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

Improve documentation concerning callRealMethod() #830

kriegaex opened this Issue Mar 11, 2018 · 0 comments


None yet
2 participants

kriegaex commented Mar 11, 2018

I got curious when reading this question on StackOverflow. I also found and posted the answer.

So basically the Spock manual mentions callRealMethod() only for spies, not for mocks or stubs. But oh - surprise, surprise - it works for all of them, which was rather unexpected for me.

Furthermore, the Javadoc for IMockInvocation says:

Delegates this method invocation to the real object underlying this mock object, replacing the original method arguments with the specified arguments. If this mock object has no underlying real object, a CannotInvokeRealMethodException is thrown.

Two problems here:

  1. The Javadoc is not found online in the API doc, so maybe the Javadoc was not created or uploaded correctly.
  2. The Javadoc does not explain what "underlying real object" is supposed to mean. Neither does the Spock manual.

I did find out what it means: An "underlying real object" is available whenever a non-interface type is mocked, stubbed or spied.

So my suggestion is:

  • Explain "underlying real object" in the Javadoc and make sure the Javadoc is generated and uploaded at all.
  • Mention in the Spock manual that callRealMethod() works for mocks, stubs and spied alike.
  • Mention in the Spock manual that callRealMethod() only works if the mocked object is not an interface type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment