-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Rework of injection strategy in the context of modules #3608
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3608 +/- ##
============================================
+ Coverage 85.56% 86.46% +0.90%
+ Complexity 2957 2952 -5
============================================
Files 341 340 -1
Lines 9028 8971 -57
Branches 1119 1103 -16
============================================
+ Hits 7725 7757 +32
+ Misses 1013 934 -79
+ Partials 290 280 -10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…cess package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's quite a bit going on here, but I did my best to understand your approach. If I understand correctly, we now use a strategy pattern to determine whether we are dealing with module boundaries or not. Based on that, we choose the appropriate strategy and make the necessary adjustments in the module graph to allow for creating of classes in the module?
That all sounds good to me. I don't have deep knowledge of these systems, so I can't comment on the implementation in detail. That said, I reckon you are one of the folks on the planet who even understands these 😛
Looking at the coverage (for me to figure out how things flow), it seems that parts of https://app.codecov.io/gh/mockito/mockito/pull/3608/blob/mockito-core/src/main/java/org/mockito/internal/creation/bytebuddy/ModuleHandler.java are not used. Most notably exportFromTo
and when we can't change the packages. Is it possible to add more regression tests in module-test
for these, or are these (near) impossible to recreate? All the uncovered IllegalStateException
I don't really mind, given that we are using reflection there.
Nit: Should we use MockitoException
wrapping an IllegalStateException
?
@scordio Could you also check if the issue you were hitting with AssertJ would be fixed with this PR? |
I understand why we never reach this branch, and it is because the InlineMockMaker that delegates to the SubclassMockMaker already adds the export. The SubclassMockMaker by itself does however not use instrumentation, so in a way its redundant. It does however yield a proper error when the subclass maker is used with named modules. I still suggest we keep it that way. Its guarded with a check, so the cost is minimal. Also, the code is easier to read this way, as another reader would wonder, and it makes it more robust against changes in the inline maker. I'd say this is good with the few additional tests. |
Sounds good to me, thanks for the additional explanation and tests. Let's wait till tomorrow to hopefully have input from the other folks if it works in their project and then we can merge. Essentially I expect assertj/assertj#3791 to have a working build again with these fixes. |
I built this branch locally, but it didn't solve the issues I experienced at assertj/assertj#3791. The following JVM options helped to fix them:
I'm not entirely sure if the first and the last can be prevented, but at least the middle one seems unrelated to the AssertJ codebase (see also assertj/assertj#3791 (comment)). |
Are you using the internal packages in assertj? If so, we'd need to look into creating public APIs around the functionality you are using. We want to keep the internal packages internal, of course. |
I don't think so and, even if we do, it's in test code only and I would argue why. I'll check and get back! |
There were some usages, and I removed them at assertj/assertj@fae7ffd8. However, I still experience issues. Here's the current summary of the test execution of Mockito 5.16.1-SNAPSHOT (this branch)I see one remaining error:
Details
I'll dig more to figure out the workaround. |
That must be a different or outdated branch as I moved the mentioned class to a different package. |
@raphw sorry, I wrote the previous comment misleadingly 🙂 please recheck it. I also deleted all the details about 5.16.0, as you solved them anyway. Sorry for the noise. |
Adding:
solves the issue. I wonder if this can also be solved on Mockito side as I wouldn't expect the |
@raphw Do I understand correctly from Scordio's comments that this PR is ready to be merged and we can publish a new patch version? Or are we missing a fix for the issues mentioned? |
Having to add:
seems like an unresolved issue to me, but happy to hear your opinion 🙂 |
There's one more fix coming for that. |
All right, cool. No rush! |
@raphw all AssertJ tests are now green, no |
I made a last adjustment. Could you give it a last run? |
All good 👍 |
then this is ready to be merged @TimvdLippe |
| Package | Type | Package file | Manager | Update | Change | |---|---|---|---|---|---| | [org.mockito:mockito-core](https://github.com/mockito/mockito) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `5.16.0` -> `5.16.1` | | [org.junit.jupiter:junit-jupiter-params](https://junit.org/junit5/) ([source](https://github.com/junit-team/junit5)) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `5.12.0` -> `5.12.1` | | [org.junit.jupiter:junit-jupiter-engine](https://junit.org/junit5/) ([source](https://github.com/junit-team/junit5)) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `5.12.0` -> `5.12.1` | | [org.junit.jupiter:junit-jupiter-api](https://junit.org/junit5/) ([source](https://github.com/junit-team/junit5)) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `5.12.0` -> `5.12.1` | | [software.amazon.awssdk:sdk-core](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.0` -> `2.31.1` | | [software.amazon.awssdk:sqs](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.0` -> `2.31.1` | | [software.amazon.awssdk:dynamodb-enhanced](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.0` -> `2.31.1` | | [software.amazon.awssdk:dynamodb](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.0` -> `2.31.1` | | [software.amazon.awssdk:aws-core](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.0` -> `2.31.1` | | [software.amazon.awssdk:bom](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.0` -> `2.31.1` | | [software.amazon.awssdk:auth](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.0` -> `2.31.1` | --- ### Release Notes <details> <summary>mockito/mockito (org.mockito:mockito-core)</summary> ### [`v5.16.1`](https://github.com/mockito/mockito/releases/tag/v5.16.1) <sup><sup>*Changelog generated by [Shipkit Changelog Gradle Plugin](https://github.com/shipkit/shipkit-changelog)*</sup></sup> ##### 5.16.1 - 2025-03-15 - [3 commit(s)](mockito/mockito@v5.16.0...v5.16.1) by Adrian Roos, Jérôme Prinet, Rafael Winterhalter - Remove Arrays.asList from critical stubbing path in GenericMetadataSu… [(#​3610)](mockito/mockito#3610) - Rework of injection strategy in the context of modules [(#​3608)](mockito/mockito#3608) - Adjust inline mocking snippet to allow task relocatability [(#​3606)](mockito/mockito#3606) - Inline mocking configuration snippet for Gradle should allow task relocatability [(#​3605)](mockito/mockito#3605) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 6pm every weekday,before 2am every weekday" in timezone Australia/Melbourne, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Never, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). GitOrigin-RevId: 1939516a6a445b5c4812a6d4f27f483cdb66b66e
Makes sure that a module can be injected into, and opens and exports the correct packages when Mockito is used as a named module together with other named modules.
Fixes #3607
Fixes #3612