gpt4 book ai didi

android - 通过 Dagger Provide 模拟 AccountManager 时出现 Java.lang.reflect.InvocationTargetException。怎么修?

转载 作者:行者123 更新时间:2023-11-29 19:14:39 25 4
gpt4 key购买 nike

在我的 Dagger 中,我想提供一个模拟客户经理

@Provides
@Singleton
AccountManager provideAccountManager(Context context) {
return Mockito.mock(AccountManager.class);
}

我在运行 Mockito.mock(AccountManager.class) 时出现以下崩溃,如下所示

    java.lang.ExceptionInInitializerError
at org.mockito.internal.creation.jmock.ClassImposterizer.createProxyClass(ClassImposterizer.java:85)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:62)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:56)
at org.mockito.internal.creation.CglibMockMaker.createMock(CglibMockMaker.java:23)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)
at org.mockito.Mockito.mock(Mockito.java:1243)
at org.mockito.Mockito.mock(Mockito.java:1120)
at com.mypackage.app.test.TestAndroidServicesModule.provideAccountManager(TestAndroidServicesModule.java:118)
at com.mypackage.app.test.TestAndroidServicesModule_ProvideAccountManagerFactory.get(TestAndroidServicesModule_ProvideAccountManagerFactory.java:31)
at com.mypackage.app.test.TestAndroidServicesModule_ProvideAccountManagerFactory.get(TestAndroidServicesModule_ProvideAccountManagerFactory.java:10)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at au.com.mypackage.utils.AccountUtil_Factory.get(AccountUtil_Factory.java:71)
at au.com.mypackage.utils.AccountUtil_Factory.get(AccountUtil_Factory.java:13)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at au.com.mypackage.utils.ShortcutUtil_Factory.get(ShortcutUtil_Factory.java:41)
at au.com.mypackage.utils.ShortcutUtil_Factory.get(ShortcutUtil_Factory.java:9)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at au.com.mypackage.app.ui.main.MainActivity_MembersInjector.injectMembers(MainActivity_MembersInjector.java:76)
at au.com.mypackage.app.ui.main.MainActivity_MembersInjector.injectMembers(MainActivity_MembersInjector.java:13)
at com.mypackage.app.test.DaggerResiTestComponent.inject(DaggerResiTestComponent.java:1814)
at au.com.mypackage.app.ui.main.MainActivity.onCreate(MainActivity.java:113)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:532)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: org.mockito.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:238)
at org.mockito.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:117)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:109)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:105)
at org.mockito.cglib.proxy.Enhancer.<clinit>(Enhancer.java:70)
... 35 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at org.mockito.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:385)
at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:220)
... 40 more
Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
at java.lang.ClassLoader.defineClass(ClassLoader.java:594)
... 43 more

Test running failed: Instrumentation run failed due to 'Process crashed.'

我错过了什么吗?

最佳答案

根据 David Rawson 的评论,我更改了我的依赖项

androidTestCompile 'org.mockito:mockito-all:1.9.5'

androidTestCompile 'org.mockito:mockito-android:2.7.22'

这解决了问题!

关于android - 通过 Dagger Provide 模拟 AccountManager 时出现 Java.lang.reflect.InvocationTargetException。怎么修?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44038731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com