7

I want to spy the Linkedlist in android.

List list = new LinkedList();
List spyData = Mockito.spy(list);
spyData.add("xxxx");

However, the exception occured.

java.lang.AbstractMethodError: abstract method "boolean org.mockito.internal.invocation.AbstractAwareMethod.isAbstract()"
    at     org.mockito.internal.invocation.InvocationImpl.callRealMethod(InvocationImpl.java:109)
    at org.mockito.internal.stubbing.answers.CallsRealMethods.answer(CallsRealMethods.java:41)
    at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:93)
    at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
    at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:38)
    at com.google.dexmaker.mockito.InvocationHandlerAdapter.invoke(InvocationHandlerAdapter.java:49)
    at LinkedList_Proxy.add(LinkedList_Proxy.generated)
    at com.app.test.testmethod(mytest.java:202)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1858)

The dependencies of libs are

dexmaker-1.2.jar
dexmaker-mockito-1.2.jar
mockito-core-1.10.19.jar

Even I update mockito-core-1.10.19.jar to mockito-core-2.0.31-beta.jar,

the problem still exists.

But Mockito.mock(Linkedlist.class) is ok, I have no ideas about this problem.

Thank you.

alec.tu
  • 1,647
  • 2
  • 20
  • 41

2 Answers2

9

I just found another way to solve the problem.

This is an issue for dexmaker 1.2, we should upgrade to dexmaker 1.4, dexmaker-mockito 1.4 and include dexmaker-dx-1.4.

So the dependencies are

dexmaker-dx-1.4.jar
dexmaker-1.4.jar
dexmaker-mockito-1.4.jar
mockito-core-1.10.19.jar
alec.tu
  • 1,647
  • 2
  • 20
  • 41
7

May be a issue between mockito 1.10 and dexmaker 1.2, Can you try forcing mockito 1.9.5 and see if that fixes it?

http://code.google.com/p/dexmaker/issues/detail?id=43

Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
  • I got this problem after downgrade to mockito 1.9.5, http://stackoverflow.com/questions/28022219/java-lang-noclassdeffounderror-org-objenesis-objenesisstd-with-mockito – alec.tu Sep 23 '15 at 03:35
  • I try to upgrage to dexmaker-1.4 instead, then it can not find `com.android.dx.rop.type.Type` – alec.tu Sep 23 '15 at 03:49
  • 1
    Ok, I find another way to solve the problem, see the self-answer. – alec.tu Sep 23 '15 at 03:54
  • @alec-tu Make sure you add the dependency for dexmaker-dx upgrading to dexmaker 1.4 – Johnny C Sep 07 '16 at 16:36