Incompatible type for getting or setting field

756 views
Skip to first unread message

Alex Anderson

unread,
Sep 26, 2012, 8:22:17 AM9/26/12
to spockfr...@googlegroups.com
Is there something obviously wrong with the following:

41 static Exchange mockExchange(body, Map headers) {
42 Exchange x = Mock()
43 def out = Mock(Message)
44 if(body) out.body >> body
45 out.headers >> headers
46 x.out >> out
47 return x
48 }


Gives the following exception:

| Error Error executing script TestApp: (class:
frontlinesms2/WebConnectionServiceSpec, method: mockExchange
signature: (Ljava/lang/Object;Ljava/util/Map;)Lorg/apache/camel/Exchange;)
Incompatible type for getting or setting field (NOTE: Stack trace has
been filtered. Use --verbose to see entire trace.)
java.lang.VerifyError: (class: frontlinesms2/WebConnectionServiceSpec,
method: mockExchange signature:
(Ljava/lang/Object;Ljava/util/Map;)Lorg/apache/camel/Exchange;)
Incompatible type for getting or setting field
at org.spockframework.runtime.SpecUtil.getFeatureCount(SpecUtil.java:85)
at org.spockframework.runtime.SpecUtil$getFeatureCount.call(Unknown Source)
at grails.plugin.spock.test.GrailsSpecTestType$_doPrepare_closure2.doCall(GrailsSpecTestType.groovy:61)
at grails.plugin.spock.test.GrailsSpecTestType.doPrepare(GrailsSpecTestType.groovy:61)
at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:282)
at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy)
at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:248)
at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:195)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:184)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at TestApp$_run_closure1.doCall(TestApp.groovy:82)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:591)
at gant.Gant.executeTargets(Gant.groovy:590)

Removing `static` seems to fix it...

Peter Niederwieser

unread,
Sep 26, 2012, 10:53:27 AM9/26/12
to spockfr...@googlegroups.com
Mocks can't be used in static context. Not nice that it gives a VerifyError, though. Mind to file an issue?

Cheers,
Peter
> --
> You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
> To post to this group, send email to spockfr...@googlegroups.com.
> To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.
>

Alex Anderson

unread,
Oct 1, 2012, 8:29:27 AM10/1/12
to spockfr...@googlegroups.com
On 26 September 2012 17:53, Peter Niederwieser <pnie...@gmail.com> wrote:
> Mocks can't be used in static context. Not nice that it gives a VerifyError, though. Mind to file an issue?

Done: https://code.google.com/p/spock/issues/detail?id=270

And thanks for the clarification :¬)
Reply all
Reply to author
Forward
0 new messages