Groovy Closure - Generated Classes/Methods

25 views
Skip to first unread message

anuma...@gmail.com

unread,
Feb 12, 2020, 1:13:53 AM2/12/20
to JaCoCo and EclEmma Users

I am working with Groovy 2.5.9, Gradle 6 and Spock Test Framework. 

As per Design Groovy closures are generating Closure classes and some internal getter methods.  Is it posssible to eliminate the generated methods in these Closure classes ? 

Some of Groovy generated methods are excluded as per Wiki page https://github.com/jacoco/jacoco/wiki/FilteringOptions#groovy

Does Closures covered in these filtering options ? If not, will it be possible enhance these in Jacoco ?

Build.gradle
============

plugins {

      id 'groovy'

    id 'jacoco'

}


repositories {

    jcenter()

}


dependencies {

 

       implementation 'org.codehaus.groovy:groovy:2.5.9'

      implementation 'org.codehaus.groovy:groovy-json:2.5.9'

    // Use JUnit test framework

   testImplementation 'junit:junit:4.12'

        testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'

     

}


jacocoTestReport {

     

       reports {

              xml.enabled false

              csv.enabled false

              html.destination file("${reportsDir}/jacoco")

  }

}

============= Main class ====

import java.util.concurrent.CompletableFuture


public class GroovyClosureMain {

       

       def String method1(def name) {

         

               def name1 = 'Hello ' + name

            def text =  ' - Closure Test'

           

              CompletableFuture<Object> future = callAsync(name1, text)

             

                return future.get()

    }

     

        def CompletableFuture<Object> callAsync(arg1, arg2) {

          return CompletableFuture.supplyAsync({ return arg1 + ' ' + arg2  })

           

        }

       

}

=============

Test Class

import spock.lang.Specification


class GroovyClosureTest extends Specification{


        def "Test Closure1" () {

               setup:

         GroovyClosureMain mainCls =  new GroovyClosureMain()

           String name = "Name"

           

               when:

          String response = mainCls.method1(name)


                then:

          assert response != null

}

     

         

}




Message has been deleted

anuma...@gmail.com

unread,
Feb 12, 2020, 1:15:46 AM2/12/20
to JaCoCo and EclEmma Users

Jacoco.png

Evgeny Mandrikov

unread,
Feb 12, 2020, 9:31:07 PM2/12/20
to JaCoCo and EclEmma Users
Hi,

In the future please avoid cross-posting.
Following issue should be fixed on Groovy side - https://issues.apache.org/jira/browse/GROOVY-9396


Regards,
Evgeny

Reply all
Reply to author
Forward
0 new messages