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

Add @InjectSpy.delegate to evade errors with default methods in intermediate spring-data repo interfaces #26900

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

famod
Copy link
Member

@famod famod commented Jul 22, 2022

Evades:

org.mockito.exceptions.base.MockitoException: 
Cannot call abstract real method on java object!
Calling real methods is only possible when mocking non abstract method.
  //correct example:
  when(mockOfConcreteClass.nonAbstractMethod()).thenCallRealMethod();
	at io.quarkus.it.spring.data.jpa.IntermediateRepository.findMandatoryById(IntermediateRepository.java:15)

It can also help with other cases, see https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#delegating_call_to_real_instance

For this specific case of spring repos, I can't help but think that there might be another solution on class generation level, but I'm lacking the time to dig deeper.
If I create a dummy impl of a repo class, trying to mimic what's happening in ArC, then mockito has no issue with calling a default method in an intermediate interface of that repo. So something might be incompatible here (between mockito/bytebuddy and quarkus/arc)...
I can provide that small playground project if required.

I hope the test class I added is sufficient to play around with. The crucial thing is that PostRepository implements https://github.com/quarkusio/quarkus/blob/main/integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/IntermediateRepository.java

I can't prove it, but I guess that issue could surface for other, non-spring-repo beans as well.

@famod famod requested a review from geoand July 22, 2022 23:39
@quarkus-bot quarkus-bot bot added area/spring Issues relating to the Spring integration area/testing labels Jul 22, 2022
@famod
Copy link
Member Author

famod commented Jul 22, 2022

Also /cc @mkouba @manovotn, maybe that rings a bell for you.

@famod
Copy link
Member Author

famod commented Jul 22, 2022

It can be considered a small new feature, but it's "fixing" an annoying issue I have, so I'd like to have it backported. YMMV!
It's only an opt in anyway, so the risk of breaking something is tiny.

@quarkus-bot

This comment has been minimized.

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@geoand geoand merged commit ecce503 into quarkusio:main Jul 26, 2022
@quarkus-bot quarkus-bot bot added this to the 2.12 - main milestone Jul 26, 2022
@gsmet gsmet modified the milestones: 2.12 - main, 2.11.1.Final Jul 26, 2022
@famod famod deleted the injectspy-spring-repo branch July 26, 2022 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/spring Issues relating to the Spring integration area/testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants