I have an integration test. Some code from it:
Test1 {
static closure1 = { Class1 resultState, Class1 originState ->
with(resultState) {
name == originState.name
breed == originState.breed
bornDate == originState.bornDate
}
}
@Unroll
def 'exercise #methodName'() {
...
expected(resultState, originState)
...
methodName || expected
'name1' || closure1
}
}
I get an groovy.lang.MissingMethodException: No signature of method: Test1$__clinit__closure10.with() is applicable for argument types: (Class1, Test1$__clinit__closure10$_closure12) values: [//values].
But when I refactor my code to form with method instead of closure, everything is fine.
Test1 {
void method1(Class1 resultState, Class1 originState) {
with(resultState) {
name == originState.name
breed == originState.breed
bornDate == originState.bornDate
}
}
@Unroll
def 'exercise #methodName'() {
...
expected(resultState, originState)
...
methodName || expected
'name1' || closure1
}
}
But why?? In closure-from I'm getting the exception in with-block, not in closure call. In my other test form of test with closures (but without with-block) works fine. Type of closure here - Closure, in other test - Closure, if it's important.
What's wrong in my code??