-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Closed as not planned
Closed as not planned
Copy link
Labels
in: testIssues in the test moduleIssues in the test modulestatus: invalidAn issue that we don't feel is validAn issue that we don't feel is valid
Description
There is a documentation on how to use @MockitoSpyBean, 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 this:
@Configuration
@SpyBeans(
SpyBean(SomeProvider::class),
SpyBean(SecondProvider::class)
)
class TestConfigurationclass 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 that look like the following?
@Configuration
@MockitoSpyBeans(
MockitoSpyBean(types = [SomeProvider::class]),
MockitoSpyBean(types = [SecondProvider::class])
)
class TestConfigurationclass 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 this 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 and other solutions like creating mocks in fields inside TestSteps, but nothing worked.
Could you provide documentation on how to migrate the code?
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test modulestatus: invalidAn issue that we don't feel is validAn issue that we don't feel is valid