Given an method with a parameter in Java, e.g.
public class Foo {
public Bar theBar(Bar bar) { /*... */ }
}
When stubbing/ mocking foo, how do I tell it to accept any argument and return it? (Groovy)
def fooStub = Stub(Foo) {
theBar(/*what to pass here*/) >> { x -> x }
}
As you can see I passed the identity function. However I do not know what to pass as argument. _ does not work because it is an ArrayList and thus not of type Bar
@CompileStaticor@TypeCheckedon your spec? could you post your whole code, there is no reason why_shouldn't work. - Leonard Brüningsxinput before the arrow is actually the entire arguments list of the method call? Doing the following solves the problem:theBar(_) >> { args -> args.get(0) }. But why is that necessary? How to express this correctly without any hacks? - tiguchi