Код: Выделить всё
whenever(this.strings).thenReturn(mock(StringProvider::class.java, StringProviderAnswer()))
Код: Выделить всё
class StringProviderAnswer : Answer {
private val delegate = Mockito.RETURNS_DEFAULTS!!
override fun answer(invocation: InvocationOnMock?): Any? {
val invocationMethodReturn = invocation?.method?.returnType
val stringType = String::class.java
return when (invocationMethodReturn) {
stringType -> invocation.method?.name.toString() + invocation.arguments.joinToString()
else -> delegate.answer(invocation)
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/729 ... with-mockk
Мобильная версия