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

Andres Almiray updated GROOVY-7320:
-----------------------------------
    Affects Version/s: 3.0.4

> Stubbing static methods don't work on instaces
> ----------------------------------------------
>
>                 Key: GROOVY-7320
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7320
>             Project: Groovy
>          Issue Type: Bug
>          Components: mocks and stubs
>    Affects Versions: 2.4.1, 2.5.0-beta-1, 3.0.4
>         Environment: Winows 8.1, JDK 1.8
>            Reporter: Markus Geiss
>            Priority: Minor
>              Labels: mock
>         Attachments: StaticStubFails.groovy
>
>
> When replaced static method is called from an instance of a class, it still 
> hits original method. Here is code example that fails:
> {code:title=StaticStubFails.java}
> class Foo {
>   static String greet() {
>     'Hello from Foo'
>    }
> }
> foo = new Foo()
> assert 'Hello from Foo' == foo.greet()
> Foo.metaClass.static.greet = { 'Hello from Stub' }
> assert 'Hello from Stub' == Foo.greet()
> //uncomment line below and it will pass
> //foo.metaClass.static.greet = { 'Hello from Stub' }
> assert 'Hello from Stub' == foo.greet()
> println 'All ok'
> {code}
> {noformat:title=Output}
> assert 'Hello from Stub' == foo.greet()
>                          |  |   |
>                          |  |   Hello from Foo
>                          |  Foo@5e82df6a
>                          false
> {noformat}



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

Reply via email to