Java – Android analog camera
Can I simulate the Android camera class?
@Override public void setUp() { _camera = Mockito.mock(Camera.class); }
Unable to generate impersonation (exceptioninitializererror in createproxyclass of mockito)
Should I create some wrappers around the camera (not my favorite solution, really want to laugh at this class...)?
Or should I use a different simulation library and then mockito?
I hope someone can point me in the right direction
Completes the stack trace for exceptioninitializererror
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.cleancode.lifesaver.flashlight.test.FlashLightTests.setUp(FlashLightTests.java:20) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661) Caused by: java.lang.VerifyError: org/mockito/cglib/core/ReflectUtils at org.mockito.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:167) at org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:217) 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) ... 18 more
Solution
In your stacktrace, notice the substring ". Cglibmockmaker": that's the problem Cglib is not suitable for Android – there is a mockito plug-in dedicated to Android, which uses dexmaker, just like cglib, but suitable for Dalvik Just search dexmaker mockito, you should be on the right path
You still can't simulate camera Open () (static factory method), but you can refactor your code around it Importantly, camera is not the last class; The rest is just a clumsy pipeline of testing, and you should accept the tax of writing well tested Android applications