[jira] [Commented] (GROOVY-9188) Partial mocking static method calls with Ignore & Demand don't work as expected.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-9188) Partial mocking static method calls with Ignore & Demand don't work as expected.

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/GROOVY-9188?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16883405#comment-16883405 ]

Paul King commented on GROOVY-9188:
-----------------------------------

added {{code}} tags

> Partial mocking static method calls with Ignore & Demand don't work as expected.
> --------------------------------------------------------------------------------
>
>                 Key: GROOVY-9188
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9188
>             Project: Groovy
>          Issue Type: Bug
>          Components: mocks and stubs
>    Affects Versions: 2.5.7
>            Reporter: Bryan Stopp
>            Priority: Major
>
> When defining a mockFor on a class with static methods, if you _ignore_ a method which invokes a _demand_ mocked method. The _demand_ is not intercepted.
> Here is an example modified from the MockFor documentation:
>  
> {code}
> import groovy.mock.interceptor.MockFor
> class Person {
>   static def ignoreMe(foo) { foo }
>   static def ignoreMeToo() { ignoreMe('foo') }
>   static def ignoreMeThree() { ignoreMe('foo') }
> }
> def mock = new MockFor(Person)
> mock.ignore('ignoreMeToo')
> mock.ignore('ignoreMeThree')
> mock.demand.ignoreMe { s -> 'baz' }
> mock.use {
>   assert Person.ignoreMe('foo') == 'baz'
>   assert Person.ignoreMeToo() == 'baz'
>   assert Person.ignoreMeThree() == 'baz'
> }
> {code}
>  
> Running this will result in a failure as {{Person.ignoreMeToo()}} returns `foo` instead of `baz`.
> Use Case: Mocking nested static method calls. I want to test a particular method. I know/expect that method to invoke another static method on the same class, but I want to mock that one, and return an expected value.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)