Groovy appears to be messing up my stubbing. The following test passes:
MockitoStubTest2.java:
public class MockitoStubTest2 {
@Test
public void testStubbing() {
MyInterface myInterface = mock(MyInterface.class);
when(myInterface.someMethod(isA(MyClass.class))).thenReturn("foobar");
assertEquals("foobar", myInterface.someMethod(new MyClass()));
}
private interface MyInterface {
String someMethod(MyClass arg);
String someMethod(String arg);
}
private static class MyClass {}
}
However, this one fails with groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method ...#someMethod
:
MockitoStubTest3.groovy:
public class MockitoStubTest3 {
@Test
public void testStubbing() {
MyInterface myInterface = mock(MyInterface.class);
when(myInterface.someMethod(isA(MyClass.class))).thenReturn("foobar");
assertEquals("foobar", myInterface.someMethod(new MyClass()));
}
private interface MyInterface {
String someMethod(MyClass arg);
String someMethod(String arg);
}
private static class MyClass {}
}
The only difference is that one is run with Java and the other with Groovy.
How can I make it so Mockito will successfully stub an overloaded method in Groovy? This is a trivial example but I have an actual use case I need to test.