Skip to content

Instantly share code, notes, and snippets.

@rkam88
rkam88 / MockProxy.kt
Last active April 21, 2023 10:08
A Java dynamic proxy that calls either the real or mocked implementation of an interface
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.lang.reflect.InvocationHandler
import java.lang.reflect.InvocationTargetException
import java.lang.reflect.Method
import java.lang.reflect.Proxy
import kotlin.coroutines.Continuation
import kotlin.coroutines.cancellation.CancellationException