Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.0, 3.0.7
-
None
-
None
Description
import groovy.mock.interceptor.MockFor class Helper { String string Helper() { string = internalMethod() } private String internalMethod() { return helperMethod() } String helperMethod() { return 'not intercepted' } } MockFor mock = new MockFor(Helper) mock.demand.helperMethod { -> 'intercepted' } mock.ignore('getString') mock.use { def helper = new Helper() assert helper.string == 'intercepted' }
method() is a public method, thus I expect it to respect mocking, even for internal calls. Let me know if this expectation is wrong.
With Groovy 2.4.21, the test works as expected. With Groovy 3.0.7, it fails:
Assertion failed: assert helper.string == 'stub' | | | | null false Helper@5c00384f at test$_run_closure2.doCall(test.groovy:17) at test$_run_closure2.doCall(test.groovy) at test.run(test.groovy:15)
Instead of either the original or mocked return value, we got null instead.
It looks like it works for call(), but not for callCurrent(). I think the issue is that MockProxyMetaClass overrides one signature of invokeMethod(), but not the one used by callCurrent(). Might 34ad466ba6a be a relevant change?