There is a documentation on how to use @MockitoSpyBean: https://docs.spring.io/spring-framework/reference/testing/annotations/integration-spring/annotation-mockitobean.html but the problem is how to use it properly with Kotlin - there are only examples with Java. Before Spring Boot 3.4 I was able to create and use mock with @SpyBean like that:
@Configuration
@SpyBeans(
SpyBean(SomeProvider::class),
SpyBean(SecondProvider::class)
)
class TestConfiguration
class TestSteps(
private val someProvider: SomeProvider,
) {
@Before
fun before() {
doReturn("value").whenever(someProvider).getSomeValue(any())
}
Now that these annotations are deprecated, I want to migrate them to @MockitoSpyBean, should this look like that?
@Configuration
@MockitoSpyBeans(
MockitoSpyBean(types = [SomeProvider::class]),
MockitoSpyBean(types = [SecondProvider::class])
)
class TestConfiguration
class TestSteps(
private val someProvider: SomeProvider,
) {
@Before
fun before() {
doReturn("value").whenever(someProvider).getSomeValue(any())
}
with above code the mocks aren't working anymore because of the error:
org.mockito.exceptions.misusing.NotAMockException:
Argument passed to when() is not a mock!
Example of correct stubbing:
doThrow(new RuntimeException()).when(mock).someMethod();
Tried this one and another solutions like creating mocks in fields inside this TestSteps class but none worked.
Could you provide right solution on how to migrate the code?