dpreussler / kotlin-testrunner

JUnit4Testrunner that removes final from classes and methods, especially needed in kotlin projects
113 stars 8 forks source link

mockito non-final classes error #19

Open zdevwu opened 7 years ago

zdevwu commented 7 years ago

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?

tasomaniac commented 7 years ago

Having the same problem.

zdevwu commented 7 years ago

@tasomaniac mockito can mock final classes now, see this

tasomaniac commented 7 years ago

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.

zdevwu commented 7 years ago

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

tasomaniac commented 7 years ago

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.

zdevwu commented 7 years ago

there you go