android - java.lang.ExceptionInInitializerError - PowerMockito -


so trying use powermockito in place of mockito can mock class final. however, after switch on powermockito, following stacktrace when trying mock class:

java.lang.exceptionininitializererror @ org.powermock.api.mockito.repackaged.classimposterizer.createproxyclass(classimposterizer.java:95) @ org.powermock.api.mockito.repackaged.classimposterizer.imposterise(classimposterizer.java:57) @ org.powermock.api.mockito.internal.mockcreation.mockcreator.createmethodinvocationcontrol(mockcreator.java:111) @ org.powermock.api.mockito.internal.mockcreation.mockcreator.mock(mockcreator.java:59) @ org.powermock.api.mockito.powermockito.mock(powermockito.java:143) @ com.app.settingstests.setup(settingstests.java:64) @ java.lang.reflect.method.invoke(native method) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:50) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:47) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:24) @ org.junit.runners.parentrunner.runleaf(parentrunner.java:325) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:78) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:57) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.junit.runners.suite.runchild(suite.java:128) @ org.junit.runners.suite.runchild(suite.java:27) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.junit.runner.junitcore.run(junitcore.java:137) @ org.junit.runner.junitcore.run(junitcore.java:115) @ android.support.test.internal.runner.testexecutor.execute(testexecutor.java:59) @ android.support.test.runner.androidjunitrunner.onstart(androidjunitrunner.java:262) @ android.app.instrumentation$instrumentationthread.run(instrumentation.java:1932) caused by: org.mockito.cglib.core.codegenerationexception: java.lang.reflect.invocationtargetexception-->null @ org.mockito.cglib.core.abstractclassgenerator.create(abstractclassgenerator.java:238) @ org.mockito.cglib.core.keyfactory$generator.create(keyfactory.java:145) @ org.mockito.cglib.core.keyfactory.create(keyfactory.java:117) @ org.mockito.cglib.core.keyfactory.create(keyfactory.java:109) @ org.mockito.cglib.core.keyfactory.create(keyfactory.java:105) @ org.mockito.cglib.proxy.enhancer.<clinit>(enhancer.java:70) ... 33 more caused by: java.lang.reflect.invocationtargetexception @ java.lang.reflect.method.invoke(native method) @ org.mockito.cglib.core.reflectutils.defineclass(reflectutils.java:385) @ org.mockito.cglib.core.abstractclassgenerator.create(abstractclassgenerator.java:220) ... 38 more caused by: java.lang.unsupportedoperationexception: can't load type of class file @ java.lang.classloader.defineclass(classloader.java:594) ... 41 more 

and here setup method:

@runwith(androidjunit4.class) @preparefortest(settingsview.class) public class settingstests {    @mock private settingsview view;    @before   public void setup() {     view = mock(settingsview.class);   } 

does know potentially causing this? have tried change mock(settingsview.class) powermockito.mock(settingsview.class) same result.

also, view interface in scenario.

i think need @runwith(powermockrunner.class). example:

@runwith(powermockrunner.class) @preparefortest({settingsview.class}) public class powermockfinalclasstest {      private settingsview view;      @test     public void testmockingstatic() {         view = powermockito.mock(settingsview.class);          string expected = "mocked call";         mockito.when(view.getsomething()).thenreturn(expected);          assert.assertequals(expected, view.getsomething());     } } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -