Почему я получаю java.lang.UnsupportedOperationException: переопределение класса не удалось: попытка добавить метод - PullRequest
0 голосов
/ 10 июля 2019

Добрый день.Я пишу юнит-тест с Mockk в Котлине.Мне нужно издеваться над классом Android 'SpannableString'

Вот мой код

private val spannableString = mockk<SpannableString>()
    @Before
    open fun setup() {
    every { spannableString.toString() } returns SPANNABLE_STRING_VALUE
    every { spannableStringWrapper.get() } returns spannableString
    every { suggestion.id } returns SUGGESTION_ID
    every { suggestion.label } returns "The Shard"
    every { customerSessionStorageProvider.guid } returns "guid"
}

Поэтому, когда я запускаю свой тестовый класс, я получаю:

java.lang.UnsupportedOperationException: class redefinition failed: attempted to add a method

at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
at io.mockk.proxy.jvm.transformation.InlineInstrumentation.doCancel(InlineInstrumentation.kt:60)
at io.mockk.proxy.jvm.transformation.InlineInstrumentation.access$doCancel(InlineInstrumentation.kt:9)
at io.mockk.proxy.jvm.transformation.InlineInstrumentation$execute$cancellation$1.invoke(InlineInstrumentation.kt:20)
at io.mockk.proxy.jvm.transformation.InlineInstrumentation$execute$cancellation$1.invoke(InlineInstrumentation.kt:9)
at io.mockk.proxy.jvm.transformation.InlineInstrumentation.execute(InlineInstrumentation.kt:43)
at io.mockk.proxy.jvm.ProxyMaker.inline(ProxyMaker.kt:88)
at io.mockk.proxy.jvm.ProxyMaker.proxy(ProxyMaker.kt:30)
at io.mockk.impl.instantiation.JvmMockFactory.newProxy(JvmMockFactory.kt:34)
at io.mockk.impl.instantiation.AbstractMockFactory.newProxy$default(AbstractMockFactory.kt:29)
at io.mockk.impl.instantiation.AbstractMockFactory.mockk(AbstractMockFactory.kt:58)

Кто-нибудь знает, почему я получаю эту ошибку?

Заранее спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...