Mockito spy methods recursively call themselves

784 views
Skip to first unread message

kgal...@gmail.com

unread,
Jul 24, 2016, 11:51:42 PM7/24/16
to j2objc-discuss
Mockito calls when you spy on an object seem to call themselves recursively (I assume the eventual crash is a stack overflow).

InvocationHandlerAdapter says the ios implementation is based on https://github.com/crittercism/dexmaker

Comparing these two:

https://github.com/crittercism/dexmaker/blob/master/mockito/src/main/java/com/android/dx/mockito/InvocationHandlerAdapter.java#L94

https://github.com/google/j2objc/blob/master/testing/mockito/src/main/java/org/mockito/internal/creation/ios/InvocationHandlerAdapter.java#L91

It looks like dexmaker creates a parallel set of methods and routes calls through 'ProxyBuilder.callSuper'. The j2objc version seems to simply call the method provided, which seems to result in the recursion.

I'm still pretty light on objc proxied classes, so if spy should work and this is just a bug, I'll file something with a simple example.

Figured I'd ask before I get any deeper into the rabbit hole.

kgal...@gmail.com

unread,
Jul 24, 2016, 11:56:56 PM7/24/16
to j2objc-discuss, kgal...@gmail.com
BTW, simple example. The mocked instance works ok, the spy one will recurse and eventually crash.

public class CheckMockTest
{
@Test public void mockingTypes() {
CheckMock mockMock = mock(CheckMock.class);
mockMock.writeThings();
CheckMock spyMock = spy(new CheckMock());
spyMock.writeThings();
}

public static class CheckMock
{
public void writeThings()
{
System.out.println("Hello");
}
}
}

Reply all
Reply to author
Forward
0 new messages