Created
October 28, 2017 18:34
-
-
Save yayaa/e33cc16c7fd8c73b800c86e1705549c5 to your computer and use it in GitHub Desktop.
How to Test Builder - 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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