-
Notifications
You must be signed in to change notification settings - Fork 41.2k
MockitoPostProcessor can trigger early initialization of factory beans #20665
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
This seems to be happening because The test passes if the name of the bean that should be replaced by a mock is specified as follows: @MockBean(name="progRepository") |
It works, great! ...But why? It's not clear to me. Thanks |
We think we may be able to fix this by prohibiting eager init when getting bean names by type. |
@wilkinsona @philwebb The only way I could think of to test this was by registering a factory bean definition. That seems to trigger early initialization. Could one of you take a look? |
That looks good to me. The only alternative that I can think of is to try and mimic Spring Data GemFire's registration of a custom editor and a failure because it's not registered in time due to eager init. That's almost certainly going to be more hoops to jump through with no difference in coverage. |
I'm working on a SpringBoot project which also uses Spring Data Gemfire, so I'm posting here hoping it is the correct place.
In a
SpringBootTest
when I useMockBean
with acache-config.xml
containingscope="global"
, I get the following exception:Spring Data Gemfire should register the
ScopeConverter
(inCustomEditorBeanFactoryPostProcessor
) which matches case-insensitive the xml value with the Scope enum. This actually happens when running the application. But not (correctly) in tests usingMockBean
.Full reproducer:
https://github.com/antoniomacri/spring-boot-sdg-mockbean
Complete stacktrace:
The text was updated successfully, but these errors were encountered: