Closed rosincc closed 1 year ago
@hellsof the interaction needs to be added to the then block. Otherwise you are still executing the method and shifting it. Same goes for non static methods.
There is no such problem after trying the non-static method, can you give a correct sample code, thanks.
@hellsof I didn't get the problem you were talking about. But now I understand. You are absolutely right there is a bug in the interception code.
Yes, an exception should not be thrown here, but it is thrown when it is actually executed, causing the above test case to pass the test.
Perhaps the following example can better demonstrate this problem:
final class Static {
public static void tVoid(List<String> list) {
list.add("old");
}
}
class StaticTest extends Specification {
def 'tVoid'() {
given:
Spy(Static)
List<String> param = new ArrayList<>()
when:
Static.tVoid(param)
then:
1 * Static.tVoid(_) >> {ArrayList<String> list ->
list << "mock"
}
expect:
param == ["mock"] // Condition not satisfied: param=["mock", "old"]
}
@hellsof The problem should be fixed now. Thanks for reporting the problem
The following example will pass the test: