mockito-kotlin
mockito-kotlin copied to clipboard
Kotlin spy beans created with incorrect method signature
Originally raised as Upgrade to Spring Framework 6.1 causes null pointer in CoroutinesUtils, but investigated by Spring there and considered to be a bug here instead.
I've got a reactive kotlin spring boot repository that I'm attempting to spy. The superclass (CoroutineCrudRepository
) has methods such as:
suspend fun findById(id: ID): T?
When autowiring the repository interface using Spring this gets created with a proxy signature of
public final java.lang.Object jdk.proxy3.$Proxy98.findById(java.lang.Object,kotlin.coroutines.Continuation)
Creating a spy from the repository using
mock(defaultAnswer = AdditionalAnswers.delegatesTo(exampleRepository))
then seems to end up with two versions of the findById
method:
public java.lang.Object uk.co.greenthistle.coroutinespybeanexample.ExampleRepository$MockitoMock$poIc1iZ2.findById(java.lang.Object,kotlin.coroutines.Continuation)
and also
public java.lang.Object uk.co.greenthistle.coroutinespybeanexample.ExampleRepository$MockitoMock$poIc1iZ2.findById(java.lang.Long,kotlin.coroutines.Continuation)
This seems to then cause the new spring boot code to choose the wrong method and then not be able to find the correct method to call on the spy.
Please see example project demonstrating the issue at https://github.com/petergphillips/spring-coroutine-spybean-example