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 2020/01/26 23:59:00 UTC
[jira] [Updated] (GROOVY-9353) Metaclass constructor overriding not
working for a method inside of @CompileStatic annotated class
[ https://issues.apache.org/jira/browse/GROOVY-9353?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King updated GROOVY-9353:
------------------------------
Fix Version/s: (was: 2.4.10)
> Metaclass constructor overriding not working for a method inside of @CompileStatic annotated class
> --------------------------------------------------------------------------------------------------
>
> Key: GROOVY-9353
> URL: https://issues.apache.org/jira/browse/GROOVY-9353
> Project: Groovy
> Issue Type: Bug
> Components: groovy-jdk
> Affects Versions: 2.4.10
> Environment: ```
> ------------------------------------------------------------
> Gradle 3.5
> ------------------------------------------------------------
> Groovy: 2.4.10,
> Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015,
> JVM: 1.8.0_221 (Oracle Corporation 25.221-b11),
> OS: Mac OS X 10.15.2 x86_64
> ```
> Reporter: Viplav Soni
> Priority: Major
> Labels: metaClass, metaprogramming
>
> When we use `{{someClass.metaClass.constructor}} for any specific class (like [{{RESTClient}}|https://github.com/jgritman/httpbuilder/wiki/RESTClient]) available inside the method of a class which is annotated with {{@CompileStatic}}, constructor overriding is not working at all.
> When we removed the {{`@CompileStatic`}} annotation, this works properly. Am I missing something?
>
> Sample Code:
>
> ```
> {{@CompileStatic}}
> {{class FooClass {}}
> {{ }}{{String getDataFromProvider() {}}
> {{ String url = "https://www.example.com"}}
> RESTClient restClient = new RESTClient(url)
> HttpResponseDecorator response = restClient.post([:]) {{as HttpResponseDecorator }}
> {{ return response}}
> }
> {{}}}
> ```
> And the test case:
> ```
>
> {{import groovyx.net.http.HttpResponseDecorator}}
> {{import groovyx.net.http.RESTClient}}
> {{import spock.lang.Specification}}
> {{class FooContentSpec extends Specification {}}
> {{ void "test getDataFromProvider method"() {}}
> {{ given: "Rest url"}}
> {{ String restURL = "https://www.example.com"}}
> {{ and: "Mock RESTClient"}}
> {{ RESTClient mockedRestClient = Mock(RESTClient)}}
> {{ // THIS IS NOT WORKING}}
> {{ RESTClient.metaClass.constructor = { Object url ->}}
> {{ assert restURL == url}}
> {{ return mockedRestClient}}
> }
> {{ mockedRestClient.metaClass.post = { Map<String, ?> args -> return ""}}
> {{ }}}
> {{ when: "We hit the method"}}
> {{ HttpResponseDecorator response = Content.getDataFromProvider()}}
> then: "We should get status 200"
> {{ response.statusCode==200}}
> {{ }}}
> {{}}}
> ```
--
This message was sent by Atlassian Jira
(v8.3.4#803005)