keeganwitt / gmock

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

Error partially mocking a Grails Service injected into an Integration test. #114

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I getting an error trying to partially gmock a Grails Service injected into an 
integration test. 

eg. 

class TestService { 
  static transactional = true 

    def serviceMethod() { 
                "foo" 
    } 
} 

@WithGMock 
class TestTests extends GroovyTestCase { 

    TestService testService 

    protected void setUp() { 
        super.setUp() 
    } 

    protected void tearDown() { 
        super.tearDown() 
    } 

    void testSomething() { 
        def m = mock(testService) 

        m.serviceMethod().raises(new RuntimeException("bar")) 

        play { 
             shouldFail(RuntimeException) { 
                 testService.serviceMethod(); 
             } 
        } 
    } 
} 

I get the following error... 

No signature of method: java.lang.String.raises() is applicable for argument 
types: (java.lang.RuntimeException) values: [java.lang.RuntimeException: bar] 
Possible solutions: wait(), size(), readLines(), reverse(), wait(long), 
matches(java.lang.String) 
groovy.lang.MissingMethodException: No signature of method: 
java.lang.String.raises() is applicable for argument types: 
(java.lang.RuntimeException) values: [java.lang.RuntimeException: bar] 
Possible solutions: wait(), size(), readLines(), reverse(), wait(long), 
matches(java.lang.String) 
        at atest.TestTests.testSomething(TestTests.groovy:23) 

Tested with Grails 1.3.7 and gmock 0.8.0. 

Thank you.

Original issue reported on code.google.com by mm...@bellsouth.net on 9 Sep 2011 at 3:28

GoogleCodeExporter commented 8 years ago

Original comment by JohnnyJianHY on 9 Sep 2011 at 3:38

GoogleCodeExporter commented 8 years ago
It is because Grails mark the getMetaClass() method as final (I don't know why 
they do so). I have tested the fix on both Grails 1.3.7 and 2.0.

Original comment by JohnnyJianHY on 17 Dec 2011 at 6:50