Skip to content

Instantly share code, notes, and snippets.

@yayaa
Created October 28, 2017 18:34
Show Gist options
  • Save yayaa/e33cc16c7fd8c73b800c86e1705549c5 to your computer and use it in GitHub Desktop.
Save yayaa/e33cc16c7fd8c73b800c86e1705549c5 to your computer and use it in GitHub Desktop.
How to Test Builder - 4
class AnswerWithPairList(private val clazz: Class<*>, private val pairs: List<Pair<Class<*>, *>>) : Answer<Any> {
private val delegate = ReturnsEmptyValues()
@Throws(Throwable::class)
override fun answer(invocation: InvocationOnMock): Any = invocation.apply {
val returnType = method.returnType
return if (returnType == clazz) mock
else pairs.find { returnType == it.first }?.second ?: delegate.answer(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment