Can't mock FirebaseRemoteConfig using mockito-inline
See original GitHub issueThis occurs when using mockito 2.7.22, openjdk version “1.8.0_112-release”, and Mac OS 10.12.4
When using mockito-inline in unit test on an Android project it is unable to mock FirebaseRemoteConfig. When I try to call when(mockFirebaseRemoteConfig.getBoolean(“test_key”)).thenReturn(true) I get a null pointer exception in the actual FirebaseRemoteConfig code:
java.lang.NullPointerException at com.google.firebase.remoteconfig.FirebaseRemoteConfig.getBoolean(Unknown Source) at com.google.firebase.remoteconfig.FirebaseRemoteConfig.getBoolean(Unknown Source) at com.example.solcott.mockfirebaseremoteconfig.ExampleUnitTest.addition_isCorrect(ExampleUnitTest.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:68) at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:74) at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39) at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:161) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
When I switch to using mockito-core it works fine. Also, when using mockito-inline and mockito-android together it also works.
Sample code that reproduces this is at https://github.com/solcott/MockFirebaseRemoteConfig
Run from the command line using ./gradlew testDebugUnitTest or from inside Android Studio.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
I believe I have a similar issue mocking
FirebaseAuth
. The funny thing is that disablingmock-maker-inline
makes everything work again.I filed a bug report at Proguard. I did some tests and this also breaks APM tools, for example.