Skip to content
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

Support @InjectSpy on javax.inject.Singleton classes #30608

Closed
davidfrickert opened this issue Jan 25, 2023 · 5 comments · Fixed by #30623
Closed

Support @InjectSpy on javax.inject.Singleton classes #30608

davidfrickert opened this issue Jan 25, 2023 · 5 comments · Fixed by #30623
Assignees
Labels
area/testing kind/enhancement New feature or request
Milestone

Comments

@davidfrickert
Copy link
Contributor

Description

Currently, if I try to @InjectSpy a javax.inject.Singleton class, like javax.transaction.TransactionManager, I get the error:

Invalid use of io.quarkus.test.junit.mockito.InjectSpy - the injected bean does not declare a CDI normal scope but: javax.inject.Singleton

By checking this issue: #8983, it seems that @InjectMock has a param convertScopes that addresses this issue. Could this also work on InjectSpy?

I wanted to do something like this in my tests:

// (...)
verify(transactionManagerSpy).setRollbackOnly();
//

Implementation ideas

No response

@quarkus-bot
Copy link

quarkus-bot bot commented Jan 25, 2023

/cc @geoand (testing)

@davidfrickert
Copy link
Contributor Author

I solved my problem by creating a wrapper bean @ApplicationScoped that injects the TransactionManager. Then I can @InjectSpy it and verify that the method is being called.
But it should still be nice to have a proper way of validating that the transaction was committed or rolled back.

geoand added a commit to geoand/quarkus that referenced this issue Jan 26, 2023
The same way we support convertScopes on @InjectMock
we can support it on @InjectSpy as well.

Closes: quarkusio#30608
geoand added a commit to geoand/quarkus that referenced this issue Jan 26, 2023
The same way we support convertScopes on @InjectMock
we can support it on @InjectSpy as well.

Closes: quarkusio#30608
@geoand
Copy link
Contributor

geoand commented Jan 26, 2023

Good idea!

#30623 will take care of it

@geoand geoand self-assigned this Jan 26, 2023
@quarkus-bot quarkus-bot bot added this to the 2.17 - main milestone Jan 26, 2023
geoand added a commit that referenced this issue Jan 26, 2023
Introduce convertScopes to `@InjectSpy`
@davidfrickert
Copy link
Contributor Author

thanks for the quick fix @geoand !

@geoand
Copy link
Contributor

geoand commented Jan 26, 2023

YW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants