I have the following code:
def method() {
try {
dependency0.call({ arg -> })
} catch {
dependency1.call()
}
}
and the following test:
@Test
void shouldDoSomething(
@Mocked final Dependency0 dependency0Mock) {
final dependency1Mock = getDependency1Mock()
new Expectations() {{
dependency0Mock.call((Closure) any)
result = new Exception('expected')
final sut = new Sut(dependency1Mock, dependency0Mock)
sut.method()
}
When the test runs, it emits the following exception:
mockit.internal.UnexpectedInvocation: Parameter "arg" of Dependency0#call(groovy.lang.Closure arg) expected null, got Sut$_method_closure1@cafebead
How do I go about mocking a method that takes in a Groovy Closure?
UPDATE: The same exception is thrown even if the argument type is Integer
.