Shadowing Kotlin extension functions example - robolectric/robolectric GitHub Wiki

To shadow Kotlin based extension function of a class, you need to check the decompiled Java code of your Kotlin extension class to exactly get the signature of the method correct. For example, I created a blur() extension function to Android's Bitmap class and named that class BitmapExt and Kotlin file looked like, BitmapExt.kt.

The method signature in Kotlin looked of the format :

fun Bitmap.blur(context: Context, radius: Float): Bitmap? {
 ...
 //some manipulation code
 ...
 return someManipulatedBitmap
}

Corresponding Shadow class looked like:

@Implements(BitmapExt.class)
public class ShadowedBitmapExt {

    public void __constructor__() {}

    @Implementation
    public static final Bitmap blur(Bitmap bitmap, Context context, float radius) {
        return Mockito.mock(Bitmap.class);
    }
}

Note: This is not the Shadow of Bitmap but of extension class.

Hope this helps, cheers!