kotlin-testrunner icon indicating copy to clipboard operation
kotlin-testrunner copied to clipboard

mockito non-final classes error

Open zdevwu opened this issue 7 years ago • 6 comments

Mockito still complains about kotlin classes even if I opens up the whole package.

I trace the code to NoMoreFinalsClassLoader.process, for the same className when the first time this method is called it does go into removeFinal, and it runs fine. however, when the second time this method is called with the same className, because the final is removed, it goes to defaultClass.toClass(this) as Class<T>

Then in bytebuddy invoked by Mockito this gets thrown: javassist.CannotCompileException: by java.lang.LinkageError: loader (instance of de/jodamob/kotlin/testrunner/NoMoreFinalsClassLoader): attempted duplicate class definition for name: "my/className"

In the NoMoreFinalsClassLoader, should loaded classes be cached?

zdevwu avatar Mar 09 '17 11:03 zdevwu

Having the same problem.

tasomaniac avatar Aug 31 '17 22:08 tasomaniac

@tasomaniac mockito can mock final classes now, see this

zdevwu avatar Sep 03 '17 13:09 zdevwu

I've been struggling with that a lot recently. We have PowerMockito in our project and right now it is impossible to remove it. Unfortunately we couldn't make mockito Inline mock maker to work when we have PowerMockito in place. It actually works in some Java sdks in command line. Never worked with Android Studio.

tasomaniac avatar Sep 03 '17 14:09 tasomaniac

you can try my commit to see if it works with your project?

zdevwu avatar Sep 03 '17 15:09 zdevwu

I saw that but I didn't have time to check it out and build it myself. Do you have a jar or maven coordinates? Then it would be super easy to try :) Thanks.

tasomaniac avatar Sep 03 '17 15:09 tasomaniac

there you go

zdevwu avatar Sep 03 '17 16:09 zdevwu