tmurakami/dexopener

Mocking final methods in Android platform classes

pushbit opened this issue · 2 comments

Am I correct in understanding that only final classes and methods that are created in our projects can be mocked with this library? I am trying to mock Activity.getApplication(), which is final and isn't normally possible with mockito-android, and it seems that this library isn't able to help there either. I think this limitation is described in the README, "Mockable final classes and methods are restricted under the package of the app's BuildConfig", but that wasn't initially clear to me.

Perhaps this limitation could be clarified in the library's main description. When I read, "A library that provides the ability to mock final classes and methods on Android", I thought it meant any final class or method anywhere (from the platform, a library, etc.).

Am I correct in understanding that only final classes and methods that are created in our projects can be mocked with this library?

You are mostly correct.
If your BuildConfig is named a.b.c.BuildConfig, you can mock only the final classes whose package name is a.b.c.**, such as a.b.c.YourClass, a.b.c.d.YourClass, etc.
It is not possible to mock the final class whose package name is not a.b.c.** even if it is what you made.

Perhaps this limitation could be clarified in the library's main description.

Thank you.
Someday I'll fix the document.

Thanks for the confirmation.