mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-02-05 04:32:12 -05:00
Get around silly `final` methods in `ContentResolver` with Mockito and `delegatesTo`. The Robolectric library presumes that people always want to test content providers by manually invoking the `query`/`update`/`delete` methods on the `ShadowContentResolver`. While that is a great feature for testing, we have helper methods that require testing, and these methods accept either a _real_ `ContentResolver` or `Context`. Robolectric did some cool magic in terms of intercepting runtime calls to content resolvers and forwarding them to the "shadow" verison, to deal with final/package private/etc methods. However, as a side effect, the `ShadowContentProvider` _is not a `ContentProvider` as far as the Java compiler is concerned. By utilising Mockito + `delegatesTo` method, we are able to achieve what is required: * An actual `ContentProvider` instance. * It forwards calls to the `ShadowContentProvider` provided by Robolectric.