You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2021/04/25 03:34:00 UTC

[jira] [Updated] (GROOVY-9932) MockFor/StubFor makes mocked internal method return null

     [ https://issues.apache.org/jira/browse/GROOVY-9932?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King updated GROOVY-9932:
------------------------------
    Affects Version/s: 2.5.0

> MockFor/StubFor makes mocked internal method return null
> --------------------------------------------------------
>
>                 Key: GROOVY-9932
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9932
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.0, 3.0.7
>            Reporter: Ryan Tandy
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 3.0.8, 4.0.0-alpha-3
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> {code:groovy}
> 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'
> }
> {code}
> {{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:
> {noformat}
> 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)
> {noformat}
> 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|https://github.com/apache/groovy/commit/34ad466ba6a] be a relevant change?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)