Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wonder-jang opened this issue Sep 9, 2020 · 1 comment

Comments

@wonder-jang
Copy link

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.

@ryanholden8
Copy link

Yeah same question 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants