Ensure assertions is contents aware - #3228
Conversation
WalkthroughThe changes update the Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Method
participant Assert as Assert.assertEqualsNoOrder
participant Helper as validateEqualityNoOrder
Test->>Assert: assertEqualsNoOrder(actual, expected, message)
Assert->>Helper: validateEqualityNoOrder(actual, expected, prefix, message)
Helper->>Helper: Check size equality
Helper->>Helper: Copy actual to list
Helper->>Helper: For each element in expected, remove one occurrence from copy
Helper->>Helper: If copy not empty, throw AssertionError with prefixed message
Helper->>Test: Return if no error
Assessment against linked issues
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms (7)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
| @Test(description = "GITHUB-3227", expectedExceptions = AssertionError.class) | ||
| public void testAssertEqualsNoOrderCollection() { | ||
| var actual = List.of("a", "b", "b"); | ||
| var expected = List.of("a", "b", "c"); |
There was a problem hiding this comment.
That change wont be a valid test because then both actual and expected will be equal (since the underlying set reduces it) and so no assertion failures will be triggered.
There was a problem hiding this comment.
That's the point. Is it expected that aab and abb are equals?
And it could be extended: is it expected that aaaaaab is equals to abbbbbb?
In both case, I think it should be added as case in order to enforce the expectations
There was a problem hiding this comment.
That's the point. Is it expected that aab and abb are equals?
They are not supposed to be equal. But my implementation ends up making them equal. The problem is that both removeAll and Set dont solve the usecase. Looks like the only option is to be able to sort the collections and then try to compare it. I am not sure if the perf implications need to be considered here.
There was a problem hiding this comment.
You can sort only if the assertion still holds after the initial check.
Otherwise, create a separate issue if you want to handle it later.
There was a problem hiding this comment.
I relooked at this. I noticed that we have a assertEqualsNoOrder method for Object[] arrays and it resorts to removing one element at a time instead of doing a removeAll(). That way we ensure that we don't do a greedy removal but only 1 element at a time. Please check now
b646a4e to
2fb4eaa
Compare
2fb4eaa to
5084c00
Compare
Closes #3227
Fixes #3227 .
Did you remember to?
CHANGES.txt./gradlew autostyleApplyWe encourage pull requests that:
If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the
TestNG-dev before you spend time working on it.
Note: For more information on contribution guidelines please make sure you refer our Contributing section for detailed set of steps.
Summary by CodeRabbit
Bug Fixes
Tests