linkedin / linkedin/dexmaker

Mock fail when use dexmaker-mockito-inline instead of dexmaker-mockito

Open
#171 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
2k
Forks
262
PR merge metrics
No merged PRs in 30d

Description

I can mock "com.android.bluetooth.btservice.AdapterService" when i include "dexmaker-mockito"

But I want to mock final class (android.bluetooth.BluetoothDevice),
so i changed "dexmaker-mockito" to "dexmaker-mockito-inline".

Then runtime error is occurred like below.

09-09 14:18:59.808 E 16288 16310 MockMakerMultiplexer: Could not init mockmaker com.android.dx.mockito.inline.InlineStaticMockMaker
09-09 14:19:00.405 E 16288 16310 TestRunner: failed: test_final_mock(com.android.bluetooth.hfp.HeadsetAudioManagerTest)
09-09 14:19:00.405 E 16288 16310 TestRunner: ----- begin exception -----
09-09 14:19:00.405 E 16288 16310 TestRunner: org.objenesis.ObjenesisException: java.lang.UnsatisfiedLinkError: No implementation found for void com.android.bluetooth.btservice.AdapterService.classInitNative() (tried Java_com_android_bluetooth_btservice_AdapterService_classInitNative and Java_com_android_bluetooth_btservice_AdapterService_classInitNative__)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.objenesis.instantiator.sun.UnsafeFactoryInstantiator.newInstance(UnsafeFactoryInstantiator.java:76)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:73)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.mockito.internal.creation.instance.ObjenesisInstantiator.newInstance(ObjenesisInstantiator.java:19)
09-09 14:19:00.405 E 16288 16310 TestRunner: at com.android.dx.mockito.inline.InlineDexmakerMockMaker.createMock(InlineDexmakerMockMaker.java:306)
09-09 14:19:00.405 E 16288 16310 TestRunner: at com.android.dx.mockito.inline.MockMakerMultiplexer.createMock(MockMakerMultiplexer.java:65)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.mockito.internal.MockitoCore.mock(MockitoCore.java:69)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.mockito.Mockito.mock(Mockito.java:1905)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.mockito.Mockito.mock(Mockito.java:1814)
09-09 14:19:00.405 E 16288 16310 TestRunner: at com.android.bluetooth.hfp.HeadsetAudioManagerTest.test_final_mock(HeadsetAudioManagerTest.java:44)
09-09 14:19:00.405 E 16288 16310 TestRunner: at java.lang.reflect.Method.invoke(Native Method)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:52)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
09-09 14:19:00.405 E 16288 16310 TestRunner: at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
09-09 14:19:00.405 E 16288 16310 TestRunner: at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
09-09 14:19:00.405 E 16288 16310 TestRunner: at androidx.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:104)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.Suite.runChild(Suite.java:128)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.Suite.runChild(Suite.java:27)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
09-09 14:19:00.405 E 16288 16310 TestRunner: at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
09-09 14:19:00.405 E 16288 16310 TestRunner: at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
09-09 14:19:00.405 E 16288 16310 TestRunner: at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2218)
09-09 14:19:00.405 E 16288 16310 TestRunner: Caused by: java.lang.UnsatisfiedLinkError: No implementation found for void com.android.bluetooth.btservice.AdapterService.classInitNative() (tried Java_com_android_bluetooth_btservice_AdapterService_classInitNative and Java_com_android_bluetooth_btservice_AdapterService_classInitNative__)
09-09 14:19:00.405 E 16288 16310 TestRunner: at com.android.bluetooth.btservice.AdapterService.classInitNative(Native Method)
09-09 14:19:00.405 E 16288 16310 TestRunner: at com.android.bluetooth.btservice.AdapterService.(AdapterService.java:347)
09-09 14:19:00.405 E 16288 16310 TestRunner: at sun.misc.Unsafe.allocateInstance(Native Method)
09-09 14:19:00.405 E 16288 16310 TestRunner: at java.lang.reflect.Method.invoke(Native Method)
09-09 14:19:00.405 E 16288 16310 TestRunner: at org.objenesis.instantiator.sun.UnsafeFactoryInstantiator.newInstance(UnsafeFactoryInstantiator.java:74)
09-09 14:19:00.405 E 16288 16310 TestRunner: ... 39 more
09-09 14:19:00.406 E 16288 16310 TestRunner: ----- end exception -----

AdapterService class code is below.

package com.android.bluetooth.btservice;

public class AdapterService extends Service {
...

static {
classInitNative();
}

...

static native void classInitNative();

...
}

I can't understand why "dexmaker-mockito" has no problem, but "dexmaker-mockito-inline" has upper problem.
There is some difference about mocking native method?

Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the failing call at com.android.bluetooth.hfp.HeadsetAudioManagerTest.java:44 and trace InlineDexmakerMockMaker.createMock through MockMakerMultiplexer. Compare the inline path with the regular dexmaker-mockito path, focusing on AdapterService's static classInitNative() initializer. Done means the reported final-class mock no longer fails with UnsatisfiedLinkError, or the incompatibility is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.