keeganwitt / gmock

Automatically exported from code.google.com/p/gmock
6 stars 2 forks source link

WithGMock, Spock and GroovyPageUnitTestMixin StackOverflowError when mocking constructor #125

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

import org.gmock.WithGMock
import spock.lang.Specification
import spock.lang.Unroll
import grails.test.mixin.TestMixin
import grails.test.mixin.web.GroovyPageUnitTestMixin

@TestMixin(GroovyPageUnitTestMixin)
@WithGMock
class GMockSpec extends Specification {

    @Unroll({"gmock can mock out call to $filename constructor"})
    def 'gmock can mock out call to file constructor'() {
        given:
        mock(File, constructor(filename)) {
            getText().returns('some text')
        }

        when:
        File file

        then:
        play {
            file = new File(filename)
            assert 'some text' == file.text
        } || true

        where:
        filename << ['filea.txt', 'fileb.txt']
    }

}

What is the expected output? What do you see instead?
The second unroll throws a StackOverflowError.

What version of the product are you using? On what operating system?

grails 2.0.1
gmock 0.8.2
spock 0.6-SNAPSHOT
linux 3.0.6
java version "1.6.0_26"

Please provide any additional information below.

This fails with both blank constructors and constructors taking arguments.

Original issue reported on code.google.com by gus.j.po...@gmail.com on 18 Feb 2012 at 5:27

GoogleCodeExporter commented 8 years ago
I can confirm, that I have the same issue, where I create the mock in the def 
setup() methode. The first test methode works, but subsequently they fail with 
StackOverflowError here:
org.codehaus.groovy.util.AbstractConcurrentMap.getOrPut(AbstractConcurrentMap.ja
va:35)

Original comment by soe...@glasius.dk on 10 Apr 2012 at 1:11

GoogleCodeExporter commented 8 years ago
ok, I will check whether it is the problem of gmock or is of spock once I have 
time.

Original comment by JohnnyJianHY on 10 Apr 2012 at 1:15

GoogleCodeExporter commented 8 years ago
We have the same issue in our project as well, and we are not using Spock. We 
are running Grails 2.0.3 with GMock 0.8.2.

We found a dodgy work-around for this. If we add:

File.metaClass.constructor = { path -> new File(path) }

before calling the mock() with constructor, it seems to work most of the times.

Original comment by w...@vith.me on 12 Apr 2012 at 11:25

GoogleCodeExporter commented 8 years ago

Original comment by JohnnyJianHY on 14 Apr 2012 at 4:49

GoogleCodeExporter commented 8 years ago
A fix is uploaded on the trunk, please confirm that it works.

This is all because of the buggy MetaClassRegistryCleaner of Grails. It's 
really a mess, one fix brings more bugs. So I need to temporarily disable it 
while setting metaclasses.

Original comment by JohnnyJianHY on 1 May 2012 at 5:01

GoogleCodeExporter commented 8 years ago
I've built the latest from trunk and added it to my grails lib folder (and 
removed 0.8.2 from BuildConfig.groovy). I've also updated to grails 2.0.3.

Now my spec gives the following error:
1: A transform used a generics containing ClassNode groovy.lang.Closure <V 
extends java.lang.Object -> java.lang.Object> for the method protected 
java.lang.Object ordered(groovy.lang.Closure closure)  { ... } directly. You 
are not suppposed to do this. Please create a new ClassNode refering to the old 
ClassNode and use the new ClassNode instead of the old one. Otherwise the 
compiler will create wrong descriptors and a potential NullPointerException in 
TypeResolver in the OpenJDK. If this is not your own doing, please report this 
bug to the writer of the transform.

Original comment by gus.j.po...@gmail.com on 3 Jun 2012 at 3:11

GoogleCodeExporter commented 8 years ago
That bug of the transformation has been fixed before, please refer to issue 115.

I tried to checkout and build a snapshot of the latest trunk, create a new app 
using grails 2.0.4, and copy the built gmock jar into the app's lib folder. 
Then I write a simple unit test using the "@WithGMock" transformation, it works 
fine!

Maybe you should do "grails clean" on your app first?

Original comment by JohnnyJianHY on 30 Jun 2012 at 4:37

GoogleCodeExporter commented 8 years ago
Hi,

Just to let you know that I encountered this stackoverflow bug and with the 
snapshot from trunk everything is working fine.

I am using Grails 2.1.1, Spock 0.6 and of course GMock snapshot.

Regarding this bug as a critical one for me, could you please release the 0.8.3 
as an interim version before getting this to the 0.9? (Or is there any change 
to backport this fix into 0.8.2 and make the 0.8.3 release?)

Original comment by chanwit on 15 Nov 2012 at 3:39

GoogleCodeExporter commented 8 years ago

Original comment by JohnnyJianHY on 19 Feb 2013 at 11:47