-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Spring not initializing mockitobeans properly in Spring 3.4.4 kotlin test class #34832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Please provide a complete sample that reproduces the problem. The attached code can't be run as-is due to some missing classes (e.g., |
this is the stubbed TokenGenerator class but it should be noted that the issue really isn't with this class at all.
|
The code is still not runnable — some methods and dependencies are missing. To help speed up troubleshooting, please provide a sample project either as a ZIP archive or by sharing a link to a repository. |
I had a feeling you would ask for this. I cant share most of the logic. I can try to extract it as a dummy project but I do feel as if enough is here to point in a direction that something isn't right in the meantime. If something is missing you can likely return a base object/blank where needed. |
I am running into an issue when upgrading from Spring Boot 3.3.9 to 3.4.4 where my tests with Mocked beans fail to run due to an initialization error on our lateinit fields. My Mockito versions are managed by the spring-boot-starter-test package which would be 5.11.0 -> 5.14.2.
My exact Mockito error is: org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Misplaced or misused argument matcher detected here: FooTest.anyTokenPayLoad.kt
I think this is caused by a kotlin exception: lateinit property tokenType has not been initialized
kotlin.UninitializedPropertyAccessException: lateinit property tokenType has not been initialized
I looked at this issue #34516 which is strikingly similar to our issue but of course we do not use spybeans.
These tests work as intended on Spring 3.3.9 and Mockito 5.11.0. They do not work on Spring 3.4.4 and do not work on either Mockitio version which leads me to believe it is a possible issue with how spring is initializing these lateinit fields via Autowire.
Thank you for taking a look into and I apologize if it was answered somewhere but I tried to look in the issues list.
Other info:
'kotlin_version', "1.7"
'org.jetbrains.kotlin.plugin.spring' version '2.1.20'
'org.jetbrains.kotlin.jvm' version '2.1.20'
I attached stubbed versions of our test class, service class that allows the autowire, and object that holds the lateinit field in question.
The text was updated successfully, but these errors were encountered: