keeganwitt / gmock

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

GMock + Clover #138

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Grails project with clover plugin
2. add the following example class "CloverTest" to that project's unit test:
<code>
import org.gmock.WithGMock
import org.junit.Test

@WithGMock
class CloverTest extends GroovyTestCase {

    @Test
    void withClover() {
        mock(Foo).static.neverCalled().never()

        play {
            new Bar().cloverTest()
        }
    }

    @Test
    void withClover2() {
        mock(Baz).static.neverCalled().never()

        play {
            new Bar().cloverTest()
        }
    }

    class Bar {
        void cloverTest() {
            new Foo().bar()
        }
    }

    class Baz extends Foo {

    }

    class Foo {
        void bar() {}

        static void neverCalled() {}
    }
}
</code>
3. run the grails target: test-app unit: CloverTest -clover.on

What is the expected output?
The test run should not fail because of
<pre>
java.lang.AssertionError: Unexpected static method call 'Foo.$CLV_R$()' 
</pre>

What do you see instead?
<pre>
--Output from withClover--
| Error --Output from withClover--
| Failure:  withClover(CloverTest)
|  java.lang.AssertionError: Unexpected static method call 'Foo.$CLV_R$()'
  'Foo.neverCalled()': expected never, actual 0
    at org.gmock.internal.InternalMockController.fail(InternalMockController.groovy:170)
    at org.gmock.internal.metaclass.MetaClassHelper.findExpectation(MetaClassHelper.groovy:25)
    at org.gmock.internal.metaclass.ClassProxyMetaClass$4.call(ClassProxyMetaClass.java:185)
    at org.gmock.internal.InternalMockController.doWork(InternalMockController.groovy:203)
    at org.gmock.internal.InternalMockController.doInternal(InternalMockController.groovy:192)
    at org.gmock.internal.InternalMockController.doInternal(InternalMockController.groovy:185)
    at org.gmock.internal.metaclass.ClassProxyMetaClass.checkAndDo(ClassProxyMetaClass.java:222)
    at org.gmock.internal.metaclass.ClassProxyMetaClass.invokeStaticMethod(ClassProxyMetaClass.java:177)
    at CloverTest$Bar.cloverTest(CloverTest.groovy:34)
    at CloverTest$_withClover_closure1.doCall(CloverTest.groovy:19)
    at org.gmock.internal.InternalMockController.play(InternalMockController.groovy:122)
    at org.gmock.GMockController.play(GMockController.groovy:29)
    at CloverTest.withClover(CloverTest.groovy:18)

Unexpected static method call 'Foo.$CLV_R$()'
  'Foo.neverCalled()': expected never, actual 0
java.lang.AssertionError: Unexpected static method call 'Foo.$CLV_R$()'
  'Foo.neverCalled()': expected never, actual 0
    at org.gmock.internal.InternalMockController.fail(InternalMockController.groovy:170)
    at org.gmock.internal.metaclass.MetaClassHelper.findExpectation(MetaClassHelper.groovy:25)
    at org.gmock.internal.metaclass.ClassProxyMetaClass$4.call(ClassProxyMetaClass.java:185)
    at org.gmock.internal.InternalMockController.doWork(InternalMockController.groovy:203)
    at org.gmock.internal.InternalMockController.doInternal(InternalMockController.groovy:192)
    at org.gmock.internal.InternalMockController.doInternal(InternalMockController.groovy:185)
    at org.gmock.internal.metaclass.ClassProxyMetaClass.checkAndDo(ClassProxyMetaClass.java:222)
    at org.gmock.internal.metaclass.ClassProxyMetaClass.invokeStaticMethod(ClassProxyMetaClass.java:177)
    at CloverTest$Bar.cloverTest(CloverTest.groovy:34)
    at CloverTest$_withClover_closure1.doCall(CloverTest.groovy:19)
    at org.gmock.internal.InternalMockController.play(InternalMockController.groovy:122)
    at org.gmock.GMockController.play(GMockController.groovy:29)
    at job.CloverTest.withClover(CloverTest.groovy:18)
</pre>

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

Please provide any additional information below.

Original issue reported on code.google.com by Patrick....@gmail.com on 3 Sep 2013 at 5:53

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 4 Sep 2013 at 1:27

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
After looking into the code a bit, changing the condition for the call to 
ClassProxyMetaClass.checkAndDo at ClassProxyMetaClass.invokeStaticMethod might 
be sufficient enough to fix that issue.

Something like: staticExpectationsEmpty || isCloverMethod(method)

where "isCloverMethod" could check for "$CLV_R$" as the method name.

PS: The cleanup was not complete: job.CloverTest should be just CloverTest. 
Also at the "withClover2" test I just tried, if it makes any difference, if I 
use a superclass (but as expected there was none) -  you can ignore that one 
also.

Original comment by Patrick....@gmail.com on 9 Sep 2013 at 2:55