Skip to content

Instantly share code, notes, and snippets.

@dmcg
Created April 3, 2022 09:13
Show Gist options
  • Save dmcg/d5631bf86f5d7025b9872f323e25b52a to your computer and use it in GitHub Desktop.
Save dmcg/d5631bf86f5d7025b9872f323e25b52a to your computer and use it in GitHub Desktop.
import java.lang.reflect.Proxy
inline fun <reified T> fake(): T =
Proxy.newProxyInstance(
T::class.java.classLoader,
arrayOf(T::class.java)
) { _, _, _ ->
TODO("not implemented")
} as T
val sentEmails = mutableListOf<Email>()
val testCollaborator: EmailSystem =
object : EmailSystem by fake() {
override fun send(email: Email) {
sentEmails.add(email)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment