Consider:
void testToStringWithGString() {
def m1 = mock()
m1.toString().returns("mock")
def m2 = mock()
m2.method("mock").returns(1)
play {
assertEquals 1, m2.method("$m1")
}
}
If fails with:
junit.framework.AssertionFailedError: Unexpected method call 'method(Mock
for Object (1))' on 'Mock for Object (2)'
'toString()' on 'Mock for Object (1)': expected 1, actual 0
'method("mock")' on 'Mock for Object (2)': expected 1, actual 0
It is due to that the internal mode assumes the parameters are evaluated
before the method is called, but GString ("$m1") is lazy evaluated, which
means "m1.toString()" will be invoked in internal mode, so the default
behavior will be invoked.
The solution is simple: when the method is called, iterate its parameters,
if some parameter is GString, evaluate it in external mode.
Original issue reported on code.google.com by JohnnyJianHY on 29 May 2009 at 5:03
Original issue reported on code.google.com by
JohnnyJianHY
on 29 May 2009 at 5:03