-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[java] Fix asserts for maps and sets #16808
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
[java] Fix asserts for maps and sets #16808
Conversation
|
Thank you, @asolntsev for this code suggestion. The support packages contain example code that many users find helpful, but they do not necessarily represent After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks. |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||
The problem is that AssertJ's method `isEqualTo` doesn't always work for Sets and Maps because it assumes strict order of elements: 1. `assertThat(MAP).isEqualTo(Map.of(...))` 2. `assertThat(SET).isEqualTo(Set.of(...))` In both cases, we have to replace `isEqualTo` by `containsExactlyInAnyOrderEntriesOf` or similar method.
After the simplification, it became obvious that some of ByChainedTest tests don't really test anything. They create a bunch of lists (e.g. `elems345`) which are not used. And only the empty list of elements is loaded and asserted. Seems that this complex/misleading test logic in ByChainedTest was introduced in commit c4861b8 (some "patch from BenChambers"). Needs to be reviewed and fixed.
9220164 to
e0ab2e3
Compare
now we check that the resulting content at least _looks like PDF_.
e0ab2e3 to
a267dae
Compare
User description
💥 What does this PR do?
Fixes AssertJ's asserts for
java.util.Maps andjava.util.Sets.🔧 Implementation Notes
The problem is that AssertJ's method
isEqualTodoesn't always work for Sets and Maps because it assumes strict order of elements:assertThat(MAP).isEqualTo(Map.of(...))// can fail time-to-time because of different order of elementsassertThat(SET).isEqualTo(Set.of(...))// can fail time-to-time because of different order of elementsIn both cases, we have to replace
isEqualTobycontainsExactlyInAnyOrderEntriesOfor similar method.💡 Additional Considerations
🔄 Types of changes
PR Type
Bug fix
Description
Replace AssertJ
isEqualTowith order-agnostic assertions for Maps and SetsFix flaky tests that fail due to element ordering assumptions
Improve PDF validation in BrowsingContextTest with content verification
Simplify test setup code using modern Java collection literals
Add proper resource management with try-with-resources blocks
Diagram Walkthrough
File Walkthrough
18 files
Fix List assertion to use containsExactlyReplace Map assertions with order-agnostic checksFix Set assertion and add resource cleanupReplace Set assertions with containsExactlyInAnyOrderFix Map capability assertion with order-agnostic checkReplace Map assertion with containsExactlyInAnyOrderEntriesOfReplace Map assertion with containsExactlyInAnyOrderEntriesOfAdd try-with-resources for resource managementReplace Map/List assertions with order-agnostic checksFix Map and List assertions for unordered collectionsReplace Set/List assertions with order-agnostic checksSimplify Set creation and fix assertionReplace List assertion with containsExactlyFix Map assertion with order-agnostic checkReplace Map assertions with containsExactlyInAnyOrderEntriesOfSimplify test setup and fix assertionsReplace List assertion with containsExactlyReplace List assertions with containsExactly1 files
Improve PDF validation with content verification1 files
Add missing test method and imports2 files
Split and clarify timeout builder testsImprove Map entry assertion clarity2 files
Simplify Set creation with Set.ofSimplify Set creation with Set.of